Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of secrets containing '=' character #201

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions __tests__/buildx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});
5 changes: 2 additions & 3 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down Expand Up @@ -107,7 +106,7 @@ describe('getArgs', () => {
'0.4.2',
new Map<string, string>([
['context', '.'],
['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno0123456789'],
['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno=0123456789'],
]),
[
'buildx',
Expand Down Expand Up @@ -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']
Expand Down
4 changes: 3 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/buildx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export async function getImageID(): Promise<string | undefined> {
}

export async function getSecret(kvp: string): Promise<string> {
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()
});
Expand Down