Skip to content
This repository has been archived by the owner on Nov 16, 2019. It is now read-only.

Commit

Permalink
Add support for old-style _auth to default registry
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jul 15, 2014
1 parent a94b6eb commit ed42b85
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 71 deletions.
19 changes: 19 additions & 0 deletions lib/get-credentials-by-uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = getCredentialsByURI
function getCredentialsByURI (uri) {
assert(uri && typeof uri === "string", "registry URL is required")
var nerfed = toNerfDart(uri)
var defnerf = toNerfDart(this.get("registry"))

var c = {scope : nerfed}

Expand All @@ -16,16 +17,34 @@ function getCredentialsByURI (uri) {
return c
}

// Handle the old-style _auth=<base64> style for the default
// registry, if set.
var authDef = this.get("_auth")
var userDef = this.get("username")
var passDef = this.get("_password")
if (authDef && !(userDef && passDef)) {
authDef = new Buffer(authDef, "base64").toString()
authDef = authDef.split(":")
userDef = authDef.shift()
passDef = authDef.join(":")
}

if (this.get(nerfed + ":_password")) {
c.password = new Buffer(this.get(nerfed + ":_password"), "base64").toString("utf8")
} else if (nerfed === defnerf && passDef) {
c.password = passDef
}

if (this.get(nerfed + ":username")) {
c.username = this.get(nerfed + ":username")
} else if (nerfed === defnerf && userDef) {
c.username = userDef
}

if (this.get(nerfed + ":email")) {
c.email = this.get(nerfed + ":email")
} else if (this.get("email")) {
c.email = this.get("email")
}

if (c.username && c.password) {
Expand Down
24 changes: 24 additions & 0 deletions test/00-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@ var userconfigSrc = path.resolve(__dirname, 'fixtures', 'userconfig')
exports.userconfig = userconfigSrc + '-with-gc'
exports.globalconfig = path.resolve(__dirname, 'fixtures', 'globalconfig')
exports.builtin = path.resolve(__dirname, 'fixtures', 'builtin')
exports.ucData =
{ globalconfig: exports.globalconfig,
email: 'i@izs.me',
'env-thing': 'asdf',
'init.author.name': 'Isaac Z. Schlueter',
'init.author.email': 'i@izs.me',
'init.author.url': 'http://blog.izs.me/',
'init.version': '1.2.3',
'proprietary-attribs': false,
'npm:publishtest': true,
'_npmjs.org:couch': 'https://admin:password@localhost:5984/registry',
'npm-www:nocache': '1',
nodedir: '/Users/isaacs/dev/js/node-v0.8',
'sign-git-tag': true,
message: 'v%s',
'strict-ssl': false,
'tmp': process.env.HOME + '/.tmp',
_auth: 'dXNlcm5hbWU6cGFzc3dvcmQ=',
_token:
{ AuthSession: 'yabba-dabba-doodle',
version: '1',
expires: '1345001053415',
path: '/',
httponly: true } }

// set the userconfig in the env
// unset anything else that npm might be trying to foist on us
Expand Down
25 changes: 1 addition & 24 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,7 @@ var path = require('path')

var projectData = {}

var ucData =
{ globalconfig: common.globalconfig,
email: 'i@izs.me',
'env-thing': 'asdf',
'init.author.name': 'Isaac Z. Schlueter',
'init.author.email': 'i@izs.me',
'init.author.url': 'http://blog.izs.me/',
'init.version': '1.2.3',
'proprietary-attribs': false,
'npm:publishtest': true,
'_npmjs.org:couch': 'https://admin:password@localhost:5984/registry',
'npm-www:nocache': '1',
nodedir: '/Users/isaacs/dev/js/node-v0.8',
'sign-git-tag': true,
message: 'v%s',
'strict-ssl': false,
'tmp': process.env.HOME + '/.tmp',
_token:
{ AuthSession: 'yabba-dabba-doodle',
version: '1',
expires: '1345001053415',
path: '/',
httponly: true } }

var ucData = common.ucData
var envData = common.envData
var envDataFix = common.envDataFix

Expand Down
24 changes: 1 addition & 23 deletions test/builtin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,7 @@ var npmconf = require('../npmconf.js')
var common = require('./00-setup.js')
var path = require('path')

var ucData =
{ globalconfig: common.globalconfig,
email: 'i@izs.me',
'env-thing': 'asdf',
'init.author.name': 'Isaac Z. Schlueter',
'init.author.email': 'i@izs.me',
'init.author.url': 'http://blog.izs.me/',
'init.version': '1.2.3',
'proprietary-attribs': false,
'npm:publishtest': true,
'_npmjs.org:couch': 'https://admin:password@localhost:5984/registry',
'npm-www:nocache': '1',
nodedir: '/Users/isaacs/dev/js/node-v0.8',
'sign-git-tag': true,
message: 'v%s',
'strict-ssl': false,
'tmp': process.env.HOME + '/.tmp',
_token:
{ AuthSession: 'yabba-dabba-doodle',
version: '1',
expires: '1345001053415',
path: '/',
httponly: true } }
var ucData = common.ucData

var envData = common.envData
var envDataFix = common.envDataFix
Expand Down
15 changes: 15 additions & 0 deletions test/credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,18 @@ test("set with old-style credentials", function (t) {
t.end()
})
})

