Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 51b12a0

Browse files
wraithgarfritzy
authored andcommittedJul 19, 2022
deps: npm-registry-fetch@13.3.0
1 parent 64fe64b commit 51b12a0

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed
 

‎node_modules/npm-registry-fetch/lib/auth.js

+34-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict'
2+
const fs = require('fs')
23
const npa = require('npm-package-arg')
34
const { URL } = require('url')
45

@@ -7,7 +8,8 @@ const { URL } = require('url')
78
const regKeyFromURI = (uri, opts) => {
89
const parsed = new URL(uri)
910
// try to find a config key indicating we have auth for this registry
10-
// can be one of :_authToken, :_auth, or :_password and :username
11+
// can be one of :_authToken, :_auth, :_password and :username, or
12+
// :certfile and :keyfile
1113
// We walk up the "path" until we're left with just //<host>[:<port>],
1214
// stopping when we reach '//'.
1315
let regKey = `//${parsed.host}${parsed.pathname}`
@@ -26,7 +28,8 @@ const regKeyFromURI = (uri, opts) => {
2628
const hasAuth = (regKey, opts) => (
2729
opts[`${regKey}:_authToken`] ||
2830
opts[`${regKey}:_auth`] ||
29-
opts[`${regKey}:username`] && opts[`${regKey}:_password`]
31+
opts[`${regKey}:username`] && opts[`${regKey}:_password`] ||
32+
opts[`${regKey}:certfile`] && opts[`${regKey}:keyfile`]
3033
)
3134

3235
const sameHost = (a, b) => {
@@ -44,6 +47,17 @@ const getRegistry = opts => {
4447
return scopeReg || opts.registry
4548
}
4649

50+
const maybeReadFile = file => {
51+
try {
52+
return fs.readFileSync(file, 'utf8')
53+
} catch (er) {
54+
if (er.code !== 'ENOENT') {
55+
throw er
56+
}
57+
return null
58+
}
59+
}
60+
4761
const getAuth = (uri, opts = {}) => {
4862
const { forceAuth } = opts
4963
if (!uri) {
@@ -59,6 +73,8 @@ const getAuth = (uri, opts = {}) => {
5973
username: forceAuth.username,
6074
password: forceAuth._password || forceAuth.password,
6175
auth: forceAuth._auth || forceAuth.auth,
76+
certfile: forceAuth.certfile,
77+
keyfile: forceAuth.keyfile,
6278
})
6379
}
6480

@@ -82,6 +98,8 @@ const getAuth = (uri, opts = {}) => {
8298
[`${regKey}:username`]: username,
8399
[`${regKey}:_password`]: password,
84100
[`${regKey}:_auth`]: auth,
101+
[`${regKey}:certfile`]: certfile,
102+
[`${regKey}:keyfile`]: keyfile,
85103
} = opts
86104

87105
return new Auth({
@@ -90,15 +108,19 @@ const getAuth = (uri, opts = {}) => {
90108
auth,
91109
username,
92110
password,
111+
certfile,
112+
keyfile,
93113
})
94114
}
95115

96116
class Auth {
97-
constructor ({ token, auth, username, password, scopeAuthKey }) {
117+
constructor ({ token, auth, username, password, scopeAuthKey, certfile, keyfile }) {
98118
this.scopeAuthKey = scopeAuthKey
99119
this.token = null
100120
this.auth = null
101121
this.isBasicAuth = false
122+
this.cert = null
123+
this.key = null
102124
if (token) {
103125
this.token = token
104126
} else if (auth) {
@@ -108,6 +130,15 @@ class Auth {
108130
this.auth = Buffer.from(`${username}:${p}`, 'utf8').toString('base64')
109131
this.isBasicAuth = true
110132
}
133+
// mTLS may be used in conjunction with another auth method above
134+
if (certfile && keyfile) {
135+
const cert = maybeReadFile(certfile, 'utf-8')
136+
const key = maybeReadFile(keyfile, 'utf-8')
137+
if (cert && key) {
138+
this.cert = cert
139+
this.key = key
140+
}
141+
}
111142
}
112143
}
113144

‎node_modules/npm-registry-fetch/lib/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ function regFetch (uri, /* istanbul ignore next */ opts_ = {}) {
112112
cache: getCacheMode(opts),
113113
cachePath: opts.cache,
114114
ca: opts.ca,
115-
cert: opts.cert,
115+
cert: auth.cert || opts.cert,
116116
headers,
117117
integrity: opts.integrity,
118-
key: opts.key,
118+
key: auth.key || opts.key,
119119
localAddress: opts.localAddress,
120120
maxSockets: opts.maxSockets,
121121
memoize: opts.memoize,

‎node_modules/npm-registry-fetch/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "npm-registry-fetch",
3-
"version": "13.2.0",
3+
"version": "13.3.0",
44
"description": "Fetch-based http client for use with npm registry APIs",
55
"main": "lib",
66
"files": [

‎package-lock.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
"npm-package-arg": "^9.1.0",
136136
"npm-pick-manifest": "^7.0.1",
137137
"npm-profile": "^6.2.0",
138-
"npm-registry-fetch": "^13.2.0",
138+
"npm-registry-fetch": "^13.3.0",
139139
"npm-user-validate": "^1.0.1",
140140
"npmlog": "^6.0.2",
141141
"opener": "^1.5.2",
@@ -5188,9 +5188,9 @@
51885188
}
51895189
},
51905190
"node_modules/npm-registry-fetch": {
5191-
"version": "13.2.0",
5192-
"resolved": "https://registry.npmjs.org/npm-registry-fetch/-/npm-registry-fetch-13.2.0.tgz",
5193-
"integrity": "sha512-NEKnK02Co31+cnDtnAvEdq9xn6E9yKPK/aOHXZieVbw/qVOcFd7su6kviZjImYoszjM2GykMfGMiyyPUQjUkag==",
5191+
"version": "13.3.0",
5192+
"resolved": "https://registry.npmjs.org/npm-registry-fetch/-/npm-registry-fetch-13.3.0.tgz",
5193+
"integrity": "sha512-10LJQ/1+VhKrZjIuY9I/+gQTvumqqlgnsCufoXETHAPFTS3+M+Z5CFhZRDHGavmJ6rOye3UvNga88vl8n1r6gg==",
51945194
"inBundle": true,
51955195
"dependencies": {
51965196
"make-fetch-happen": "^10.0.6",

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
"npm-package-arg": "^9.1.0",
104104
"npm-pick-manifest": "^7.0.1",
105105
"npm-profile": "^6.2.0",
106-
"npm-registry-fetch": "^13.2.0",
106+
"npm-registry-fetch": "^13.3.0",
107107
"npm-user-validate": "^1.0.1",
108108
"npmlog": "^6.0.2",
109109
"opener": "^1.5.2",

0 commit comments

Comments
 (0)
Please sign in to comment.