Skip to content

Commit

Permalink
fix: bump axios version to 1.6.2 (#10400)
Browse files Browse the repository at this point in the history
* build(deps): bump axios from 0.21.2 to 1.6.0

Bumps [axios](https://github.com/axios/axios) from 0.21.2 to 1.6.0.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](axios/axios@v0.21.2...v1.6.0)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix: node-fetch

* fix: use node-fetch 2.7.0

* test: ut

* fix: axios error

* feat: axios 1.6.2

* fix: aadAppClient

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
jayzhang and dependabot[bot] authored Nov 20, 2023
1 parent 712facb commit 0c07743
Show file tree
Hide file tree
Showing 9 changed files with 392 additions and 711 deletions.
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"dependencies": {
"@azure/core-auth": "^1.4.0",
"@microsoft/teams-manifest": "workspace:*",
"axios": "^0.21.2",
"axios": "^1.6.2",
"chai": "^4.3.4",
"jsonschema": "^1.4.0",
"neverthrow": "^3.2.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/fx-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"@npmcli/arborist": "^4.2.0",
"adm-zip": "^0.5.5",
"ajv": "^8.5.0",
"axios": "^0.21.4",
"axios": "^1.6.2",
"axios-retry": "^3.3.1",
"comment-json": "^4.2.3",
"cryptr": "^6.0.2",
Expand All @@ -111,6 +111,7 @@
"md5": "^2.3.0",
"mime": "^2.5.2",
"mustache": "^4.2.0",
"node-fetch": "2.7.0",
"node-forge": "^1.3.1",
"office-addin-manifest": "^1.12.4",
"office-addin-project": "^0.7.0",
Expand Down Expand Up @@ -149,6 +150,7 @@
"@types/mock-fs": "^4.13.1",
"@types/mustache": "^4.1.1",
"@types/node": "^14.14.21",
"@types/node-fetch": "^2.6.9",
"@types/node-forge": "^0.9.7",
"@types/proper-lockfile": "4.1.1",
"@types/proxyquire": "^1.3.28",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

import { hooks } from "@feathersjs/hooks/lib";
import { LogProvider, M365TokenProvider } from "@microsoft/teamsfx-api";
import axios, { AxiosError, AxiosInstance } from "axios";
import axios, { AxiosError, AxiosInstance, AxiosRequestHeaders } from "axios";
import axiosRetry, { IAxiosRetryConfig } from "axios-retry";
import { getLocalizedString } from "../../../../common/localizeUtils";
import { AadOwner } from "../../../../common/permissionInterface";
import { GraphScopes } from "../../../../common/tools";
import { ErrorContextMW } from "../../../../core/globalVars";
Expand All @@ -15,7 +16,6 @@ import { IAADDefinition } from "../interface/IAADDefinition";
import { SignInAudience } from "../interface/signInAudience";
import { AadManifestHelper } from "./aadManifestHelper";
import { aadErrorCode, constants } from "./constants";
import { getLocalizedString } from "../../../../common/localizeUtils";
// Another implementation of src\component\resource\aadApp\graph.ts to reduce call stacks
// It's our internal utility so make sure pass valid parameters to it instead of relying on it to handle parameter errors

Expand Down Expand Up @@ -52,7 +52,7 @@ export class AadAppClient {
const token = tokenResponse.value;

if (!config.headers) {
config.headers = {};
config.headers = {} as AxiosRequestHeaders;
}
config.headers["Authorization"] = `Bearer ${token}`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import fse from "fs-extra";
import * as path from "path";
import * as unzip from "unzipper";
import { manifestUtils } from "../../driver/teamsApp/utils/ManifestUtils";
import fetch from "node-fetch";

const zipFile = "project.zip";

Expand All @@ -19,23 +20,33 @@ export class HelperMethods {
projectRepo: string,
projectBranch?: string
): Promise<void> {
const projectTemplateZipFile = `${projectRepo}/archive/${projectBranch || ""}.zip`;
const writeFileStream = fs.createWriteStream(path.resolve(projectFolder, zipFile));
const projectTemplateZipFile = path.resolve(
`${projectRepo}/archive/${projectBranch || ""}.zip`
);
const response = await fetch(projectTemplateZipFile, { method: "GET" });
const reader = response.body?.getReader();
if (reader) {
while (true) {
const res = await reader.read();
if (res.value) {
writeFileStream.write(res.value);
}
if (res.done) {
break;
}
return new Promise<void>((resolve, reject) => {
if (response.body) {
response.body
.pipe(fs.createWriteStream(path.resolve(projectFolder, zipFile)))
.on("error", (err) => {
reject(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`Unable to download project zip file for "${projectTemplateZipFile}".\n${err}`
);
})
.on("close", () => {
HelperMethods.unzipProjectTemplate(projectFolder)
.then(() => {
resolve();
})
.catch((err) => {
reject(err);
});
});
} else {
reject(`Response body is null.`);
}
writeFileStream.close();
await HelperMethods.unzipProjectTemplate(projectFolder);
}
});
}

static async unzipProjectTemplate(projectFolder: string): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { createContextV3 } from "../../../src/component/utils";
import { setTools } from "../../../src/core/globalVars";
import { QuestionNames } from "../../../src/question";
import { MockTools } from "../../core/utils";
import * as fetch from "node-fetch";

describe("OfficeAddinGenerator", function () {
const testFolder = path.resolve("./tmp");
Expand Down Expand Up @@ -371,37 +372,78 @@ describe("helperMethods", async () => {

describe("downloadProjectTemplateZipFile", async () => {
const sandbox = sinon.createSandbox();

class ResponseData extends EventEmitter {
pipe(ws: fs.WriteStream) {
return this;
}
}

class MockedWriteStream {
write(data: any) {}
close() {}
on(event: string, cb: () => void) {
return this;
}
}

afterEach(() => {
sandbox.restore();
});

const mockFetch = async (url: any, options: any) => {
// You can customize the response here
const response = new Response("Hello, world!", {
status: 200,
headers: { "Content-Type": "text/plain" },
});
return Promise.resolve(response);
};

it("should download project template zip file", async () => {
sandbox.stub(global, "fetch").value(mockFetch);
const resp = new ResponseData();
sandbox.stub(fetch, "default").resolves({ body: resp } as any);
const mockedStream = new MockedWriteStream();
const unzipStub = sandbox.stub(HelperMethods, "unzipProjectTemplate").resolves();
sandbox.stub<any, any>(fs, "createWriteStream").returns(mockedStream);
const promise = HelperMethods.downloadProjectTemplateZipFile("", "", "");
// manully wait for the close event to be registered
await new Promise((resolve) => setTimeout(resolve, 100));
resp.emit("close");
await promise;
chai.assert.isTrue(unzipStub.calledOnce);
});

it("unzipProjectTemplate error", async () => {
const resp = new ResponseData();
sandbox.stub(fetch, "default").resolves({ body: resp } as any);
const mockedStream = new MockedWriteStream();
sandbox.stub(HelperMethods, "unzipProjectTemplate").resolves();
sandbox.stub(HelperMethods, "unzipProjectTemplate").rejects(new Error());
sandbox.stub<any, any>(fs, "createWriteStream").returns(mockedStream);
await HelperMethods.downloadProjectTemplateZipFile("", "", "");
const promise = HelperMethods.downloadProjectTemplateZipFile("", "", "");
// manully wait for the close event to be registered
await new Promise((resolve) => setTimeout(resolve, 100));
resp.emit("close");
try {
await promise;
chai.assert.fail("should throw error");
} catch (e) {}
});

it("download error", async () => {
const resp = new ResponseData();
sandbox.stub(fetch, "default").resolves({ body: resp } as any);
const mockedStream = new MockedWriteStream();
const unzipStub = sandbox.stub(HelperMethods, "unzipProjectTemplate").resolves();
sandbox.stub<any, any>(fs, "createWriteStream").returns(mockedStream);
const promise = HelperMethods.downloadProjectTemplateZipFile("", "", "");
// manully wait for the close event to be registered
await new Promise((resolve) => setTimeout(resolve, 100));
resp.emit("error", new Error());
try {
await promise;
chai.assert.fail("should throw error");
} catch (e) {}
chai.assert.isTrue(unzipStub.notCalled);
});

it("Response body is null.", async () => {
sandbox.stub(fetch, "default").resolves({ body: null } as any);
const promise = HelperMethods.downloadProjectTemplateZipFile("", "", "");
try {
await promise;
chai.assert.fail("should throw error");
} catch (e) {
chai.assert.equal(e, `Response body is null.`);
}
});
});

Expand Down
4 changes: 3 additions & 1 deletion packages/manifest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"license": "MIT",
"dependencies": {
"@types/fs-extra": "^11.0.1",
"@types/node-fetch": "^2.6.9",
"ajv": "^8.5.0",
"ajv-draft-04": "^1.0.0",
"fs-extra": "^9.1.0"
"fs-extra": "^9.1.0",
"node-fetch": "2.7.0"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
Expand Down
1 change: 1 addition & 0 deletions packages/manifest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { JSONSchemaType } from "ajv";
import { DevPreviewSchema } from "./devPreviewManifest";
import { ManifestCommonProperties } from "./ManifestCommonProperties";
import { SharePointAppId } from "./constants";
import fetch from "node-fetch";

export * from "./manifest";
export * as devPreview from "./devPreviewManifest";
Expand Down
4 changes: 2 additions & 2 deletions packages/tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
"@azure/arm-sql": "^9.0.0",
"@azure/identity": "^3.1.3",
"@azure/msal-node": "1.17.3",
"@microsoft/teamsfx-api": "workspace:*",
"@microsoft/teamsapp-cli": "workspace:*",
"@microsoft/teamsfx-api": "workspace:*",
"@types/semver": "^7.3.8",
"axios": "^0.21.1",
"axios": "^1.6.2",
"azure-arm-resource": "^7.4.0",
"dotenv": "^8.2.0",
"fs-extra": "^7.0.1",
Expand Down
Loading

0 comments on commit 0c07743

Please sign in to comment.