renovate/lib/util/http/host-rules.spec.ts

115 lines
2.4 KiB
TypeScript
Raw Normal View History

import {
PLATFORM_TYPE_GITEA,
PLATFORM_TYPE_GITHUB,
} from '../../constants/platforms';
2020-08-11 09:53:23 +00:00
import { bootstrap } from '../../proxy';
import * as hostRules from '../host-rules';
import { applyHostRules } from './host-rules';
const url = 'https://github.com';
2020-08-11 09:53:23 +00:00
jest.mock('global-agent');
describe('util/http/host-rules', () => {
const options = {
hostType: PLATFORM_TYPE_GITHUB,
};
beforeEach(() => {
// reset module
jest.resetAllMocks();
2020-08-11 09:53:23 +00:00
delete process.env.HTTP_PROXY;
// clean up hostRules
hostRules.clear();
hostRules.add({
hostType: PLATFORM_TYPE_GITHUB,
token: 'token',
});
hostRules.add({
hostType: PLATFORM_TYPE_GITEA,
password: 'password',
});
hostRules.add({
hostType: 'npm',
authType: 'Basic',
token: 'XXX',
});
});
2020-08-11 09:53:23 +00:00
afterEach(() => {
delete process.env.HTTP_PROXY;
});
it('adds token', () => {
expect(applyHostRules(url, { ...options })).toMatchInlineSnapshot(`
Object {
"context": Object {
"authType": undefined,
},
"hostType": "github",
"token": "token",
}
`);
});
it('adds auth', () => {
expect(applyHostRules(url, { hostType: PLATFORM_TYPE_GITEA }))
.toMatchInlineSnapshot(`
Object {
"hostType": "gitea",
"password": "password",
"username": undefined,
}
`);
});
it('adds custom auth', () => {
expect(applyHostRules(url, { hostType: 'npm' })).toMatchInlineSnapshot(`
Object {
"context": Object {
"authType": "Basic",
},
"hostType": "npm",
"token": "XXX",
}
`);
});
it('skips', () => {
expect(applyHostRules(url, { ...options, token: 'xxx' }))
.toMatchInlineSnapshot(`
Object {
"hostType": "github",
"token": "xxx",
}
`);
});
2020-08-11 09:53:23 +00:00
it('uses http2', () => {
hostRules.add({ enableHttp2: true });
expect(applyHostRules(url, { ...options, token: 'xxx' }))
.toMatchInlineSnapshot(`
Object {
"hostType": "github",
"http2": true,
"token": "xxx",
}
`);
});
it('disables http2', () => {
process.env.HTTP_PROXY = 'http://proxy';
bootstrap();
hostRules.add({ enableHttp2: true });
expect(applyHostRules(url, { ...options, token: 'xxx' }))
.toMatchInlineSnapshot(`
Object {
"hostType": "github",
"token": "xxx",
}
`);
});
});