diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2014-06-21 06:34:37 +0400 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2014-07-02 05:43:16 +0400 |
commit | cfcbf34fe4819818c3de75a9e7d77ff794d31cf9 (patch) | |
tree | b6c2566fbff6d20a957a4cd48848cabd3a2e74ca /test | |
parent | 0689ba249b92b4c6279a26804c96af6f92b3a501 (diff) |
chasing down errant uses of old auth, part 1
Diffstat (limited to 'test')
-rw-r--r-- | test/tap/publish-config.js | 17 | ||||
-rw-r--r-- | test/tap/publish-scoped.js | 4 | ||||
-rw-r--r-- | test/tap/whoami.js | 77 |
3 files changed, 92 insertions, 6 deletions
diff --git a/test/tap/publish-config.js b/test/tap/publish-config.js index 3c4624eea..39d6e8311 100644 --- a/test/tap/publish-config.js +++ b/test/tap/publish-config.js @@ -7,11 +7,17 @@ pkg += '/npm-test-publish-config' require('mkdirp').sync(pkg) -fs.writeFileSync(pkg + '/package.json', JSON.stringify({ - name: 'npm-test-publish-config', - version: '1.2.3', +fs.writeFileSync(pkg + "/package.json", JSON.stringify({ + name: "npm-test-publish-config", + version: "1.2.3", publishConfig: { registry: common.registry } -}), 'utf8') +}), "utf8") + +fs.writeFileSync(pkg + "/fixture_npmrc", + "//localhost:1337/:email = fancy@feast.net\n" + + "//localhost:1337/:username = fancy\n" + + "//localhost:1337/:_password = " + new Buffer("feast").toString("base64") + "\n" + + "registry = http://localhost:1337/") var spawn = require('child_process').spawn var npm = require.resolve('../../bin/npm-cli.js') @@ -36,8 +42,9 @@ test(function (t) { // itself functions normally. // // Make sure that we don't sit around waiting for lock files - child = spawn(node, [npm, 'publish', '--email=fancy', '--_auth=feast'], { + child = spawn(node, [npm, "publish", "--userconfig=" + pkg + "/fixture_npmrc"], { cwd: pkg, + stdio: "inherit", env: { npm_config_cache_lock_stale: 1000, npm_config_cache_lock_wait: 1000, diff --git a/test/tap/publish-scoped.js b/test/tap/publish-scoped.js index 4e7d557ff..7547c91f1 100644 --- a/test/tap/publish-scoped.js +++ b/test/tap/publish-scoped.js @@ -40,7 +40,9 @@ test("npm publish should honor scoping", function (t) { cache : path.join(pkg, "cache"), loglevel : "silent", registry : "http://nonexistent.lvh.me", - "//localhost:1337/:_auth" : new Buffer("testuser:password", "utf8").toString("base64") + "//localhost:1337/:username" : "username", + "//localhost:1337/:_password" : new Buffer("password").toString("base64"), + "//localhost:1337/:email" : "ogd@aoaioxxysz.net" } npm.load(configuration, onload) diff --git a/test/tap/whoami.js b/test/tap/whoami.js new file mode 100644 index 000000000..e4ed30df7 --- /dev/null +++ b/test/tap/whoami.js @@ -0,0 +1,77 @@ +var common = require("../common-tap.js") + +var fs = require("fs") +var path = require("path") +var createServer = require("http").createServer + +var test = require("tap").test +var rimraf = require("rimraf") + +var opts = { cwd: __dirname } + +var FIXTURE_PATH = path.resolve(__dirname, "fixture_npmrc") + +test("npm whoami with basic auth", function (t) { + var s = "//registry.lvh.me/:username = wombat\n" + + "//registry.lvh.me/:_password = YmFkIHBhc3N3b3Jk\n" + + "//registry.lvh.me/:email = lindsay@wdu.org.au\n" + fs.writeFileSync(FIXTURE_PATH, s, "ascii") + fs.chmodSync(FIXTURE_PATH, "0444") + + common.npm( + [ + "whoami", + "--userconfig=" + FIXTURE_PATH, + "--registry=http://registry.lvh.me/" + ], + opts, + function (err, code, stdout, stderr) { + t.ifError(err) + + t.equal(stderr, "", "got nothing on stderr") + t.equal(code, 0, "exit ok") + t.equal(stdout, "wombat\n", "got username") + rimraf.sync(FIXTURE_PATH) + t.end() + } + ) +}) + +test("npm whoami with bearer auth", {timeout : 2 * 1000}, function (t) { + var s = "//localhost:" + common.port + + "/:_authToken = wombat-developers-union\n" + fs.writeFileSync(FIXTURE_PATH, s, "ascii") + fs.chmodSync(FIXTURE_PATH, "0444") + + function verify(req, res) { + t.equal(req.method, "GET") + t.equal(req.url, "/whoami") + + res.setHeader("content-type", "application/json") + res.writeHeader(200) + res.end(JSON.stringify({username : "wombat"}), "utf8") + } + + var server = createServer(verify) + + server.listen(common.port, function () { + common.npm( + [ + "whoami", + "--userconfig=" + FIXTURE_PATH, + "--registry=http://localhost:" + common.port + "/" + ], + opts, + function (err, code, stdout, stderr) { + t.ifError(err) + + t.equal(stderr, "", "got nothing on stderr") + t.equal(code, 0, "exit ok") + t.equal(stdout, "wombat\n", "got username") + rimraf.sync(FIXTURE_PATH) + server.close() + t.end() + } + ) + }) +}) |