2021-10-23 06:38:23 +00:00
|
|
|
import { hostRulesFromEnv } from './host-rules-from-env';
|
|
|
|
|
|
|
|
describe('workers/global/config/parse/host-rules-from-env', () => {
|
|
|
|
it('supports docker username/password', () => {
|
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
|
|
|
DOCKER_USERNAME: 'some-username',
|
|
|
|
DOCKER_PASSWORD: 'some-password',
|
|
|
|
};
|
2022-10-11 04:47:23 +00:00
|
|
|
expect(hostRulesFromEnv(envParam)).toMatchObject([
|
2021-10-23 06:38:23 +00:00
|
|
|
{
|
|
|
|
hostType: 'docker',
|
|
|
|
password: 'some-password',
|
|
|
|
username: 'some-username',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2021-10-23 06:38:23 +00:00
|
|
|
it('supports password-only', () => {
|
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
|
|
|
NPM_PASSWORD: 'some-password',
|
|
|
|
};
|
2022-10-11 04:47:23 +00:00
|
|
|
expect(hostRulesFromEnv(envParam)).toMatchObject([
|
2021-10-23 06:38:23 +00:00
|
|
|
{ hostType: 'npm', password: 'some-password' },
|
|
|
|
]);
|
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2021-10-23 06:38:23 +00:00
|
|
|
it('supports domain and host names with case insensitivity', () => {
|
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
|
|
|
GITHUB__TAGS_GITHUB_COM_TOKEN: 'some-token',
|
|
|
|
pypi_my_CUSTOM_HOST_passWORD: 'some-password',
|
|
|
|
};
|
|
|
|
|
2022-10-11 04:47:23 +00:00
|
|
|
expect(hostRulesFromEnv(envParam)).toMatchObject([
|
2021-10-23 06:38:23 +00:00
|
|
|
{ matchHost: 'github.com', token: 'some-token' },
|
|
|
|
{ matchHost: 'my.custom.host', password: 'some-password' },
|
|
|
|
]);
|
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2021-10-23 06:38:23 +00:00
|
|
|
it('regression test for #10937', () => {
|
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
|
|
|
GIT__TAGS_GITLAB_EXAMPLE__DOMAIN_NET_USERNAME: 'some-user',
|
|
|
|
GIT__TAGS_GITLAB_EXAMPLE__DOMAIN_NET_PASSWORD: 'some-password',
|
|
|
|
};
|
2022-10-11 04:47:23 +00:00
|
|
|
expect(hostRulesFromEnv(envParam)).toMatchObject([
|
2021-10-23 06:38:23 +00:00
|
|
|
{
|
|
|
|
hostType: 'git-tags',
|
|
|
|
matchHost: 'gitlab.example-domain.net',
|
|
|
|
password: 'some-password',
|
|
|
|
username: 'some-user',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2021-10-23 06:38:23 +00:00
|
|
|
it('supports datasource env token', () => {
|
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
|
|
|
PYPI_TOKEN: 'some-token',
|
|
|
|
};
|
2022-10-11 04:47:23 +00:00
|
|
|
expect(hostRulesFromEnv(envParam)).toMatchObject([
|
2021-10-23 06:38:23 +00:00
|
|
|
{ hostType: 'pypi', token: 'some-token' },
|
|
|
|
]);
|
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2021-10-23 06:38:23 +00:00
|
|
|
it('rejects incomplete datasource env token', () => {
|
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
|
|
|
PYPI_FOO_TOKEN: 'some-token',
|
|
|
|
};
|
|
|
|
expect(hostRulesFromEnv(envParam)).toHaveLength(0);
|
|
|
|
});
|
2022-04-12 14:49:49 +00:00
|
|
|
|
2021-10-23 06:38:23 +00:00
|
|
|
it('rejects npm env', () => {
|
|
|
|
const envParam: NodeJS.ProcessEnv = {
|
|
|
|
npm_package_devDependencies__types_registry_auth_token: '4.2.0',
|
|
|
|
};
|
|
|
|
expect(hostRulesFromEnv(envParam)).toHaveLength(0);
|
|
|
|
});
|
|
|
|
});
|