test("get old-style credentials for default registry", function (t) {
npmconf.load(common.builtin, function (er, conf) {
var actual = conf.getCredentialsByURI(conf.get("registry"))
var expected = {
scope: '//registry.npmjs.org/',
password: 'password',
username: 'username',
email: 'i@izs.me',
auth: 'dXNlcm5hbWU6cGFzc3dvcmQ='
}
t.same(actual, expected)
t.end()
})
})
1 change: 1 addition & 0 deletions test/fixtures/userconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sign-git-tag = true
message = v%s
strict-ssl = false
tmp = ~/.tmp
_auth = dXNlcm5hbWU6cGFzc3dvcmQ=

[_token]
AuthSession = yabba-dabba-doodle
Expand Down
25 changes: 1 addition & 24 deletions test/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,7 @@ var projectRc = path.resolve(fix, '.npmrc')

var projectData = { just: 'testing' }

var ucData =
{ globalconfig: common.globalconfig,
email: 'i@izs.me',
'env-thing': 'asdf',
'init.author.name': 'Isaac Z. Schlueter',
'init.author.email': 'i@izs.me',
'init.author.url': 'http://blog.izs.me/',
'init.version': '1.2.3',
'proprietary-attribs': false,
'npm:publishtest': true,
'_npmjs.org:couch': 'https://admin:password@localhost:5984/registry',
'npm-www:nocache': '1',
nodedir: '/Users/isaacs/dev/js/node-v0.8',
'sign-git-tag': true,
message: 'v%s',
'strict-ssl': false,
'tmp': process.env.HOME + '/.tmp',
_token:
{ AuthSession: 'yabba-dabba-doodle',
version: '1',
expires: '1345001053415',
path: '/',
httponly: true } }

var ucData = common.ucData
var envData = common.envData
var envDataFix = common.envDataFix

Expand Down
2 changes: 2 additions & 0 deletions test/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var expectConf =
'sign-git-tag = false',
'message = v%s',
'strict-ssl = false',
'_auth = dXNlcm5hbWU6cGFzc3dvcmQ=',
'',
'[_token]',
'AuthSession = yabba-dabba-doodle',
Expand All @@ -41,6 +42,7 @@ var expectFile =
'sign-git-tag = false',
'message = v%s',
'strict-ssl = false',
'_auth = dXNlcm5hbWU6cGFzc3dvcmQ=',
'',
'[_token]',
'AuthSession = yabba-dabba-doodle',
Expand Down

0 comments on commit ed42b85

Please sign in to comment.