UNPKG

3.97 kBJavaScriptView Raw
1var test = require("tap").test
2
3var npmconf = require("../npmconf.js")
4var common = require("./00-setup.js")
5
6var URI = "https://registry.lvh.me:8661/"
7
8test("getting scope with no credentials set", function (t) {
9 npmconf.load({}, function (er, conf) {
10 t.ifError(er, "configuration loaded")
11
12 var basic = conf.getCredentialsByURI(URI)
13 t.equal(basic.scope, "//registry.lvh.me:8661/", "nerfed URL extracted")
14
15 t.end()
16 })
17})
18
19test("trying to set credentials with no URI", function (t) {
20 npmconf.load(common.builtin, function (er, conf) {
21 t.ifError(er, "configuration loaded")
22
23 t.throws(function () {
24 conf.setCredentialsByURI()
25 }, "enforced missing URI")
26
27 t.end()
28 })
29})
30
31test("set with missing credentials object", function (t) {
32 npmconf.load(common.builtin, function (er, conf) {
33 t.ifError(er, "configuration loaded")
34
35 t.throws(function () {
36 conf.setCredentialsByURI(URI)
37 }, "enforced missing credentials")
38
39 t.end()
40 })
41})
42
43test("set with empty credentials object", function (t) {
44 npmconf.load(common.builtin, function (er, conf) {
45 t.ifError(er, "configuration loaded")
46
47 t.throws(function () {
48 conf.setCredentialsByURI(URI, {})
49 }, "enforced missing credentials")
50
51 t.end()
52 })
53})
54
55test("set with token", function (t) {
56 npmconf.load(common.builtin, function (er, conf) {
57 t.ifError(er, "configuration loaded")
58
59 t.doesNotThrow(function () {
60 conf.setCredentialsByURI(URI, {token : "simple-token"})
61 }, "needs only token")
62
63 var expected = {
64 scope : "//registry.lvh.me:8661/",
65 token : "simple-token"
66 }
67
68 t.same(conf.getCredentialsByURI(URI), expected, "got bearer token and scope")
69
70 t.end()
71 })
72})
73
74test("set with missing username", function (t) {
75 npmconf.load(common.builtin, function (er, conf) {
76 t.ifError(er, "configuration loaded")
77
78 var credentials = {
79 password : "password",
80 email : "ogd@aoaioxxysz.net"
81 }
82
83 t.throws(function () {
84 conf.setCredentialsByURI(URI, credentials)
85 }, "enforced missing email")
86
87 t.end()
88 })
89})
90
91test("set with missing password", function (t) {
92 npmconf.load(common.builtin, function (er, conf) {
93 t.ifError(er, "configuration loaded")
94
95 var credentials = {
96 username : "username",
97 email : "ogd@aoaioxxysz.net"
98 }
99
100 t.throws(function () {
101 conf.setCredentialsByURI(URI, credentials)
102 }, "enforced missing email")
103
104 t.end()
105 })
106})
107
108test("set with missing email", function (t) {
109 npmconf.load(common.builtin, function (er, conf) {
110 t.ifError(er, "configuration loaded")
111
112 var credentials = {
113 username : "username",
114 password : "password"
115 }
116
117 t.throws(function () {
118 conf.setCredentialsByURI(URI, credentials)
119 }, "enforced missing email")
120
121 t.end()
122 })
123})
124
125test("set with old-style credentials", function (t) {
126 npmconf.load(common.builtin, function (er, conf) {
127 t.ifError(er, "configuration loaded")
128
129 var credentials = {
130 username : "username",
131 password : "password",
132 email : "ogd@aoaioxxysz.net"
133 }
134
135 t.doesNotThrow(function () {
136 conf.setCredentialsByURI(URI, credentials)
137 }, "requires all of username, password, and email")
138
139 var expected = {
140 scope : "//registry.lvh.me:8661/",
141 username : "username",
142 password : "password",
143 email : "ogd@aoaioxxysz.net",
144 auth : "dXNlcm5hbWU6cGFzc3dvcmQ="
145 }
146
147 t.same(conf.getCredentialsByURI(URI), expected, "got credentials")
148
149 t.end()
150 })
151})
152
153test("get old-style credentials for default registry", function (t) {
154 npmconf.load(common.builtin, function (er, conf) {
155 var actual = conf.getCredentialsByURI(conf.get("registry"))
156 var expected = {
157 scope: '//registry.npmjs.org/',
158 password: 'password',
159 username: 'username',
160 email: 'i@izs.me',
161 auth: 'dXNlcm5hbWU6cGFzc3dvcmQ='
162 }
163 t.same(actual, expected)
164 t.end()
165 })
166})