Skip to content

Commit 23de77e

Browse files
authored
Authenticate with identityToken when present in auths (#1197)
1 parent 5385863 commit 23de77e

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

packages/testcontainers/src/container-runtime/auth/auths.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,37 @@ describe("Auths", () => {
8282
};
8383
expect(await locator.getAuthConfig("https://registry.example.com", containerRuntimeConfig)).toEqual(authConfig);
8484
});
85+
86+
it("should return credentials from identity token", async () => {
87+
const containerRuntimeConfig: ContainerRuntimeConfig = {
88+
auths: {
89+
"https://registry.example.com": {
90+
identitytoken: "token-value",
91+
},
92+
},
93+
};
94+
const authConfig: AuthConfig = {
95+
identityToken: "token-value",
96+
registryAddress: "https://registry.example.com",
97+
};
98+
expect(await locator.getAuthConfig("https://registry.example.com", containerRuntimeConfig)).toEqual(authConfig);
99+
});
100+
101+
it("should use identity token when token and user and pass are provided", async () => {
102+
const containerRuntimeConfig: ContainerRuntimeConfig = {
103+
auths: {
104+
"https://registry.example.com": {
105+
identitytoken: "token-value",
106+
username: "user",
107+
password: "pass",
108+
},
109+
},
110+
};
111+
const authConfig: AuthConfig = {
112+
identityToken: "token-value",
113+
registryAddress: "https://registry.example.com",
114+
};
115+
expect(await locator.getAuthConfig("https://registry.example.com", containerRuntimeConfig)).toEqual(authConfig);
116+
});
85117
});
86118
});

packages/testcontainers/src/container-runtime/auth/auths.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ export class Auths implements RegistryAuthLocator {
1313
return undefined;
1414
}
1515

16+
if (auth.identitytoken) {
17+
return {
18+
registryAddress: registry,
19+
identityToken: auth.identitytoken,
20+
};
21+
}
22+
1623
const authConfig: Partial<UsernamePasswordAuthConfig> = { registryAddress: registry };
1724

1825
if (auth.email) {

packages/testcontainers/src/container-runtime/auth/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type Auth = {
99
email?: string;
1010
username?: string;
1111
password?: string;
12+
identitytoken?: string;
1213
};
1314

1415
export type AuthConfig = UsernamePasswordAuthConfig | IdentityTokenAuthConfig;

0 commit comments

Comments
 (0)