Closed mikicho closed 11 months ago
Seems like password without a user is ok too 😅
add a fallback to the password value to make sure it's an empty string if it's not set.
I thought about it, but isn't it the job of the normalization function?
@mikicho, not really. The normalization happens between the variable nature of the ClientRequest
options, but we still treat the given values as-is. In this case, if the URL
has been given, we will operate with its url.username
and url.password
values as they were provided to prevent any confusion.
Besides, this fallback value logic is necessary only in the context of the
Authorization
header so it belongs here.
Regarding the password being optional too, I suggest then making this check OR-OR and composing the auth
string taking the optional nature of the two values into account.
if (username != null || password != null) {
const resolvedUsername = username || ''
const resolvedPassword = password || ''
const auth = `${resolvedUsername}:${resolvedPassword}`
}
@kettanaito PTAL. Feel free to update the formatting :)
This has been released in v0.25.5!
Make sure to always update to the latest version (npm i @mswjs/interceptors@latest
) to get the newest features and bug fixes.
Predictable release automation by @ossjs/release.
According to this test, passwords are not mandatory.
I couldn't find any specific spec for this, but I guess that if Nock has a test for it someone needed this.