Skip to content

Commit

Permalink
Fixes docker auth passwords that contain a colon (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshystuart authored Oct 3, 2024
1 parent 3a1ab3a commit 50df1d4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 18 additions & 0 deletions packages/testcontainers/src/container-runtime/auth/auths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,23 @@ describe("Auths", () => {
};
expect(await locator.getAuthConfig("https://registry.example.com", containerRuntimeConfig)).toEqual(authConfig);
});

it("should return credentials from encoded auth when the password contains a colon", async () => {
const containerRuntimeConfig: ContainerRuntimeConfig = {
auths: {
"https://registry.example.com": {
email: "user@example.com",
auth: "dXNlcjpwYXNzOjE=",
},
},
};
const authConfig: AuthConfig = {
username: "user",
password: "pass:1",
email: "user@example.com",
registryAddress: "https://registry.example.com",
};
expect(await locator.getAuthConfig("https://registry.example.com", containerRuntimeConfig)).toEqual(authConfig);
});
});
});
4 changes: 3 additions & 1 deletion packages/testcontainers/src/container-runtime/auth/auths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export class Auths implements RegistryAuthLocator {

if (auth.auth) {
const decodedAuth = Buffer.from(auth.auth, "base64").toString();
const [username, password] = decodedAuth.split(":");
const [username, ...passwordParts] = decodedAuth.split(":");
const password = passwordParts.join(":");

authConfig.username = username;
authConfig.password = password;
} else {
Expand Down

0 comments on commit 50df1d4

Please sign in to comment.