mirror of
https://github.com/docker/login-action.git
synced 2026-03-25 14:27:40 +08:00
Merge pull request #945 from crazy-max/fix-scope-dir-dockerhub
fix scoped Docker Hub cleanup path when registry is omitted
This commit is contained in:
commit
717e062c09
@ -1,6 +1,17 @@
|
|||||||
import {expect, test} from 'vitest';
|
import {afterEach, expect, test} from 'vitest';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
import {getInputs} from '../src/context.js';
|
import {Buildx} from '@docker/actions-toolkit/lib/buildx/buildx.js';
|
||||||
|
|
||||||
|
import {getAuthList, getInputs} from '../src/context.js';
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
for (const key of Object.keys(process.env)) {
|
||||||
|
if (key.startsWith('INPUT_')) {
|
||||||
|
delete process.env[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('with password and username getInputs does not throw error', async () => {
|
test('with password and username getInputs does not throw error', async () => {
|
||||||
process.env['INPUT_USERNAME'] = 'dbowie';
|
process.env['INPUT_USERNAME'] = 'dbowie';
|
||||||
@ -10,3 +21,15 @@ test('with password and username getInputs does not throw error', async () => {
|
|||||||
getInputs();
|
getInputs();
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('getAuthList uses the default Docker Hub registry when computing scoped config dir', async () => {
|
||||||
|
process.env['INPUT_USERNAME'] = 'dbowie';
|
||||||
|
process.env['INPUT_PASSWORD'] = 'groundcontrol';
|
||||||
|
process.env['INPUT_SCOPE'] = 'myscope';
|
||||||
|
process.env['INPUT_LOGOUT'] = 'false';
|
||||||
|
const [auth] = getAuthList(getInputs());
|
||||||
|
expect(auth).toMatchObject({
|
||||||
|
registry: 'docker.io',
|
||||||
|
configDir: path.join(Buildx.configDir, 'config', 'registry-1.docker.io', 'myscope')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@ -1,15 +1,10 @@
|
|||||||
import {expect, test, vi} from 'vitest';
|
import {expect, test, vi} from 'vitest';
|
||||||
import * as path from 'path';
|
|
||||||
|
|
||||||
import {Docker} from '@docker/actions-toolkit/lib/docker/docker.js';
|
import {Docker} from '@docker/actions-toolkit/lib/docker/docker.js';
|
||||||
|
|
||||||
import {loginStandard, logout} from '../src/docker.js';
|
import {loginStandard, logout} from '../src/docker.js';
|
||||||
|
|
||||||
process.env['RUNNER_TEMP'] = path.join(__dirname, 'runner');
|
|
||||||
|
|
||||||
test('loginStandard calls exec', async () => {
|
test('loginStandard calls exec', async () => {
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
const execSpy = vi.spyOn(Docker, 'getExecOutput').mockImplementation(async () => {
|
const execSpy = vi.spyOn(Docker, 'getExecOutput').mockImplementation(async () => {
|
||||||
return {
|
return {
|
||||||
exitCode: expect.any(Number),
|
exitCode: expect.any(Number),
|
||||||
@ -38,8 +33,6 @@ test('loginStandard calls exec', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('logout calls exec', async () => {
|
test('logout calls exec', async () => {
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
const execSpy = vi.spyOn(Docker, 'getExecOutput').mockImplementation(async () => {
|
const execSpy = vi.spyOn(Docker, 'getExecOutput').mockImplementation(async () => {
|
||||||
return {
|
return {
|
||||||
exitCode: expect.any(Number),
|
exitCode: expect.any(Number),
|
||||||
|
|||||||
2
dist/index.js
generated
vendored
2
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@ -42,24 +42,26 @@ export function getAuthList(inputs: Inputs): Array<Auth> {
|
|||||||
}
|
}
|
||||||
let auths: Array<Auth> = [];
|
let auths: Array<Auth> = [];
|
||||||
if (!inputs.registryAuth) {
|
if (!inputs.registryAuth) {
|
||||||
|
const registry = inputs.registry || 'docker.io';
|
||||||
auths.push({
|
auths.push({
|
||||||
registry: inputs.registry || 'docker.io',
|
registry,
|
||||||
username: inputs.username,
|
username: inputs.username,
|
||||||
password: inputs.password,
|
password: inputs.password,
|
||||||
scope: inputs.scope,
|
scope: inputs.scope,
|
||||||
ecr: inputs.ecr || 'auto',
|
ecr: inputs.ecr || 'auto',
|
||||||
configDir: scopeToConfigDir(inputs.registry, inputs.scope)
|
configDir: scopeToConfigDir(registry, inputs.scope)
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
auths = (yaml.load(inputs.registryAuth) as Array<Auth>).map(auth => {
|
auths = (yaml.load(inputs.registryAuth) as Array<Auth>).map(auth => {
|
||||||
core.setSecret(auth.password); // redacted in workflow logs
|
core.setSecret(auth.password); // redacted in workflow logs
|
||||||
|
const registry = auth.registry || 'docker.io';
|
||||||
return {
|
return {
|
||||||
registry: auth.registry || 'docker.io',
|
registry,
|
||||||
username: auth.username,
|
username: auth.username,
|
||||||
password: auth.password,
|
password: auth.password,
|
||||||
scope: auth.scope,
|
scope: auth.scope,
|
||||||
ecr: auth.ecr || 'auto',
|
ecr: auth.ecr || 'auto',
|
||||||
configDir: scopeToConfigDir(auth.registry || 'docker.io', auth.scope)
|
configDir: scopeToConfigDir(registry, auth.scope)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user