Skip to content

Commit 50df1d4

Browse files
authored
Fixes docker auth passwords that contain a colon (#839)
1 parent 3a1ab3a commit 50df1d4

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,23 @@ describe("Auths", () => {
6464
};
6565
expect(await locator.getAuthConfig("https://registry.example.com", containerRuntimeConfig)).toEqual(authConfig);
6666
});
67+
68+
it("should return credentials from encoded auth when the password contains a colon", async () => {
69+
const containerRuntimeConfig: ContainerRuntimeConfig = {
70+
auths: {
71+
"https://registry.example.com": {
72+
73+
auth: "dXNlcjpwYXNzOjE=",
74+
},
75+
},
76+
};
77+
const authConfig: AuthConfig = {
78+
username: "user",
79+
password: "pass:1",
80+
81+
registryAddress: "https://registry.example.com",
82+
};
83+
expect(await locator.getAuthConfig("https://registry.example.com", containerRuntimeConfig)).toEqual(authConfig);
84+
});
6785
});
6886
});

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export class Auths implements RegistryAuthLocator {
2121

2222
if (auth.auth) {
2323
const decodedAuth = Buffer.from(auth.auth, "base64").toString();
24-
const [username, password] = decodedAuth.split(":");
24+
const [username, ...passwordParts] = decodedAuth.split(":");
25+
const password = passwordParts.join(":");
26+
2527
authConfig.username = username;
2628
authConfig.password = password;
2729
} else {

0 commit comments

Comments
 (0)