Skip to content

Commit bef45c0

Browse files
authored
Merge pull request #201 from mathieubergeron/fix-parse-secret-containing-equal-character
Fix parsing of secrets containing '=' character
2 parents b3b0ca3 + c8e09bf commit bef45c0

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

__tests__/buildx.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import * as path from 'path';
33
import * as semver from 'semver';
44
import * as buildx from '../src/buildx';
55
import * as docker from '../src/docker';
6-
import * as exec from '@actions/exec';
76
import * as context from '../src/context';
87

8+
const tmpNameSync = path.join('/tmp/.docker-build-push-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep);
99
const digest = 'sha256:bfb45ab72e46908183546477a08f8867fc40cebadd00af54b071b097aed127a9';
1010

1111
jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
@@ -17,7 +17,7 @@ jest.spyOn(context, 'tmpDir').mockImplementation((): string => {
1717
});
1818

1919
jest.spyOn(context, 'tmpNameSync').mockImplementation((): string => {
20-
return path.join('/tmp/.docker-build-push-jest', '.tmpname-jest').split(path.sep).join(path.posix.sep);
20+
return tmpNameSync;
2121
});
2222

2323
describe('getImageID', () => {
@@ -115,3 +115,16 @@ describe('parseVersion', () => {
115115
expect(await buildx.parseVersion(stdout)).toEqual(expected);
116116
});
117117
});
118+
119+
describe('getSecret', () => {
120+
it('writes correct secret content', async () => {
121+
const key = 'MY_KEY';
122+
const secret = 'c3RyaW5nLXdpdGgtZXF1YWxzCg==';
123+
const secretArgs = await buildx.getSecret(`${key}=${secret}`);
124+
console.log(`secretArgs: ${secretArgs}`);
125+
expect(secretArgs).toEqual(`id=${key},src=${tmpNameSync}`);
126+
const secretContent = await fs.readFileSync(tmpNameSync, 'utf-8');
127+
console.log(`secretValue: ${secretContent}`);
128+
expect(secretContent).toEqual(secret);
129+
});
130+
});

__tests__/context.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
3-
import * as buildx from '../src/buildx';
43
import * as context from '../src/context';
54

65
jest.spyOn(context, 'defaultContext').mockImplementation((): string => {
@@ -107,7 +106,7 @@ describe('getArgs', () => {
107106
'0.4.2',
108107
new Map<string, string>([
109108
['context', '.'],
110-
['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno0123456789'],
109+
['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno=0123456789'],
111110
]),
112111
[
113112
'buildx',
@@ -139,7 +138,7 @@ describe('getArgs', () => {
139138
['context', 'https://github.com/docker/build-push-action.git#heads/master'],
140139
['tag', 'localhost:5000/name/app:latest'],
141140
['platforms', 'linux/amd64,linux/arm64'],
142-
['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno0123456789'],
141+
['secrets', 'GIT_AUTH_TOKEN=abcdefghijklmno=0123456789'],
143142
['file', './test/Dockerfile'],
144143
['builder', 'builder-git-context-2'],
145144
['push', 'true']

dist/index.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/buildx.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export async function getImageID(): Promise<string | undefined> {
1818
}
1919

2020
export async function getSecret(kvp: string): Promise<string> {
21-
const [key, value] = kvp.split('=');
21+
const delimiterIndex = kvp.indexOf('=');
22+
const key = kvp.substring(0, delimiterIndex);
23+
const value = kvp.substring(delimiterIndex + 1);
2224
const secretFile = context.tmpNameSync({
2325
tmpdir: context.tmpDir()
2426
});

0 commit comments

Comments
 (0)