Skip to content

Commit

Permalink
Merge pull request #201 from mathieubergeron/fix-parse-secret-contain…
Browse files Browse the repository at this point in the history
…ing-equal-character

Fix parsing of secrets containing '=' character
  • Loading branch information
crazy-max authored Oct 23, 2020
2 parents b3b0ca3 + c8e09bf commit bef45c0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
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

0 comments on commit bef45c0

Please sign in to comment.