Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion __tests__/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {afterEach, expect, test} from 'vitest';
import {afterEach, expect, test, vi} from 'vitest';
import * as path from 'path';

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

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

afterEach(() => {
vi.restoreAllMocks();
for (const key of Object.keys(process.env)) {
if (key.startsWith('INPUT_')) {
delete process.env[key];
Expand Down Expand Up @@ -33,3 +34,37 @@ test('getAuthList uses the default Docker Hub registry when computing scoped con
configDir: path.join(Buildx.configDir, 'config', 'registry-1.docker.io', 'myscope')
});
});

test('getAuthList skips secret masking when registry-auth password is absent', async () => {
const stdoutWriteSpy = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);
const [auth] = getAuthList({
registry: '',
username: '',
password: '',
scope: '',
ecr: '',
logout: true,
registryAuth: '- registry: public.ecr.aws\n'
});

expect(stdoutWriteSpy.mock.calls.map(call => call[0]).join('')).not.toContain('::add-mask::');
expect(auth).toMatchObject({
registry: 'public.ecr.aws',
ecr: 'auto'
});
});

test('getAuthList masks registry-auth password when present', async () => {
const stdoutWriteSpy = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);
getAuthList({
registry: '',
username: '',
password: '',
scope: '',
ecr: '',
logout: true,
registryAuth: '- registry: ghcr.io\n username: dbowie\n password: groundcontrol\n'
});

expect(stdoutWriteSpy.mock.calls.map(call => call[0]).join('')).toContain('::add-mask::groundcontrol');
});
Loading