|
1 | | -import {afterEach, expect, test} from 'vitest'; |
| 1 | +import {afterEach, expect, test, vi} from 'vitest'; |
2 | 2 | import * as path from 'path'; |
3 | 3 |
|
4 | 4 | import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx.js'; |
5 | 5 |
|
6 | 6 | import {getAuthList, getInputs} from '../src/context.js'; |
7 | 7 |
|
8 | 8 | afterEach(() => { |
| 9 | + vi.restoreAllMocks(); |
9 | 10 | for (const key of Object.keys(process.env)) { |
10 | 11 | if (key.startsWith('INPUT_')) { |
11 | 12 | delete process.env[key]; |
@@ -33,3 +34,37 @@ test('getAuthList uses the default Docker Hub registry when computing scoped con |
33 | 34 | configDir: path.join(Buildx.configDir, 'config', 'registry-1.docker.io', 'myscope') |
34 | 35 | }); |
35 | 36 | }); |
| 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