Merge pull request #13516 from Robbilie/patch-1

Use username password or token for bitbucket server
This commit is contained in:
Johan Haals
2022-09-06 09:12:10 +02:00
committed by GitHub
3 changed files with 20 additions and 2 deletions
+5
View File
@@ -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.
@@ -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,
@@ -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')}`;
}