-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: set user credentials in URL as Authorization header (#5884)
* Add functions to encode / decode base64 * Move URL validation function to utils package * Improve URL validation and fail on startup * Set user credentials in URL as Authorization header * Improve monitoring endpoint validation errors * Fix http client fallback tests * Always remove username and password from URL
- Loading branch information
Showing
14 changed files
with
107 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const hasBufferFrom = typeof Buffer !== "undefined" && typeof Buffer.from === "function"; | ||
|
||
export function toBase64(value: string): string { | ||
return hasBufferFrom ? Buffer.from(value).toString("base64") : btoa(value); | ||
} | ||
|
||
export function fromBase64(value: string): string { | ||
return hasBufferFrom ? Buffer.from(value, "base64").toString("utf8") : atob(value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export function isValidHttpUrl(urlStr: string): boolean { | ||
let url; | ||
try { | ||
url = new URL(urlStr); | ||
} catch (_) { | ||
return false; | ||
} | ||
|
||
return url.protocol === "http:" || url.protocol === "https:"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import "../setup.js"; | ||
import {expect} from "chai"; | ||
import {toBase64, fromBase64} from "../../src/index.js"; | ||
|
||
describe("toBase64", () => { | ||
it("should encode UTF-8 string as base64 string", () => { | ||
expect(toBase64("user:password")).to.be.equal("dXNlcjpwYXNzd29yZA=="); | ||
}); | ||
}); | ||
|
||
describe("fromBase64", () => { | ||
it("should decode UTF-8 string from base64 string", () => { | ||
expect(fromBase64("dXNlcjpwYXNzd29yZA==")).to.be.equal("user:password"); | ||
}); | ||
}); |