1 var test = require("tap").test
3 var npmconf = require("../../lib/config/core.js")
4 var common = require("./00-config-setup.js")
6 var URI = "https://registry.lvh.me:8661/"
8 test("getting scope with no credentials set", function (t) {
9 npmconf.load({}, function (er, conf) {
10 t.ifError(er, "configuration loaded")
12 var basic = conf.getCredentialsByURI(URI)
13 t.equal(basic.scope, "//registry.lvh.me:8661/", "nerfed URL extracted")
19 test("trying to set credentials with no URI", function (t) {
20 npmconf.load(common.builtin, function (er, conf) {
21 t.ifError(er, "configuration loaded")
23 t.throws(function () {
24 conf.setCredentialsByURI()
25 }, "enforced missing URI")
31 test("trying to clear credentials with no URI", function (t) {
32 npmconf.load(common.builtin, function (er, conf) {
33 t.ifError(er, "configuration loaded")
35 t.throws(function () {
36 conf.clearCredentialsByURI()
37 }, "enforced missing URI")
43 test("set with missing credentials object", function (t) {
44 npmconf.load(common.builtin, function (er, conf) {
45 t.ifError(er, "configuration loaded")
47 t.throws(function () {
48 conf.setCredentialsByURI(URI)
49 }, "enforced missing credentials")
55 test("set with empty credentials object", function (t) {
56 npmconf.load(common.builtin, function (er, conf) {
57 t.ifError(er, "configuration loaded")
59 t.throws(function () {
60 conf.setCredentialsByURI(URI, {})
61 }, "enforced missing credentials")
67 test("set with token", function (t) {
68 npmconf.load(common.builtin, function (er, conf) {
69 t.ifError(er, "configuration loaded")
71 t.doesNotThrow(function () {
72 conf.setCredentialsByURI(URI, {token : "simple-token"})
73 }, "needs only token")
76 scope: '//registry.lvh.me:8661/',
77 token: 'simple-token',
85 t.same(conf.getCredentialsByURI(URI), expected, "got bearer token and scope")
91 test("clear with token", function (t) {
92 npmconf.load(common.builtin, function (er, conf) {
93 t.ifError(er, "configuration loaded")
95 t.doesNotThrow(function () {
96 conf.setCredentialsByURI(URI, {token : "simple-token"})
97 }, "needs only token")
99 t.doesNotThrow(function () {
100 conf.clearCredentialsByURI(URI)
103 t.notOk(conf.getCredentialsByURI(URI).token, "token all gone")
109 test("set with missing username", function (t) {
110 npmconf.load(common.builtin, function (er, conf) {
111 t.ifError(er, "configuration loaded")
114 password : "password",
115 email : "ogd@aoaioxxysz.net"
118 t.throws(function () {
119 conf.setCredentialsByURI(URI, credentials)
120 }, "enforced missing email")
126 test("set with missing password", function (t) {
127 npmconf.load(common.builtin, function (er, conf) {
128 t.ifError(er, "configuration loaded")
131 username : "username",
132 email : "ogd@aoaioxxysz.net"
135 t.throws(function () {
136 conf.setCredentialsByURI(URI, credentials)
137 }, "enforced missing email")
143 test("set with missing email", function (t) {
144 npmconf.load(common.builtin, function (er, conf) {
145 t.ifError(er, "configuration loaded")
148 username : "username",
149 password : "password"
152 t.throws(function () {
153 conf.setCredentialsByURI(URI, credentials)
154 }, "enforced missing email")
160 test("set with old-style credentials", function (t) {
161 npmconf.load(common.builtin, function (er, conf) {
162 t.ifError(er, "configuration loaded")
165 username : "username",
166 password : "password",
167 email : "ogd@aoaioxxysz.net"
170 t.doesNotThrow(function () {
171 conf.setCredentialsByURI(URI, credentials)
172 }, "requires all of username, password, and email")
175 scope : "//registry.lvh.me:8661/",
177 username : "username",
178 password : "password",
179 email : "ogd@aoaioxxysz.net",
180 auth : "dXNlcm5hbWU6cGFzc3dvcmQ=",
184 t.same(conf.getCredentialsByURI(URI), expected, "got credentials")
190 test("clear with old-style credentials", function (t) {
191 npmconf.load(common.builtin, function (er, conf) {
192 t.ifError(er, "configuration loaded")
195 username : "username",
196 password : "password",
197 email : "ogd@aoaioxxysz.net"
200 t.doesNotThrow(function () {
201 conf.setCredentialsByURI(URI, credentials)
202 }, "requires all of username, password, and email")
204 t.doesNotThrow(function () {
205 conf.clearCredentialsByURI(URI)
206 }, "clearing only required URI")
208 t.notOk(conf.getCredentialsByURI(URI).username, "username cleared")
209 t.notOk(conf.getCredentialsByURI(URI).password, "password cleared")
215 test("get old-style credentials for default registry", function (t) {
216 npmconf.load(common.builtin, function (er, conf) {
217 var actual = conf.getCredentialsByURI(conf.get("registry"))
219 scope : "//registry.npmjs.org/",
221 password : "password",
222 username : "username",
224 auth : "dXNlcm5hbWU6cGFzc3dvcmQ=",
227 t.same(actual, expected)
232 test("set with always-auth enabled", function (t) {
233 npmconf.load(common.builtin, function (er, conf) {
234 t.ifError(er, "configuration loaded")
237 username : "username",
238 password : "password",
239 email : "ogd@aoaioxxysz.net",
243 conf.setCredentialsByURI(URI, credentials)
246 scope : "//registry.lvh.me:8661/",
248 username : "username",
249 password : "password",
250 email : "ogd@aoaioxxysz.net",
251 auth : "dXNlcm5hbWU6cGFzc3dvcmQ=",
255 t.same(conf.getCredentialsByURI(URI), expected, "got credentials")
261 test("set with always-auth disabled", function (t) {
262 npmconf.load(common.builtin, function (er, conf) {
263 t.ifError(er, "configuration loaded")
266 username : "username",
267 password : "password",
268 email : "ogd@aoaioxxysz.net",
272 conf.setCredentialsByURI(URI, credentials)
275 scope : "//registry.lvh.me:8661/",
277 username : "username",
278 password : "password",
279 email : "ogd@aoaioxxysz.net",
280 auth : "dXNlcm5hbWU6cGFzc3dvcmQ=",
284 t.same(conf.getCredentialsByURI(URI), expected, "got credentials")
290 test("set with global always-auth enabled", function (t) {
291 npmconf.load(common.builtin, function (er, conf) {
292 t.ifError(er, "configuration loaded")
293 var original = conf.get("always-auth")
294 conf.set("always-auth", true)
297 username : "username",
298 password : "password",
299 email : "ogd@aoaioxxysz.net"
302 conf.setCredentialsByURI(URI, credentials)
305 scope : "//registry.lvh.me:8661/",
307 username : "username",
308 password : "password",
309 email : "ogd@aoaioxxysz.net",
310 auth : "dXNlcm5hbWU6cGFzc3dvcmQ=",
314 t.same(conf.getCredentialsByURI(URI), expected, "got credentials")
316 conf.set("always-auth", original)
321 test("set with global always-auth disabled", function (t) {
322 npmconf.load(common.builtin, function (er, conf) {
323 t.ifError(er, "configuration loaded")
324 var original = conf.get("always-auth")
325 conf.set("always-auth", false)
328 username : "username",
329 password : "password",
330 email : "ogd@aoaioxxysz.net"
333 conf.setCredentialsByURI(URI, credentials)
336 scope : "//registry.lvh.me:8661/",
338 username : "username",
339 password : "password",
340 email : "ogd@aoaioxxysz.net",
341 auth : "dXNlcm5hbWU6cGFzc3dvcmQ=",
345 t.same(conf.getCredentialsByURI(URI), expected, "got credentials")
347 conf.set("always-auth", original)