Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not fallback if explicit auth is configured #11760

Merged
merged 3 commits into from Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
rarkins marked this conversation as resolved.
Show resolved Hide resolved
}

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