From 50df1d47f8bb65026a445fbb0dfe0903c6ff7b62 Mon Sep 17 00:00:00 2001 From: Josh Stuart Date: Thu, 3 Oct 2024 21:12:00 +1000 Subject: [PATCH] Fixes docker auth passwords that contain a colon (#839) --- .../src/container-runtime/auth/auths.test.ts | 18 ++++++++++++++++++ .../src/container-runtime/auth/auths.ts | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/testcontainers/src/container-runtime/auth/auths.test.ts b/packages/testcontainers/src/container-runtime/auth/auths.test.ts index 3879cd3a3..8dd366d25 100644 --- a/packages/testcontainers/src/container-runtime/auth/auths.test.ts +++ b/packages/testcontainers/src/container-runtime/auth/auths.test.ts @@ -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); + }); }); }); diff --git a/packages/testcontainers/src/container-runtime/auth/auths.ts b/packages/testcontainers/src/container-runtime/auth/auths.ts index 5399de3a7..fb295cb28 100644 --- a/packages/testcontainers/src/container-runtime/auth/auths.ts +++ b/packages/testcontainers/src/container-runtime/auth/auths.ts @@ -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 {