Merge pull request #13516 from Robbilie/patch-1
Use username password or token for bitbucket server
This commit is contained in:
@@ -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')}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user