Skip to content

Commit ca0a662

Browse files
authored
Merge pull request #1035 from crazy-max/fix-registry-auth-empty-mask
skip empty registry-auth secret mask
2 parents 992421c + c455755 commit ca0a662

4 files changed

Lines changed: 42 additions & 5 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+
});

0 commit comments

Comments
 (0)