1 var test = require('tap').test
2 var npm = require('../../')
4 var common = require('../common-tap.js')
5 var mapRegistry = require('../../lib/utils/map-to-registry.js')
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
13 test('setup', function (t) {
14 npm.load(creds, function (err) {
20 test('mapRegistryToURI', function (t) {
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')
27 scope: '//registry.npmjs.org/',
35 t.equal(registry, 'https://registry.npmjs.org/')
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')
45 scope: '//reg.npm/design/-/rewrite/',
53 t.equal(registry, 'http://reg.npm/design/-/rewrite/')
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')
63 scope: '//reg.npm/-/rewrite/',
71 t.equal(registry, 'http://reg.npm/-/rewrite/')
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')
81 scope: '//reg.npm/design/-/rewrite/',
89 t.equal(registry, 'http://reg.npm/design/-/rewrite/relative/')
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')
98 t.test('pass token to registry host', function (t) {
100 'https://reg.npm/packages/e/easy-1.0.0.tgz',
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')
114 t.equal(registry, 'https://reg.npm/')
120 t.test("don't pass token to non-registry host", function (t) {
122 'https://butts.lol/packages/e/easy-1.0.0.tgz',
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')
136 t.equal(registry, 'https://reg.npm/')
142 t.test('pass token to non-registry host with always-auth', function (t) {
143 npm.config.set('always-auth', true)
145 'https://butts.lol/packages/e/easy-1.0.0.tgz',
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')
159 t.equal(registry, 'https://reg.npm/')