Skip to content
Permalink
Browse files
fix: do not fallback if explicit auth is configured (#11760)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
viceice and rarkins committed Sep 15, 2021
1 parent 1d528fc commit 28222bf762fbee6d7f75999869e12512befd8313
Showing with 23 additions and 8 deletions.
  1. +0 −5 lib/platform/index.spec.ts
  2. +0 −2 lib/platform/index.ts
  3. +18 −1 lib/util/http/host-rules.spec.ts
  4. +5 −0 lib/util/http/host-rules.ts
@@ -66,11 +66,6 @@ describe('platform/index', () => {
password: '123',
username: 'abc',
},
{
matchHost: 'api.bitbucket.org',
password: '123',
username: 'abc',
},
],
platform: PLATFORM_TYPE_BITBUCKET,
});
@@ -71,7 +71,5 @@ export async function initPlatform(config: AllConfig): Promise<AllConfig> {
};
returnConfig.hostRules.push(typedPlatformRule);
hostRules.add(typedPlatformRule);
returnConfig.hostRules.push(platformRule);
hostRules.add(platformRule);
return returnConfig;
}
@@ -1,6 +1,7 @@
import {
PLATFORM_TYPE_GITEA,
PLATFORM_TYPE_GITHUB,
PLATFORM_TYPE_GITLAB,
} from '../../constants/platforms';
import { bootstrap } from '../../proxy';
import * as hostRules from '../host-rules';
@@ -38,9 +39,15 @@ describe('util/http/host-rules', () => {
});

hostRules.add({
hostType: 'gitlab-tags',
hostType: PLATFORM_TYPE_GITLAB,
token: 'abc',
});

hostRules.add({
hostType: 'github-releases',
username: 'some',
password: 'xxx',
});
});

afterEach(() => {
@@ -127,6 +134,16 @@ describe('util/http/host-rules', () => {
`);
});

it('no fallback', () => {
expect(
applyHostRules(url, { ...options, hostType: 'github-releases' })
).toEqual({
hostType: 'github-releases',
username: 'some',
password: 'xxx',
});
});

it('fallback to github', () => {
expect(applyHostRules(url, { ...options, hostType: 'github-tags' }))
.toMatchInlineSnapshot(`
@@ -14,6 +14,11 @@ function findMatchingRules(options: GotOptions, url: string): HostRule {
const { hostType } = options;
let res = hostRules.find({ hostType, url });

if (res.token || res.username || res.password) {
// do not fallback if we already have auth infos
return res;
}

// Fallback to `github` hostType
if (
GITHUB_API_USING_HOST_TYPES.includes(hostType) &&

0 comments on commit 28222bf

Please sign in to comment.