Skip to content

Commit 4835190

Browse files
committed
skip empty registry-auth secret mask
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 992421c commit 4835190

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

__tests__/context.test.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import {afterEach, expect, test} from 'vitest';
1+
import {afterEach, expect, test, vi} from 'vitest';
22
import * as path from 'path';
33

44
import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx.js';
55

66
import {getAuthList, getInputs} from '../src/context.js';
77

88
afterEach(() => {
9+
vi.restoreAllMocks();
910
for (const key of Object.keys(process.env)) {
1011
if (key.startsWith('INPUT_')) {
1112
delete process.env[key];
@@ -33,3 +34,37 @@ test('getAuthList uses the default Docker Hub registry when computing scoped con
3334
configDir: path.join(Buildx.configDir, 'config', 'registry-1.docker.io', 'myscope')
3435
});
3536
});
37+
38+
test('getAuthList skips secret masking when registry-auth password is absent', async () => {
39+
const stdoutWriteSpy = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);
40+
const [auth] = getAuthList({
41+
registry: '',
42+
username: '',
43+
password: '',
44+
scope: '',
45+
ecr: '',
46+
logout: true,
47+
registryAuth: '- registry: public.ecr.aws\n'
48+
});
49+
50+
expect(stdoutWriteSpy.mock.calls.map(call => call[0]).join('')).not.toContain('::add-mask::');
51+
expect(auth).toMatchObject({
52+
registry: 'public.ecr.aws',
53+
ecr: 'auto'
54+
});
55+
});
56+
57+
test('getAuthList masks registry-auth password when present', async () => {
58+
const stdoutWriteSpy = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);
59+
getAuthList({
60+
registry: '',
61+
username: '',
62+
password: '',
63+
scope: '',
64+
ecr: '',
65+
logout: true,
66+
registryAuth: '- registry: ghcr.io\n username: dbowie\n password: groundcontrol\n'
67+
});
68+
69+
expect(stdoutWriteSpy.mock.calls.map(call => call[0]).join('')).toContain('::add-mask::groundcontrol');
70+
});

src/context.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export function getAuthList(inputs: Inputs): Array<Auth> {
5353
});
5454
} else {
5555
auths = (yaml.load(inputs.registryAuth) as Array<Auth>).map(auth => {
56-
core.setSecret(auth.password); // redacted in workflow logs
56+
if (auth.password) {
57+
core.setSecret(auth.password); // redacted in workflow logs
58+
}
5759
const registry = auth.registry || 'docker.io';
5860
return {
5961
registry,

0 commit comments

Comments
 (0)