Skip to content

Commit

Permalink
Fix Failbot sending auth (#22396)
Browse files Browse the repository at this point in the history
Part of #1063
  • Loading branch information
peterbe authored Oct 25, 2021
1 parent 2e7194b commit 791b661
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/failbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ export default class FailBot {
this.app = app
this.haystackURL = haystackURL
this.headers = headers

// Since we're using `node-fetch` we can't rely on it deconstructing the
// basic authentication credentials from the URL (e.g.
// https://user:pass@failbotdomain/path) because `node-fetch` will always
// strip it. See https://github.com/node-fetch/node-fetch/issues/1330
// and it's not a bug.
// The correct thing is to extract it manually and add an `Authorization`
// header based on it from the URL.
const url = new URL(this.haystackURL)
const { username, password } = url
if (username || password) {
this.headers.Authorization = `Basic ${Buffer.from(`${username}:${password}`).toString(
'base64'
)}`
} else {
console.warn(`The haystack URL does not contain authentication credentials`)
}
}

/**
Expand Down

0 comments on commit 791b661

Please sign in to comment.