3
0
Fork 0
mirror of https://gitea.com/docker/build-push-action.git synced 2024-11-25 10:59:38 +01:00

Merge pull request #201 from mathieubergeron/fix-parse-secret-containing-equal-character

Fix parsing of secrets containing '=' character
This commit is contained in:
CrazyMax 2020-10-23 22:39:07 +02:00 committed by GitHub
commit bef45c0027
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 7 deletions

View file

@ -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);
});
});

View file

@ -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']

4
dist/index.js generated vendored
View file

@ -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()
});

View file

@ -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()
});