diff --git a/__tests__/buildx.test.ts b/__tests__/buildx.test.ts index 0a82efa..9f04124 100644 --- a/__tests__/buildx.test.ts +++ b/__tests__/buildx.test.ts @@ -3,9 +3,9 @@ import * as path from 'path'; import * as semver from 'semver'; import * as buildx from '../src/buildx'; import * as docker from '../src/docker'; -import * as exec from '@actions/exec'; import * as context from '../src/context'; +const tmpNameSync = path.join('/tmp/.docker-build-push-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep); const digest = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9'; jest.spyOn(context, 'tmpDir').mockImplementation((): string => { @@ -17,7 +17,7 @@ jest.spyOn(context, 'tmpDir').mockImplementation((): string => { }); jest.spyOn(context, 'tmpNameSync').mockImplementation((): string => { - return path.join('/tmp/.docker-build-push-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep); + return tmpNameSync; }); describe('getImageID', () => { @@ -115,3 +115,16 @@ describe('parseVersion', () => { expect(await buildx.parseVersion(stdout)).toEqual(expected); }); }); + +describe('getSecret', () => { + it('writes correct secret content', async () => { + const key = 'MY_KEY'; + const secret = 'c3RyaW5nLXdpdGgtZXF1YWxzCg=='; + const secretArgs = await buildx.getSecret(`${key}=${secret}`); + console.log(`secretArgs: ${secretArgs}`); + expect(secretArgs).toEqual(`id=${key},src=${tmpNameSync}`); + const secretContent = await fs.readFileSync(tmpNameSync, 'utf-8'); + console.log(`secretValue: ${secretContent}`); + expect(secretContent).toEqual(secret); + }); +}); diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index 4c87e1b..d38a570 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -1,6 +1,5 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as buildx from '../src/buildx'; import * as context from '../src/context'; jest.spyOn(context, 'defaultContext').mockImplementation((): string => { @@ -107,7 +106,7 @@ describe('getArgs', () => { '0.4.2', new Map([ ['context', '.'], - ['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno0123456789'], + ['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno=0123456789'], ]), [ 'buildx', @@ -139,7 +138,7 @@ describe('getArgs', () => { ['context', 'https://github.com/docker/build-push-action.git#heads/master'], ['tag', 'localhost:5000/name/app:latest'], ['platforms', 'linux/amd64,linux/arm64'], - ['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno0123456789'], + ['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno=0123456789'], ['file', './test/Dockerfile'], ['builder', 'builder-git-context-2'], ['push', 'true'] diff --git a/dist/index.js b/dist/index.js index 56cefdc..06d16f9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4248,7 +4248,9 @@ function getImageID() { exports.getImageID = getImageID; function getSecret(kvp) { return __awaiter(this, void 0, void 0, function* () { - const [key, value] = kvp.split('='); + const delimiterIndex = kvp.indexOf('='); + const key = kvp.substring(0, delimiterIndex); + const value = kvp.substring(delimiterIndex + 1); const secretFile = context.tmpNameSync({ tmpdir: context.tmpDir() }); diff --git a/src/buildx.ts b/src/buildx.ts index 32f5fc3..8fb506f 100644 --- a/src/buildx.ts +++ b/src/buildx.ts @@ -18,7 +18,9 @@ export async function getImageID(): Promise { } export async function getSecret(kvp: string): Promise { - const [key, value] = kvp.split('='); + const delimiterIndex = kvp.indexOf('='); + const key = kvp.substring(0, delimiterIndex); + const value = kvp.substring(delimiterIndex + 1); const secretFile = context.tmpNameSync({ tmpdir: context.tmpDir() });