Skip to content

Commit 6efa349

Browse files
authored
fix: COREPACK_NPM_REGISTRY should allow for username/password auth (#466)
1 parent 78781fa commit 6efa349

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

sources/httpUtils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ async function fetch(input: string | URL, init?: RequestInit) {
1717

1818
let headers = init?.headers;
1919

20-
const username: string | undefined = input.username ?? process.env.COREPACK_NPM_USERNAME;
21-
const password: string | undefined = input.password ?? process.env.COREPACK_NPM_PASSWORD;
20+
const username: string | undefined = input.username || process.env.COREPACK_NPM_USERNAME;
21+
const password: string | undefined = input.password || process.env.COREPACK_NPM_PASSWORD;
2222

2323
if (username || password) {
2424
headers = {

tests/_registryServer.mjs

+4-2
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ const server = createServer((req, res) => {
116116
const auth = req.headers.authorization;
117117

118118
if (
119-
(auth?.startsWith(`Bearer `) && auth.slice(`Bearer `.length) !== TOKEN_MOCK) ||
120-
(auth?.startsWith(`Basic `) && Buffer.from(auth.slice(`Basic `.length), `base64`).toString() !== `user:pass`)
119+
auth == null ||
120+
(auth.startsWith(`Bearer `) && auth.slice(`Bearer `.length) !== TOKEN_MOCK) ||
121+
(auth.startsWith(`Basic `) && Buffer.from(auth.slice(`Basic `.length), `base64`).toString() !== `user:pass`) ||
122+
!/^(Basic|Bearer) /.test(auth)
121123
) {
122124
res.writeHead(401).end(`Unauthorized`);
123125
return;

0 commit comments

Comments
 (0)