Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/credential-provider-node/jest.config.integ.js

This file was deleted.

5 changes: 3 additions & 2 deletions packages/credential-provider-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"test": "yarn g:vitest run",
"test:integration": "yarn g:jest -c jest.config.integ.js",
"test:watch": "yarn g:vitest watch"
"test:watch": "yarn g:vitest watch",
"test:integration": "yarn g:vitest run -c vitest.config.integ.mts",
"test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.mts"
},
"keywords": [
"aws",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,31 @@ import { HttpResponse } from "@smithy/protocol-http";
import type { SharedConfigInit, SourceProfileInit } from "@smithy/shared-ini-file-loader";
import type { HttpRequest, NodeHttpHandlerOptions, ParsedIniData, SharedConfigFiles } from "@smithy/types";
import { AdaptiveRetryStrategy, StandardRetryStrategy } from "@smithy/util-retry";
import * as childProcess from "child_process";
import { PassThrough } from "stream";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test as it, vi } from "vitest";

import { defaultProvider } from "./defaultProvider";

jest.mock("fs", () => {
const actual = jest.requireActual("fs");
vi.mock("fs", async () => {
const actual = (await vi.importActual("fs")) as typeof import("fs");
return {
...actual,
readFileSync(file: string, ...options: any[]) {
readFileSync: vi.fn((file: string, ...options: any[]) => {
if (file === "token-filepath") {
return "token-contents";
}
return actual.readFileSync(file, ...options);
},
}),
};
});

let iniProfileData: ParsedIniData = null as any;
jest.mock("@smithy/shared-ini-file-loader", () => {
const actual = jest.requireActual("@smithy/shared-ini-file-loader");
vi.mock("@smithy/shared-ini-file-loader", async () => {
const actual = await vi.importActual("@smithy/shared-ini-file-loader");
return {
...actual,
async loadSsoSessionData() {
loadSsoSessionData: vi.fn(async () => {
return Object.entries(iniProfileData)
.filter(([key]) => key.startsWith("sso-session."))
.reduce(
Expand All @@ -37,29 +39,29 @@ jest.mock("@smithy/shared-ini-file-loader", () => {
}),
{}
);
},
async parseKnownFiles(init: SourceProfileInit): Promise<ParsedIniData> {
}),
parseKnownFiles: vi.fn(async (init: SourceProfileInit): Promise<ParsedIniData> => {
return iniProfileData;
},
async loadSharedConfigFiles(init: SharedConfigInit): Promise<SharedConfigFiles> {
}),
loadSharedConfigFiles: vi.fn(async (init: SharedConfigInit): Promise<SharedConfigFiles> => {
return {
configFile: iniProfileData,
credentialsFile: iniProfileData,
};
},
async getSSOTokenFromFile() {
}),
getSSOTokenFromFile: vi.fn(async () => {
return {
accessToken: "mock_sso_token",
expiresAt: "3000-01-01T00:00:00.000Z",
};
},
}),
};
});

const assumeRoleArns: string[] = [];

jest.mock("@smithy/node-http-handler", () => {
const actual = jest.requireActual("@smithy/node-http-handler");
vi.mock("@smithy/node-http-handler", async () => {
const actual = await vi.importActual("@smithy/node-http-handler");

class MockNodeHttpHandler {
static create(instanceOrOptions?: any) {
Expand All @@ -68,7 +70,8 @@ jest.mock("@smithy/node-http-handler", () => {
}
return new MockNodeHttpHandler();
}
async handle(request: HttpRequest) {

handle = vi.fn(async (request: HttpRequest) => {
const body = new PassThrough({});

if (request.body?.includes("RoleArn=")) {
Expand Down Expand Up @@ -165,11 +168,15 @@ jest.mock("@smithy/node-http-handler", () => {
headers: {},
}),
};
}
updateHttpClientConfig(key: keyof NodeHttpHandlerOptions, value: NodeHttpHandlerOptions[typeof key]): void {}
httpHandlerConfigs(): NodeHttpHandlerOptions {
});

updateHttpClientConfig = vi.fn(
(key: keyof NodeHttpHandlerOptions, value: NodeHttpHandlerOptions[typeof key]): void => {}
);

httpHandlerConfigs = vi.fn((): NodeHttpHandlerOptions => {
return null as any;
}
});
}

return {
Expand All @@ -178,11 +185,12 @@ jest.mock("@smithy/node-http-handler", () => {
};
});

jest.mock("child_process", () => {
const actual = jest.requireActual("child_process");
vi.mock("child_process", async () => {
const actual = (await vi.importActual("child_process")) as typeof childProcess;

return {
...actual,
exec(bin: string, cb: (err: unknown, data: any) => void, ...args: any[]) {
exec: vi.fn((bin: string, cb: (err: unknown, data: any) => void, ...args: any[]) => {
if (bin === "credential-process") {
return cb(null, {
stdout: JSON.stringify({
Expand All @@ -194,7 +202,7 @@ jest.mock("child_process", () => {
});
}
return actual.exec(bin, cb, ...args);
},
}),
};
});

Expand Down Expand Up @@ -271,8 +279,8 @@ describe("credential-provider-node integration test", () => {
});

afterAll(async () => {
jest.clearAllMocks();
jest.clearAllTimers();
vi.clearAllMocks();
vi.clearAllTimers();
});

describe("fromEnv", () => {
Expand Down Expand Up @@ -570,7 +578,7 @@ describe("credential-provider-node integration test", () => {
iniProfileData.credential_source_profile = {
credential_source: "EcsContainer",
};
const spy = jest.spyOn(credentialProviderHttp, "fromHttp");
const spy = vi.spyOn(credentialProviderHttp, "fromHttp");
sts = new STS({
region: "us-west-2",
credentials: defaultProvider({
Expand Down Expand Up @@ -658,7 +666,7 @@ describe("credential-provider-node integration test", () => {
role_arn: "ROLE_ARN_1",
};

const spy = jest.spyOn(credentialProviderHttp, "fromHttp");
const spy = vi.spyOn(credentialProviderHttp, "fromHttp");
sts = new STS({
region: "us-west-2",
credentials: defaultProvider({
Expand Down Expand Up @@ -710,7 +718,7 @@ describe("credential-provider-node integration test", () => {
// This scenario tests the option of having no role_arn in this step of the chain.
};

const spy = jest.spyOn(credentialProviderHttp, "fromHttp");
const spy = vi.spyOn(credentialProviderHttp, "fromHttp");
sts = new STS({
region: "us-west-2",
credentials: defaultProvider({
Expand Down Expand Up @@ -805,7 +813,7 @@ describe("credential-provider-node integration test", () => {
});
});

xit("should use instance metadata unless IMDS is disabled", async () => {
it.skip("should use instance metadata unless IMDS is disabled", async () => {
// TODO
});
});
Expand Down
Loading