Skip to content

Commit

Permalink
fix: COREPACK_NPM_REGISTRY should allow for username/password auth (#466
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Keysox authored Apr 24, 2024
1 parent 78781fa commit 6efa349
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions sources/httpUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ async function fetch(input: string | URL, init?: RequestInit) {

let headers = init?.headers;

const username: string | undefined = input.username ?? process.env.COREPACK_NPM_USERNAME;
const password: string | undefined = input.password ?? process.env.COREPACK_NPM_PASSWORD;
const username: string | undefined = input.username || process.env.COREPACK_NPM_USERNAME;
const password: string | undefined = input.password || process.env.COREPACK_NPM_PASSWORD;

if (username || password) {
headers = {
Expand Down
6 changes: 4 additions & 2 deletions tests/_registryServer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6efa349

Please sign in to comment.