Skip to content

Commit

Permalink
fix: do not fallback if explicit auth is configured (#11760)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
viceice and rarkins committed Sep 15, 2021
1 parent 1d528fc commit 28222bf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
5 changes: 0 additions & 5 deletions lib/platform/index.spec.ts
Expand Up @@ -66,11 +66,6 @@ describe('platform/index', () => {
password: '123',
username: 'abc',
},
{
matchHost: 'api.bitbucket.org',
password: '123',
username: 'abc',
},
],
platform: PLATFORM_TYPE_BITBUCKET,
});
Expand Down
2 changes: 0 additions & 2 deletions lib/platform/index.ts
Expand Up @@ -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;
}
19 changes: 18 additions & 1 deletion lib/util/http/host-rules.spec.ts
@@ -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';
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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(`
Expand Down
5 changes: 5 additions & 0 deletions lib/util/http/host-rules.ts
Expand Up @@ -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) &&
Expand Down

0 comments on commit 28222bf

Please sign in to comment.