diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2014-06-18 11:19:39 +0400 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2014-07-02 05:43:16 +0400 |
commit | 0689ba249b92b4c6279a26804c96af6f92b3a501 (patch) | |
tree | c1d56154d44ee0f25eefbd0bdc5c8c4413007721 /node_modules/npm-registry-client | |
parent | 4441ea1ca17c584a12c266beacf4f9a77d763dfc (diff) |
use --scope to map scope to registry
Diffstat (limited to 'node_modules/npm-registry-client')
10 files changed, 205 insertions, 93 deletions
diff --git a/node_modules/npm-registry-client/lib/publish.js b/node_modules/npm-registry-client/lib/publish.js index 745d93297..aea8565bf 100644 --- a/node_modules/npm-registry-client/lib/publish.js +++ b/node_modules/npm-registry-client/lib/publish.js @@ -7,14 +7,22 @@ var url = require("url") , fs = require("fs") , fixNameField = require("normalize-package-data/lib/fixer.js").fixNameField +var toNerfDart = require("./util/nerf-dart.js") + function escaped(name) { return name.replace("/", "%2f") } function publish (uri, data, tarball, cb) { - var email = this.conf.get('email') - var auth = this.conf.get('_auth') - var username = this.conf.get('username') + var email = this.conf.get('email') || + this.conf.get(toNerfDart(uri) + ':email') + var auth = this.conf.get('_auth') || + this.conf.get(toNerfDart(uri) + ':_auth') + var username + if (auth) { + var creds = new Buffer(auth, "base64").toString("utf8") + if (creds) username = creds.split(":")[0] + } if (!email || !auth || !username) { var er = new Error("auth and email required for publishing") diff --git a/node_modules/npm-registry-client/lib/request.js b/node_modules/npm-registry-client/lib/request.js index 1925dd25f..d26be15dd 100644 --- a/node_modules/npm-registry-client/lib/request.js +++ b/node_modules/npm-registry-client/lib/request.js @@ -8,8 +8,9 @@ var url = require("url") , request = require("request") , retry = require("retry") , crypto = require("crypto") - , pkg = require("../package.json") +var pkg = require("../package.json") + , toNerfDart = require("./util/nerf-dart.js") // npm: means // 1. https @@ -65,10 +66,9 @@ function regRequest (method, uri, options, cb_) { , adduserNew = /^\/?-\/user\/org\.couchdb\.user:([^\/]+)/ , nu = where.match(adduserNew) , uc = where.match(adduserChange) - , alwaysAuth = this.conf.get('always-auth') + , alwaysAuth = this.conf.get("always-auth") , isDel = method === "DELETE" , isWrite = what || isDel - , authRequired = (authThis || alwaysAuth || isWrite) && !nu || uc || isDel // resolve to a full url on the registry if (!where.match(/^https?:\/\//)) { @@ -94,32 +94,39 @@ function regRequest (method, uri, options, cb_) { this.log.verbose("request", "where is", where) var remote = url.parse(where) - , auth = this.conf.get('_auth') - - if (authRequired && !auth) { - var un = this.conf.get('username') - var pw = this.conf.get('_password') + if ((authThis || alwaysAuth || isWrite) && !nu || uc || isDel) { + // 1. see if there's multi-registry auth in there + var auth = this.conf.get(toNerfDart(where) + ":_auth") + + // 2. check for (deprecated) generic auth + if (!auth) auth = this.conf.get("_auth") + + // 3. check to see if npmconf has unbundled the credentials + if (!auth) { + var un = this.conf.get("username") + var pw = this.conf.get("_password") + + if (!(un && pw)) { + return cb(new Error( + "This request requires auth credentials. Run `npm login` and repeat the request." + )) + } - if (!(un && pw)) { - return cb(new Error( - "This request requires auth credentials. Run `npm login` and repeat the request." - )) + auth = new Buffer(un + ":" + pw).toString("base64") } - auth = new Buffer(un + ':' + pw).toString('base64') - } - - if (auth && authRequired) { - remote.auth = new Buffer(auth, "base64").toString("utf8") + if (auth) { + remote.auth = new Buffer(auth, "base64").toString("utf8") + } } // Tuned to spread 3 attempts over about a minute. // See formula at <https://github.com/tim-kos/node-retry>. var operation = retry.operation({ - retries: this.conf.get('fetch-retries') || 2, - factor: this.conf.get('fetch-retry-factor'), - minTimeout: this.conf.get('fetch-retry-mintimeout') || 10000, - maxTimeout: this.conf.get('fetch-retry-maxtimeout') || 60000 + retries: this.conf.get("fetch-retries") || 2, + factor: this.conf.get("fetch-retry-factor"), + minTimeout: this.conf.get("fetch-retry-mintimeout") || 10000, + maxTimeout: this.conf.get("fetch-retry-maxtimeout") || 60000 }) var self = this @@ -130,7 +137,7 @@ function regRequest (method, uri, options, cb_) { , function (er, parsed, raw, response) { if (!er || (er.message && er.message.match(/^SSL Error/))) { if (er) - er.code = 'ESSL' + er.code = "ESSL" return cb(er, parsed, raw, response) } @@ -142,7 +149,7 @@ function regRequest (method, uri, options, cb_) { var statusRetry = !statusCode || timeout || serverError if (er && statusRetry && operation.retry(er)) { self.log.info("retry", "will retry, error on last attempt: " + er) - return + return undefined } if (response) this.log.verbose("headers", response.headers) @@ -159,15 +166,15 @@ function makeRequest (method, remote, where, what, etag, nofollow, cb_) { cb_.apply(null, arguments) } - var strict = this.conf.get('strict-ssl') + var strict = this.conf.get("strict-ssl") if (strict === undefined) strict = true var opts = { url: remote , method: method , encoding: null // tell request let body be Buffer instance - , ca: this.conf.get('ca') - , localAddress: this.conf.get('local-address') - , cert: this.conf.get('cert') - , key: this.conf.get('key') + , ca: this.conf.get("ca") + , localAddress: this.conf.get("local-address") + , cert: this.conf.get("cert") + , key: this.conf.get("key") , strictSSL: strict } , headers = opts.headers = {} if (etag) { @@ -175,7 +182,7 @@ function makeRequest (method, remote, where, what, etag, nofollow, cb_) { headers[method === "GET" ? "if-none-match" : "if-match"] = etag } - headers['npm-session'] = this.sessionToken + headers["npm-session"] = this.sessionToken headers.version = this.version || pkg.version if (this.refer) { @@ -183,12 +190,12 @@ function makeRequest (method, remote, where, what, etag, nofollow, cb_) { } headers.accept = "application/json" - headers['accept-encoding'] = 'gzip' + headers["accept-encoding"] = "gzip" - headers["user-agent"] = this.conf.get('user-agent') || - 'node/' + process.version + headers["user-agent"] = this.conf.get("user-agent") || + "node/" + process.version - var tokenKey = toKey(url.format(remote)) + var tokenKey = toNerfDart(url.format(remote)) + ":_authToken" this.log.silly("tokenKey", tokenKey) var authToken = this.conf.get(tokenKey) if (authToken) { @@ -197,11 +204,11 @@ function makeRequest (method, remote, where, what, etag, nofollow, cb_) { headers.authorization = "Bearer " + authToken } - var p = this.conf.get('proxy') - var sp = this.conf.get('https-proxy') || p + var p = this.conf.get("proxy") + var sp = this.conf.get("https-proxy") || p opts.proxy = remote.protocol === "https:" ? sp : p - // figure out wth 'what' is + // figure out wth "what" is if (what) { if (Buffer.isBuffer(what) || typeof what === "string") { opts.body = what @@ -245,7 +252,7 @@ function decodeResponseBody(cb) { response.socket.destroy() } - if (response.headers['content-encoding'] !== 'gzip') return cb(er, response, data) + if (response.headers["content-encoding"] !== "gzip") return cb(er, response, data) zlib.gunzip(data, function (er, buf) { if (er) return cb(er, response, data) @@ -262,7 +269,7 @@ function requestDone (method, where, cb) { var urlObj = url.parse(where) if (urlObj.auth) - urlObj.auth = '***' + urlObj.auth = "***" this.log.http(response.statusCode, url.format(urlObj)) var parsed @@ -303,7 +310,7 @@ function requestDone (method, where, cb) { if (!w.match(/^-/) && parsed.error === "not_found") { w = w.split("/") name = w[w.indexOf("_rewrite") + 1] - er = new Error("404 Not Found: "+name) + er = new Error("404 Not Found: " + name) er.code = "E404" er.pkgid = name } else { @@ -322,12 +329,3 @@ function requestDone (method, where, cb) { return cb(er, parsed, data, response) }.bind(this) } - -function toKey(uri) { - var parsed = url.parse(uri) - parsed.pathname = "/" - delete parsed.protocol - delete parsed.auth - - return url.format(parsed) + ":_authToken" -} diff --git a/node_modules/npm-registry-client/lib/util/nerf-dart.js b/node_modules/npm-registry-client/lib/util/nerf-dart.js new file mode 100644 index 000000000..3b26a56c6 --- /dev/null +++ b/node_modules/npm-registry-client/lib/util/nerf-dart.js @@ -0,0 +1,21 @@ +var url = require("url") + +module.exports = toNerfDart + +/** + * Maps a URL to an identifier. + * + * Name courtesy schiffertronix media LLC, a New Jersey corporation + * + * @param {String} uri The URL to be nerfed. + * + * @returns {String} A nerfed URL. + */ +function toNerfDart(uri) { + var parsed = url.parse(uri) + parsed.pathname = "/" + delete parsed.protocol + delete parsed.auth + + return url.format(parsed) +} diff --git a/node_modules/npm-registry-client/node_modules/normalize-package-data/lib/fixer.js b/node_modules/npm-registry-client/node_modules/normalize-package-data/lib/fixer.js index 82c1348be..72836002f 100644 --- a/node_modules/npm-registry-client/node_modules/normalize-package-data/lib/fixer.js +++ b/node_modules/npm-registry-client/node_modules/normalize-package-data/lib/fixer.js @@ -290,24 +290,25 @@ var fixer = module.exports = { } } -function ensureValidName (name, strict) { - function scoped(spec) { - if (spec.charAt(0) !== '@') return false +function isValidScopedPackageName(spec) { + if (spec.charAt(0) !== '@') return false - var rest = spec.slice(1).split('/') - if (rest.length !== 2) return false + var rest = spec.slice(1).split('/') + if (rest.length !== 2) return false - return rest[0] === encodeURIComponent(rest[0]) && - rest[1] === encodeURIComponent(rest[1]) - } + return rest[0] && rest[1] && + rest[0] === encodeURIComponent(rest[0]) && + rest[1] === encodeURIComponent(rest[1]) +} - function scopedOrEncoded(spec) { - return !scoped(spec) && - (spec.match(/[\/@\s\+%:]/) || spec !== encodeURIComponent(spec)) - } +function isCorrectlyEncodedName(spec) { + return !spec.match(/[\/@\s\+%:]/) && + spec === encodeURIComponent(spec) +} +function ensureValidName (name, strict) { if (name.charAt(0) === "." || - scopedOrEncoded(name) || + !(isValidScopedPackageName(name) || isCorrectlyEncodedName(name)) || (strict && name !== name.toLowerCase()) || name.toLowerCase() === "node_modules" || name.toLowerCase() === "favicon.ico") { diff --git a/node_modules/npm-registry-client/node_modules/normalize-package-data/package.json b/node_modules/npm-registry-client/node_modules/normalize-package-data/package.json index 3c1737d50..18fdd92ad 100644 --- a/node_modules/npm-registry-client/node_modules/normalize-package-data/package.json +++ b/node_modules/npm-registry-client/node_modules/normalize-package-data/package.json @@ -45,7 +45,7 @@ }, "homepage": "https://github.com/meryn/normalize-package-data", "_id": "normalize-package-data@0.3.0", - "_shasum": "d763a0bdb2bc4f4cf9d355aab9991bd7585e0c57", - "_resolved": "git://github.com/npm/normalize-package-data#15869dc14c1ac8e3b202586f62f755c69443e403", + "_shasum": "61130418af14cee0f569f5a5970a3f3960c5b36d", + "_resolved": "git://github.com/npm/normalize-package-data#84bae1f6f8061b664c05c5f06abae316f3cc0b53", "_from": "normalize-package-data@git://github.com/npm/normalize-package-data#othiym23/scoped" } diff --git a/node_modules/npm-registry-client/node_modules/normalize-package-data/test/scoped.js b/node_modules/npm-registry-client/node_modules/normalize-package-data/test/scoped.js index 0f17e9f5b..31bbf4f7f 100644 --- a/node_modules/npm-registry-client/node_modules/normalize-package-data/test/scoped.js +++ b/node_modules/npm-registry-client/node_modules/normalize-package-data/test/scoped.js @@ -12,8 +12,7 @@ test("a simple scoped module has a valid name", function (t) { test("'org@package' is not a valid name", function (t) { t.throws(function () { - var data = {name : "org@package"} - fixNameField(data, false) + fixNameField({name : "org@package"}, false) }, "blows up as expected") t.end() @@ -21,8 +20,7 @@ test("'org@package' is not a valid name", function (t) { test("'org=package' is not a valid name", function (t) { t.throws(function () { - var data = {name : "org=package"} - fixNameField(data, false) + fixNameField({name : "org=package"}, false) }, "blows up as expected") t.end() @@ -30,8 +28,23 @@ test("'org=package' is not a valid name", function (t) { test("'@org=sub/package' is not a valid name", function (t) { t.throws(function () { - var data = {name : "@org=sub/package"} - fixNameField(data, false) + fixNameField({name : "@org=sub/package"}, false) + }, "blows up as expected") + + t.end() +}) + +test("'@org/' is not a valid name", function (t) { + t.throws(function () { + fixNameField({name : "@org/"}, false) + }, "blows up as expected") + + t.end() +}) + +test("'@/package' is not a valid name", function (t) { + t.throws(function () { + fixNameField({name : "@/package"}, false) }, "blows up as expected") t.end() diff --git a/node_modules/npm-registry-client/package.json b/node_modules/npm-registry-client/package.json index 87b635560..2ac5ea15c 100644 --- a/node_modules/npm-registry-client/package.json +++ b/node_modules/npm-registry-client/package.json @@ -41,7 +41,7 @@ }, "homepage": "https://github.com/isaacs/npm-registry-client", "_id": "npm-registry-client@2.0.2", - "_shasum": "d69124ffd5c82173dfa5cb092132799def53056c", - "_resolved": "git://github.com/npm/npm-registry-client#a5ee4ea90bb066466837cc42ed59fb3d5101c4ed", + "_shasum": "13578a17a2876db802542dff7e0b2950efcc23e3", + "_resolved": "git://github.com/npm/npm-registry-client#74a250ce75853a173f094e7cbae2570453f17b3c", "_from": "git://github.com/npm/npm-registry-client#othiym23/multi-registry" } diff --git a/node_modules/npm-registry-client/test/lib/common.js b/node_modules/npm-registry-client/test/lib/common.js index f9048c094..8d369a418 100644 --- a/node_modules/npm-registry-client/test/lib/common.js +++ b/node_modules/npm-registry-client/test/lib/common.js @@ -1,16 +1,20 @@ var resolve = require("path").resolve -var server = require('./server.js') -var RC = require('../../') +var server = require("./server.js") +var RC = require("../../") + +var REGISTRY = "http://localhost:" + server.port module.exports = { + port : server.port, + registry : REGISTRY, freshClient : function freshClient(config) { config = config || {} - config.cache = resolve(__dirname, '../fixtures/cache') - config.registry = 'http://localhost:' + server.port + config.cache = resolve(__dirname, "../fixtures/cache") + config.registry = REGISTRY var client = new RC(config) server.log = client.log - client.log.level = 'silent' + client.log.level = "silent" return client } diff --git a/node_modules/npm-registry-client/test/publish-scoped-auth-token.js b/node_modules/npm-registry-client/test/publish-scoped-auth-token.js new file mode 100644 index 000000000..8adec406b --- /dev/null +++ b/node_modules/npm-registry-client/test/publish-scoped-auth-token.js @@ -0,0 +1,60 @@ +var tap = require("tap") +var crypto = require("crypto") +var fs = require("fs") + +var toNerfDart = require("../lib/util/nerf-dart.js") +var server = require("./lib/server.js") +var common = require("./lib/common.js") + +var configuration = {"always-auth" : true} + +var authKey = toNerfDart(common.registry) + ":_auth" +configuration[authKey] = new Buffer("username:password").toString("base64") + +var emailKey = toNerfDart(common.registry) + ":email" +configuration[emailKey] = "ogd@aoaioxxysz.net" + +var tokenKey = toNerfDart(common.registry) + ":_authToken" +configuration[tokenKey] = "of-glad-tidings" + +var client = common.freshClient(configuration) + +tap.test("publish", function (t) { + // not really a tarball, but doesn't matter + var tarball = require.resolve("../package.json") + var pd = fs.readFileSync(tarball, "base64") + var pkg = require("../package.json") + pkg.name = "@npm/npm-registry-client" + + server.expect("/@npm%2fnpm-registry-client", function (req, res) { + t.equal(req.method, "PUT") + t.equal(req.headers.authorization, "Bearer of-glad-tidings") + + var b = "" + req.setEncoding("utf8") + req.on("data", function (d) { + b += d + }) + + req.on("end", function () { + var o = JSON.parse(b) + t.equal(o._id, "@npm/npm-registry-client") + t.equal(o["dist-tags"].latest, pkg.version) + t.has(o.versions[pkg.version], pkg) + t.same(o.maintainers, [ { name: "username", email: "ogd@aoaioxxysz.net" } ]) + t.same(o.maintainers, o.versions[pkg.version].maintainers) + var att = o._attachments[ pkg.name + "-" + pkg.version + ".tgz" ] + t.same(att.data, pd) + var hash = crypto.createHash("sha1").update(pd, "base64").digest("hex") + t.equal(o.versions[pkg.version].dist.shasum, hash) + res.statusCode = 201 + res.json({created:true}) + }) + }) + + client.publish(common.registry, pkg, tarball, function (er, data) { + if (er) throw er + t.deepEqual(data, { created: true }) + t.end() + }) +}) diff --git a/node_modules/npm-registry-client/test/publish-scoped.js b/node_modules/npm-registry-client/test/publish-scoped.js index 9b83341dd..e71d68d49 100644 --- a/node_modules/npm-registry-client/test/publish-scoped.js +++ b/node_modules/npm-registry-client/test/publish-scoped.js @@ -2,20 +2,32 @@ var tap = require("tap") var crypto = require("crypto") var fs = require("fs") +var toNerfDart = require("../lib/util/nerf-dart.js") var server = require("./lib/server.js") var common = require("./lib/common.js") -var client = common.freshClient({ - username: "username", - password: "password", - email: "i@izs.me", - _auth: new Buffer("username:password").toString("base64"), - "always-auth": true -}) +var configuration = {"always-auth" : true} + +var authKey = toNerfDart(common.registry) + ":_auth" +var _auth = new Buffer("username:password").toString("base64") +configuration[authKey] = _auth + +var emailKey = toNerfDart(common.registry) + ":email" +configuration[emailKey] = "ogd@aoaioxxysz.net" + +var client = common.freshClient(configuration) tap.test("publish", function (t) { + // not really a tarball, but doesn't matter + var tarball = require.resolve("../package.json") + var pd = fs.readFileSync(tarball, "base64") + var pkg = require("../package.json") + pkg.name = "@npm/npm-registry-client" + server.expect("/@npm%2fnpm-registry-client", function (req, res) { t.equal(req.method, "PUT") + t.equal(req.headers.authorization, "Basic " + _auth) + var b = "" req.setEncoding("utf8") req.on("data", function (d) { @@ -27,7 +39,7 @@ tap.test("publish", function (t) { t.equal(o._id, "@npm/npm-registry-client") t.equal(o["dist-tags"].latest, pkg.version) t.has(o.versions[pkg.version], pkg) - t.same(o.maintainers, [ { name: "username", email: "i@izs.me" } ]) + t.same(o.maintainers, [ { name: "username", email: "ogd@aoaioxxysz.net" } ]) t.same(o.maintainers, o.versions[pkg.version].maintainers) var att = o._attachments[ pkg.name + "-" + pkg.version + ".tgz" ] t.same(att.data, pd) @@ -38,12 +50,7 @@ tap.test("publish", function (t) { }) }) - // not really a tarball, but doesn't matter - var tarball = require.resolve("../package.json") - var pd = fs.readFileSync(tarball, "base64") - var pkg = require("../package.json") - pkg.name = '@npm/npm-registry-client' - client.publish("http://localhost:1337/", pkg, tarball, function (er, data) { + client.publish(common.registry, pkg, tarball, function (er, data) { if (er) throw er t.deepEqual(data, { created: true }) t.end() |