renovate/lib/workers/global/config/parse/host-rules-from-env.spec.ts
renovate[bot] 7935a7b8ed
chore(deps): lock file maintenance (#18082)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2022-10-10 21:47:23 -07:00

76 lines
2.2 KiB
TypeScript

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',
};
expect(hostRulesFromEnv(envParam)).toMatchObject([
{
hostType: 'docker',
password: 'some-password',
username: 'some-username',
},
]);
});
it('supports password-only', () => {
const envParam: NodeJS.ProcessEnv = {
NPM_PASSWORD: 'some-password',
};
expect(hostRulesFromEnv(envParam)).toMatchObject([
{ hostType: 'npm', password: 'some-password' },
]);
});
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',
};
expect(hostRulesFromEnv(envParam)).toMatchObject([
{ matchHost: 'github.com', token: 'some-token' },
{ matchHost: 'my.custom.host', password: 'some-password' },
]);
});
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',
};
expect(hostRulesFromEnv(envParam)).toMatchObject([
{
hostType: 'git-tags',
matchHost: 'gitlab.example-domain.net',
password: 'some-password',
username: 'some-user',
},
]);
});
it('supports datasource env token', () => {
const envParam: NodeJS.ProcessEnv = {
PYPI_TOKEN: 'some-token',
};
expect(hostRulesFromEnv(envParam)).toMatchObject([
{ hostType: 'pypi', token: 'some-token' },
]);
});
it('rejects incomplete datasource env token', () => {
const envParam: NodeJS.ProcessEnv = {
PYPI_FOO_TOKEN: 'some-token',
};
expect(hostRulesFromEnv(envParam)).toHaveLength(0);
});
it('rejects npm env', () => {
const envParam: NodeJS.ProcessEnv = {
npm_package_devDependencies__types_registry_auth_token: '4.2.0',
};
expect(hostRulesFromEnv(envParam)).toHaveLength(0);
});
});