From 6e06c1d1ab9d4c2082394aa4072a6fb9a2330c32 Mon Sep 17 00:00:00 2001 From: Robert Schuh Date: Sat, 3 Sep 2022 02:24:40 +0200 Subject: [PATCH 1/5] Use username password or token for bitbucket server The bitbucket server publish action allows setting the token like other platforms, if the integration has a username and password configured though, not the token but the credentials are used In config.ts the docs claim token takes precedence which only holds true if username & password are not set Signed-off-by: Robert Schuh --- packages/integration/src/bitbucketServer/core.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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')}`; } From d2ca018f4372fffabac1fe72727038400652d358 Mon Sep 17 00:00:00 2001 From: Robert Schuh Date: Sat, 3 Sep 2022 03:16:48 +0200 Subject: [PATCH 2/5] Add a test for the precedence Signed-off-by: Robert Schuh --- packages/integration/src/bitbucketServer/core.test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/integration/src/bitbucketServer/core.test.ts b/packages/integration/src/bitbucketServer/core.test.ts index de18dcd821..5184d14ba7 100644 --- a/packages/integration/src/bitbucketServer/core.test.ts +++ b/packages/integration/src/bitbucketServer/core.test.ts @@ -42,6 +42,13 @@ 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 +61,10 @@ 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, From 42918e085cf0e5fb0502ab3005500c1a560724e2 Mon Sep 17 00:00:00 2001 From: Robert Schuh Date: Sat, 3 Sep 2022 03:22:21 +0200 Subject: [PATCH 3/5] Add a changeset Signed-off-by: Robert Schuh --- .changeset/rude-tips-argue.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/rude-tips-argue.md diff --git a/.changeset/rude-tips-argue.md b/.changeset/rude-tips-argue.md new file mode 100644 index 0000000000..40441d6c0b --- /dev/null +++ b/.changeset/rude-tips-argue.md @@ -0,0 +1,5 @@ +--- +'@backstage/integration': patch +--- + +have token take precedence over username and password in the bitbucketServer integration according to documentation From 66952b3f281e94496159ff5fd012f5a76c7e9520 Mon Sep 17 00:00:00 2001 From: Robert Schuh Date: Sun, 4 Sep 2022 02:21:39 +0200 Subject: [PATCH 4/5] Fix prettier Signed-off-by: Robert Schuh --- .../src/bitbucketServer/core.test.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/integration/src/bitbucketServer/core.test.ts b/packages/integration/src/bitbucketServer/core.test.ts index 5184d14ba7..5ed0780604 100644 --- a/packages/integration/src/bitbucketServer/core.test.ts +++ b/packages/integration/src/bitbucketServer/core.test.ts @@ -42,13 +42,14 @@ describe('bitbucketServer core', () => { username: 'u', password: 'p', }; - const withBasicAuthAndTokenPrecedence: BitbucketServerIntegrationConfig = { - host: '', - apiBaseUrl: '', - token: 'A', - username: 'u', - password: 'p', - }; + const withBasicAuthAndTokenPrecedence: BitbucketServerIntegrationConfig = + { + host: '', + apiBaseUrl: '', + token: 'A', + username: 'u', + password: 'p', + }; const withoutCredentials: BitbucketServerIntegrationConfig = { host: '', apiBaseUrl: '', @@ -62,8 +63,10 @@ describe('bitbucketServer core', () => { .Authorization, ).toEqual('Basic dTpw'); expect( - (getBitbucketServerRequestOptions(withBasicAuthAndTokenPrecedence).headers as any) - .Authorization, + ( + getBitbucketServerRequestOptions(withBasicAuthAndTokenPrecedence) + .headers as any + ).Authorization, ).toEqual('Bearer A'); expect( (getBitbucketServerRequestOptions(withoutCredentials).headers as any) From fc8eaa6cda4a377548a5a11fb861406f2decc436 Mon Sep 17 00:00:00 2001 From: Robert Schuh Date: Mon, 5 Sep 2022 11:27:16 +0200 Subject: [PATCH 5/5] Update .changeset/rude-tips-argue.md Co-authored-by: Johan Haals Signed-off-by: Robert Schuh --- .changeset/rude-tips-argue.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/rude-tips-argue.md b/.changeset/rude-tips-argue.md index 40441d6c0b..a66e0935b9 100644 --- a/.changeset/rude-tips-argue.md +++ b/.changeset/rude-tips-argue.md @@ -2,4 +2,4 @@ '@backstage/integration': patch --- -have token take precedence over username and password in the bitbucketServer integration according to documentation +Fixed bug in the `bitbucketServer` integration where token did not take precedence over supplied username and password which is described in the documentation.