1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
var test = require("tap").test
var npm = require("../../")
var mapRegistry = require("../../lib/utils/map-to-registry.js")
var creds = {
"//registry.npmjs.org/:username" : "u",
"//registry.npmjs.org/:_password" : new Buffer("p").toString("base64"),
"//registry.npmjs.org/:email" : "e"
}
test("setup", function (t) {
npm.load(creds, function (err) {
t.ifError(err)
t.end()
})
})
test("mapRegistryToURI", function (t) {
t.plan(16)
mapRegistry("basic", npm.config, function (er, uri, auth, registry) {
t.ifError(er, "mapRegistryToURI worked")
t.equal(uri, "https://registry.npmjs.org/basic")
t.deepEqual(auth, {
scope : "//registry.npmjs.org/",
token : undefined,
username : "u",
password : "p",
email : "e",
auth : "dTpw",
alwaysAuth : false
})
t.equal(registry, "https://registry.npmjs.org/")
})
npm.config.set("scope", "test")
npm.config.set("@test:registry", "http://reg.npm/design/-/rewrite/")
npm.config.set("//reg.npm/design/-/rewrite/:_authToken", "a-token")
mapRegistry("simple", npm.config, function (er, uri, auth, registry) {
t.ifError(er, "mapRegistryToURI worked")
t.equal(uri, "http://reg.npm/design/-/rewrite/simple")
t.deepEqual(auth, {
scope : "//reg.npm/design/-/rewrite/",
token : "a-token",
username : undefined,
password : undefined,
email : undefined,
auth : undefined,
alwaysAuth : undefined
})
t.equal(registry, "http://reg.npm/design/-/rewrite/")
})
npm.config.set("scope", "")
npm.config.set("@test2:registry", "http://reg.npm/-/rewrite/")
npm.config.set("//reg.npm/-/rewrite/:_authToken", "b-token")
mapRegistry("@test2/easy", npm.config, function (er, uri, auth, registry) {
t.ifError(er, "mapRegistryToURI worked")
t.equal(uri, "http://reg.npm/-/rewrite/@test2%2feasy")
t.deepEqual(auth, {
scope : "//reg.npm/-/rewrite/",
token : "b-token",
username : undefined,
password : undefined,
email : undefined,
auth : undefined,
alwaysAuth : undefined
})
t.equal(registry, "http://reg.npm/-/rewrite/")
})
npm.config.set("scope", "test")
npm.config.set("@test3:registry", "http://reg.npm/design/-/rewrite/relative")
npm.config.set("//reg.npm/design/-/rewrite/:_authToken", "c-token")
mapRegistry("@test3/basic", npm.config, function (er, uri, auth, registry) {
t.ifError(er, "mapRegistryToURI worked")
t.equal(uri, "http://reg.npm/design/-/rewrite/relative/@test3%2fbasic")
t.deepEqual(auth, {
scope : "//reg.npm/design/-/rewrite/",
token : "c-token",
username : undefined,
password : undefined,
email : undefined,
auth : undefined,
alwaysAuth : undefined
})
t.equal(registry, "http://reg.npm/design/-/rewrite/relative/")
})
})
|