Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorForrest L Norvell <forrest@npmjs.com>2015-02-13 14:49:48 +0300
committerForrest L Norvell <forrest@npmjs.com>2015-02-13 14:49:48 +0300
commitd0790dcf87ade85316aaac1700a7e9877c5c7127 (patch)
treee060e315e95ca6306e47d04355b2798421889254
parent4bf0f5d56c33649124b486e016ba4a620c105c1c (diff)
config: clear credentials by nerf dart
-rw-r--r--lib/config/clear-credentials-by-uri.js16
-rw-r--r--lib/config/core.js1
-rw-r--r--test/tap/config-credentials.js55
3 files changed, 72 insertions, 0 deletions
diff --git a/lib/config/clear-credentials-by-uri.js b/lib/config/clear-credentials-by-uri.js
new file mode 100644
index 000000000..88131f7ad
--- /dev/null
+++ b/lib/config/clear-credentials-by-uri.js
@@ -0,0 +1,16 @@
+var assert = require("assert")
+
+var toNerfDart = require("./nerf-dart.js")
+
+module.exports = clearCredentialsByURI
+
+function clearCredentialsByURI (uri) {
+ assert(uri && typeof uri === "string", "registry URL is required")
+
+ var nerfed = toNerfDart(uri)
+
+ this.del(nerfed + ":_authToken", "user")
+ this.del(nerfed + ":_password", "user")
+ this.del(nerfed + ":username", "user")
+ this.del(nerfed + ":email", "user")
+}
diff --git a/lib/config/core.js b/lib/config/core.js
index ddd851cf7..97c17919d 100644
--- a/lib/config/core.js
+++ b/lib/config/core.js
@@ -227,6 +227,7 @@ Conf.prototype.setUser = require("./set-user.js")
Conf.prototype.findPrefix = require("./find-prefix.js")
Conf.prototype.getCredentialsByURI = require("./get-credentials-by-uri.js")
Conf.prototype.setCredentialsByURI = require("./set-credentials-by-uri.js")
+Conf.prototype.clearCredentialsByURI = require("./clear-credentials-by-uri.js")
Conf.prototype.loadExtras = function(cb) {
this.setUser(function(er) {
diff --git a/test/tap/config-credentials.js b/test/tap/config-credentials.js
index c24bb7e1b..1cb2a7eb4 100644
--- a/test/tap/config-credentials.js
+++ b/test/tap/config-credentials.js
@@ -28,6 +28,18 @@ test("trying to set credentials with no URI", function (t) {
})
})
+test("trying to clear credentials with no URI", function (t) {
+ npmconf.load(common.builtin, function (er, conf) {
+ t.ifError(er, "configuration loaded")
+
+ t.throws(function () {
+ conf.clearCredentialsByURI()
+ }, "enforced missing URI")
+
+ t.end()
+ })
+})
+
test("set with missing credentials object", function (t) {
npmconf.load(common.builtin, function (er, conf) {
t.ifError(er, "configuration loaded")
@@ -76,6 +88,24 @@ test("set with token", function (t) {
})
})
+test("clear with token", function (t) {
+ npmconf.load(common.builtin, function (er, conf) {
+ t.ifError(er, "configuration loaded")
+
+ t.doesNotThrow(function () {
+ conf.setCredentialsByURI(URI, {token : "simple-token"})
+ }, "needs only token")
+
+ t.doesNotThrow(function () {
+ conf.clearCredentialsByURI(URI)
+ }, "needs only URI")
+
+ t.notOk(conf.getCredentialsByURI(URI).token, "token all gone")
+
+ t.end()
+ })
+})
+
test("set with missing username", function (t) {
npmconf.load(common.builtin, function (er, conf) {
t.ifError(er, "configuration loaded")
@@ -157,6 +187,31 @@ test("set with old-style credentials", function (t) {
})
})
+test("clear with old-style credentials", function (t) {
+ npmconf.load(common.builtin, function (er, conf) {
+ t.ifError(er, "configuration loaded")
+
+ var credentials = {
+ username : "username",
+ password : "password",
+ email : "ogd@aoaioxxysz.net"
+ }
+
+ t.doesNotThrow(function () {
+ conf.setCredentialsByURI(URI, credentials)
+ }, "requires all of username, password, and email")
+
+ t.doesNotThrow(function () {
+ conf.clearCredentialsByURI(URI)
+ }, "clearing only required URI")
+
+ t.notOk(conf.getCredentialsByURI(URI).username, "username cleared")
+ t.notOk(conf.getCredentialsByURI(URI).password, "password cleared")
+
+ 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"))