diff --git a/.changeset/rude-tips-argue.md b/.changeset/rude-tips-argue.md new file mode 100644 index 0000000000..a66e0935b9 --- /dev/null +++ b/.changeset/rude-tips-argue.md @@ -0,0 +1,5 @@ +--- +'@backstage/integration': patch +--- + +Fixed bug in the `bitbucketServer` integration where token did not take precedence over supplied username and password which is described in the documentation. diff --git a/packages/integration/src/bitbucketServer/core.test.ts b/packages/integration/src/bitbucketServer/core.test.ts index de18dcd821..5ed0780604 100644 --- a/packages/integration/src/bitbucketServer/core.test.ts +++ b/packages/integration/src/bitbucketServer/core.test.ts @@ -42,6 +42,14 @@ describe('bitbucketServer core', () => { username: 'u', password: 'p', }; + const withBasicAuthAndTokenPrecedence: BitbucketServerIntegrationConfig = + { + host: '', + apiBaseUrl: '', + token: 'A', + username: 'u', + password: 'p', + }; const withoutCredentials: BitbucketServerIntegrationConfig = { host: '', apiBaseUrl: '', @@ -54,6 +62,12 @@ describe('bitbucketServer core', () => { (getBitbucketServerRequestOptions(withBasicAuth).headers as any) .Authorization, ).toEqual('Basic dTpw'); + expect( + ( + getBitbucketServerRequestOptions(withBasicAuthAndTokenPrecedence) + .headers as any + ).Authorization, + ).toEqual('Bearer A'); expect( (getBitbucketServerRequestOptions(withoutCredentials).headers as any) .Authorization, diff --git a/packages/integration/src/bitbucketServer/core.ts b/packages/integration/src/bitbucketServer/core.ts index 5fca2aba68..8741b8f0e7 100644 --- a/packages/integration/src/bitbucketServer/core.ts +++ b/packages/integration/src/bitbucketServer/core.ts @@ -139,8 +139,7 @@ export function getBitbucketServerRequestOptions( if (config.token) { headers.Authorization = `Bearer ${config.token}`; - } - if (config.username && config.password) { + } else if (config.username && config.password) { const buffer = Buffer.from(`${config.username}:${config.password}`, 'utf8'); headers.Authorization = `Basic ${buffer.toString('base64')}`; }