mirror of
https://github.com/docker/login-action.git
synced 2026-10-23 23:03:07 +01:00
use registry hosts for scoped credentials
Parse registry URLs so scoped ECR credentials use the same config directory for login, logout, and Buildx lookup. Preserve explicit default ports. Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -3,7 +3,7 @@ import * as path from 'path';
|
||||
|
||||
import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx.js';
|
||||
|
||||
import {getAuthList, getInputs} from '../src/context.js';
|
||||
import {getAuthList, getInputs, scopeToConfigDir} from '../src/context.js';
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
@@ -188,3 +188,23 @@ test.each([
|
||||
});
|
||||
expect(auth.ecr).toBe(expected);
|
||||
});
|
||||
|
||||
// prettier-ignore
|
||||
test.each([
|
||||
['ghcr.io', 'ghcr.io'],
|
||||
['ghcr.io/', 'ghcr.io'],
|
||||
['https://ghcr.io', 'ghcr.io'],
|
||||
['https://ghcr.io/', 'ghcr.io'],
|
||||
['https://ghcr.io/v2/', 'ghcr.io'],
|
||||
['http://localhost:5000', 'localhost:5000'],
|
||||
['http://localhost:80', 'localhost:80'],
|
||||
['https://ghcr.io:443', 'ghcr.io:443'],
|
||||
['https://012345678910.dkr.ecr.eu-west-3.amazonaws.com', '012345678910.dkr.ecr.eu-west-3.amazonaws.com'],
|
||||
['https://docker.io', 'registry-1.docker.io']
|
||||
])('scopeToConfigDir uses the registry host for %s', (registry, host) => {
|
||||
expect(scopeToConfigDir(registry, 'myorg/myimage@push')).toBe(path.join(Buildx.configDir, 'config', host, 'myorg', 'myimage') + '@push');
|
||||
});
|
||||
|
||||
test('scopeToConfigDir rejects a URL whose host escapes the config directory', () => {
|
||||
expect(() => scopeToConfigDir('https://../', '@push')).toThrow(/Invalid registry/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user