]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/map-to-registry.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / map-to-registry.js
1 var test = require('tap').test
2 var npm = require('../../')
3
4 var common = require('../common-tap.js')
5 var mapRegistry = require('../../lib/utils/map-to-registry.js')
6
7 var creds = {
8   '//registry.npmjs.org/:username': 'u',
9   '//registry.npmjs.org/:_password': new Buffer('p').toString('base64'),
10   '//registry.npmjs.org/:email': 'e',
11   cache: common.npm_config_cache
12 }
13 test('setup', function (t) {
14   npm.load(creds, function (err) {
15     t.ifError(err)
16     t.end()
17   })
18 })
19
20 test('mapRegistryToURI', function (t) {
21   t.plan(16)
22
23   mapRegistry('basic', npm.config, function (er, uri, auth, registry) {
24     t.ifError(er, 'mapRegistryToURI worked')
25     t.equal(uri, 'https://registry.npmjs.org/basic')
26     t.deepEqual(auth, {
27       scope: '//registry.npmjs.org/',
28       token: undefined,
29       username: 'u',
30       password: 'p',
31       email: 'e',
32       auth: 'dTpw',
33       alwaysAuth: false
34     })
35     t.equal(registry, 'https://registry.npmjs.org/')
36   })
37
38   npm.config.set('scope', 'test')
39   npm.config.set('@test:registry', 'http://reg.npm/design/-/rewrite/')
40   npm.config.set('//reg.npm/design/-/rewrite/:_authToken', 'a-token')
41   mapRegistry('simple', npm.config, function (er, uri, auth, registry) {
42     t.ifError(er, 'mapRegistryToURI worked')
43     t.equal(uri, 'http://reg.npm/design/-/rewrite/simple')
44     t.deepEqual(auth, {
45       scope: '//reg.npm/design/-/rewrite/',
46       token: 'a-token',
47       username: undefined,
48       password: undefined,
49       email: undefined,
50       auth: undefined,
51       alwaysAuth: false
52     })
53     t.equal(registry, 'http://reg.npm/design/-/rewrite/')
54   })
55
56   npm.config.set('scope', '')
57   npm.config.set('@test2:registry', 'http://reg.npm/-/rewrite/')
58   npm.config.set('//reg.npm/-/rewrite/:_authToken', 'b-token')
59   mapRegistry('@test2/easy', npm.config, function (er, uri, auth, registry) {
60     t.ifError(er, 'mapRegistryToURI worked')
61     t.equal(uri, 'http://reg.npm/-/rewrite/@test2%2feasy')
62     t.deepEqual(auth, {
63       scope: '//reg.npm/-/rewrite/',
64       token: 'b-token',
65       username: undefined,
66       password: undefined,
67       email: undefined,
68       auth: undefined,
69       alwaysAuth: false
70     })
71     t.equal(registry, 'http://reg.npm/-/rewrite/')
72   })
73
74   npm.config.set('scope', 'test')
75   npm.config.set('@test3:registry', 'http://reg.npm/design/-/rewrite/relative')
76   npm.config.set('//reg.npm/design/-/rewrite/:_authToken', 'c-token')
77   mapRegistry('@test3/basic', npm.config, function (er, uri, auth, registry) {
78     t.ifError(er, 'mapRegistryToURI worked')
79     t.equal(uri, 'http://reg.npm/design/-/rewrite/relative/@test3%2fbasic')
80     t.deepEqual(auth, {
81       scope: '//reg.npm/design/-/rewrite/',
82       token: 'c-token',
83       username: undefined,
84       password: undefined,
85       email: undefined,
86       auth: undefined,
87       alwaysAuth: false
88     })
89     t.equal(registry, 'http://reg.npm/design/-/rewrite/relative/')
90   })
91 })
92
93 test('mapToRegistry token scoping', function (t) {
94   npm.config.set('scope', '')
95   npm.config.set('registry', 'https://reg.npm/')
96   npm.config.set('//reg.npm/:_authToken', 'r-token')
97
98   t.test('pass token to registry host', function (t) {
99     mapRegistry(
100       'https://reg.npm/packages/e/easy-1.0.0.tgz',
101       npm.config,
102       function (er, uri, auth, registry) {
103         t.ifError(er, 'mapRegistryToURI worked')
104         t.equal(uri, 'https://reg.npm/packages/e/easy-1.0.0.tgz')
105         t.deepEqual(auth, {
106           scope: '//reg.npm/',
107           token: 'r-token',
108           username: undefined,
109           password: undefined,
110           email: undefined,
111           auth: undefined,
112           alwaysAuth: false
113         })
114         t.equal(registry, 'https://reg.npm/')
115       }
116     )
117     t.end()
118   })
119
120   t.test("don't pass token to non-registry host", function (t) {
121     mapRegistry(
122       'https://butts.lol/packages/e/easy-1.0.0.tgz',
123       npm.config,
124       function (er, uri, auth, registry) {
125         t.ifError(er, 'mapRegistryToURI worked')
126         t.equal(uri, 'https://butts.lol/packages/e/easy-1.0.0.tgz')
127         t.deepEqual(auth, {
128           scope: '//reg.npm/',
129           token: undefined,
130           username: undefined,
131           password: undefined,
132           email: undefined,
133           auth: undefined,
134           alwaysAuth: false
135         })
136         t.equal(registry, 'https://reg.npm/')
137       }
138     )
139     t.end()
140   })
141
142   t.test('pass token to non-registry host with always-auth', function (t) {
143     npm.config.set('always-auth', true)
144     mapRegistry(
145       'https://butts.lol/packages/e/easy-1.0.0.tgz',
146       npm.config,
147       function (er, uri, auth, registry) {
148         t.ifError(er, 'mapRegistryToURI worked')
149         t.equal(uri, 'https://butts.lol/packages/e/easy-1.0.0.tgz')
150         t.deepEqual(auth, {
151           scope: '//reg.npm/',
152           token: 'r-token',
153           username: undefined,
154           password: undefined,
155           email: undefined,
156           auth: undefined,
157           alwaysAuth: true
158         })
159         t.equal(registry, 'https://reg.npm/')
160       }
161     )
162     t.end()
163   })
164
165   t.end()
166 })