Skip to content

Commit 791b661

Browse files
author
Peter Bengtsson
authored
Fix Failbot sending auth (#22396)
Part of #1063
1 parent 2e7194b commit 791b661

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/failbot.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ export default class FailBot {
55
this.app = app
66
this.haystackURL = haystackURL
77
this.headers = headers
8+
9+
// Since we're using `node-fetch` we can't rely on it deconstructing the
10+
// basic authentication credentials from the URL (e.g.
11+
// https://user:pass@failbotdomain/path) because `node-fetch` will always
12+
// strip it. See https://github.com/node-fetch/node-fetch/issues/1330
13+
// and it's not a bug.
14+
// The correct thing is to extract it manually and add an `Authorization`
15+
// header based on it from the URL.
16+
const url = new URL(this.haystackURL)
17+
const { username, password } = url
18+
if (username || password) {
19+
this.headers.Authorization = `Basic ${Buffer.from(`${username}:${password}`).toString(
20+
'base64'
21+
)}`
22+
} else {
23+
console.warn(`The haystack URL does not contain authentication credentials`)
24+
}
825
}
926

1027
/**

0 commit comments

Comments
 (0)