Skip to content
Merged
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
32 changes: 32 additions & 0 deletions packages/testcontainers/src/container-runtime/auth/auths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,37 @@ describe("Auths", () => {
};
expect(await locator.getAuthConfig("https://registry.example.com", containerRuntimeConfig)).toEqual(authConfig);
});

it("should return credentials from identity token", async () => {
const containerRuntimeConfig: ContainerRuntimeConfig = {
auths: {
"https://registry.example.com": {
identitytoken: "token-value",
},
},
};
const authConfig: AuthConfig = {
identityToken: "token-value",
registryAddress: "https://registry.example.com",
};
expect(await locator.getAuthConfig("https://registry.example.com", containerRuntimeConfig)).toEqual(authConfig);
});

it("should use identity token when token and user and pass are provided", async () => {
const containerRuntimeConfig: ContainerRuntimeConfig = {
auths: {
"https://registry.example.com": {
identitytoken: "token-value",
username: "user",
password: "pass",
},
},
};
const authConfig: AuthConfig = {
identityToken: "token-value",
registryAddress: "https://registry.example.com",
};
expect(await locator.getAuthConfig("https://registry.example.com", containerRuntimeConfig)).toEqual(authConfig);
});
});
});
7 changes: 7 additions & 0 deletions packages/testcontainers/src/container-runtime/auth/auths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ export class Auths implements RegistryAuthLocator {
return undefined;
}

if (auth.identitytoken) {
return {
registryAddress: registry,
identityToken: auth.identitytoken,
};
}

const authConfig: Partial<UsernamePasswordAuthConfig> = { registryAddress: registry };

if (auth.email) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type Auth = {
email?: string;
username?: string;
password?: string;
identitytoken?: string;
};

export type AuthConfig = UsernamePasswordAuthConfig | IdentityTokenAuthConfig;
Expand Down
Loading