mirror of
https://github.com/docker/build-push-action.git
synced 2024-11-10 04:15:40 +01:00
Fix parsing of secrets containing '=' character
Signed-off-by: Mathieu Bergeron <mathieu.bergeron@nuecho.com>
This commit is contained in:
parent
c58c6870a2
commit
fc7e9a2b38
@ -2,9 +2,9 @@ import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
import * as buildx from '../src/buildx';
|
||||
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 => {
|
||||
@ -16,7 +16,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', () => {
|
||||
@ -107,3 +107,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);
|
||||
});
|
||||
});
|
||||
|
@ -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<string, string>([
|
||||
['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']
|
||||
|
3309
dist/index.js
generated
vendored
3309
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
@ -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 sepIndex = kvp.indexOf('=');
|
||||
const key = kvp.substr(0, sepIndex);
|
||||
const value = kvp.substr(sepIndex + 1);
|
||||
const secretFile = context.tmpNameSync({
|
||||
tmpdir: context.tmpDir()
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user