From 28222bf762fbee6d7f75999869e12512befd8313 Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Wed, 15 Sep 2021 17:13:17 +0200 Subject: [PATCH] fix: do not fallback if explicit auth is configured (#11760) Co-authored-by: Rhys Arkins --- lib/platform/index.spec.ts | 5 ----- lib/platform/index.ts | 2 -- lib/util/http/host-rules.spec.ts | 19 ++++++++++++++++++- lib/util/http/host-rules.ts | 5 +++++ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/platform/index.spec.ts b/lib/platform/index.spec.ts index ef366e3a2bc436..1a29be4909fd66 100644 --- a/lib/platform/index.spec.ts +++ b/lib/platform/index.spec.ts @@ -66,11 +66,6 @@ describe('platform/index', () => { password: '123', username: 'abc', }, - { - matchHost: 'api.bitbucket.org', - password: '123', - username: 'abc', - }, ], platform: PLATFORM_TYPE_BITBUCKET, }); diff --git a/lib/platform/index.ts b/lib/platform/index.ts index f86e7382c2da43..8b6a7241dc44d1 100644 --- a/lib/platform/index.ts +++ b/lib/platform/index.ts @@ -71,7 +71,5 @@ export async function initPlatform(config: AllConfig): Promise { }; returnConfig.hostRules.push(typedPlatformRule); hostRules.add(typedPlatformRule); - returnConfig.hostRules.push(platformRule); - hostRules.add(platformRule); return returnConfig; } diff --git a/lib/util/http/host-rules.spec.ts b/lib/util/http/host-rules.spec.ts index a46e6d32308288..b4c8ebfd944c50 100644 --- a/lib/util/http/host-rules.spec.ts +++ b/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'; @@ -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(` diff --git a/lib/util/http/host-rules.ts b/lib/util/http/host-rules.ts index d327f0418e9363..86537e4ea12c17 100644 --- a/lib/util/http/host-rules.ts +++ b/lib/util/http/host-rules.ts @@ -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) &&