fix: COREPACK_NPM_REGISTRY should allow for username/password auth#466
Merged
aduh95 merged 2 commits intonodejs:mainfrom Apr 24, 2024
Merged
fix: COREPACK_NPM_REGISTRY should allow for username/password auth#466aduh95 merged 2 commits intonodejs:mainfrom
aduh95 merged 2 commits intonodejs:mainfrom
Conversation
Contributor
|
Thanks for the PR, that makes sense. Do you know why the tests do not catch that? We're checking against a custom mock repository, which should validate authentication works 🤔 |
Contributor
|
Well I found the problem: the mock registry would skip auth validation if none was provided, Windows 95 style 🤦♂️ Can you apply the following diff to ensure we don't regress: diff --git a/tests/_registryServer.mjs b/tests/_registryServer.mjs
index ff0be26..d051b0a 100644
--- a/tests/_registryServer.mjs
+++ b/tests/_registryServer.mjs
@@ -116,8 +116,10 @@ const server = createServer((req, res) => {
const auth = req.headers.authorization;
if (
- (auth?.startsWith(`Bearer `) && auth.slice(`Bearer `.length) !== TOKEN_MOCK) ||
- (auth?.startsWith(`Basic `) && Buffer.from(auth.slice(`Basic `.length), `base64`).toString() !== `user:pass`)
+ auth == null ||
+ (auth.startsWith(`Bearer `) && auth.slice(`Bearer `.length) !== TOKEN_MOCK) ||
+ (auth.startsWith(`Basic `) && Buffer.from(auth.slice(`Basic `.length), `base64`).toString() !== `user:pass`) ||
+ !/^(Basic|Bearer) /.test(auth)
) {
res.writeHead(401).end(`Unauthorized`);
return; |
aduh95
approved these changes
Apr 24, 2024
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I noticed when using this package, if you set
COREPACK_NPM_REGISTRY, authentication wasn't working as expected.After debugging and reading through the code, it appears that when the following code was run:
input.usernamewould become an empty string. This causedprocess.env.COREPACK_NPM_USERNAMEto not be used.By switching
??to||, the authorization header should now be sent to the registry as expected!