1 var common = require('../common-tap.js')
2 var test = require('tap').test
3 var npm = require('../../')
4 var mkdirp = require('mkdirp')
5 var rimraf = require('rimraf')
6 var path = require('path')
7 var mr = require('npm-registry-mock')
9 var updateIndex = require('../../lib/cache/update-index.js')
11 var PKG_DIR = path.resolve(__dirname, 'get-basic')
12 var CACHE_DIR = path.resolve(PKG_DIR, 'cache')
17 basic: function (mock) {
18 mock.get('/-/all').reply(200, allMock)
20 auth: function (mock) {
21 var littleBobbyTablesAuth = new Buffer('bobby:tables').toString('base64')
22 var auth = 'Basic ' + littleBobbyTablesAuth
23 mock.get('/-/all', { authorization: auth }).reply(200, allMock)
24 mock.get('/-/all').reply(401, {
25 error: 'unauthorized',
26 reason: 'You are not authorized to access this db.'
32 '_updated': 1411727900 + 25,
33 'generator-frontcow': {
34 'name': 'generator-frontcow',
35 'description': 'f36b6a6123da50959741e2ce4d634f96ec668c56 This is a fake description to ensure we do not accidentally search the real npm registry or use some kind of cache',
42 'email': 'contact@benjamincabanes.com'
45 'homepage': 'https://github.com/bcabanes/generator-frontcow',
62 'url': 'https://github.com/bcabanes/generator-frontcow'
66 'email': 'contact@benjamincabanes.com',
67 'url': 'https://github.com/bcabanes'
70 'url': 'https://github.com/bcabanes/generator-frontcow/issues'
73 'readmeFilename': 'README.md',
75 'modified': '2014-10-03T02:26:18.406Z'
83 'description': 'Marko is an extensible, streaming, asynchronous, high performance, HTML-based templating language that can be used in Node.js or in the browser.',
90 'email': 'pnidem@gmail.com'
94 'email': 'phillip.idem@gmail.com'
97 'homepage': 'https://github.com/raptorjs/marko',
106 'url': 'https://github.com/raptorjs/marko.git'
109 'name': 'Patrick Steele-Idem',
110 'email': 'pnidem@gmail.com'
113 'url': 'https://github.com/raptorjs/marko/issues'
115 'license': 'Apache License v2.0',
116 'readmeFilename': 'README.md',
121 'modified': '2014-10-03T02:27:31.775Z'
129 function setup (t, mock, extra) {
130 mkdirp.sync(CACHE_DIR)
131 mr({ port: common.port, plugin: mock }, function (er, s) {
132 npm.load({ cache: CACHE_DIR, registry: common.registry }, function (err) {
134 Object.keys(extra).forEach(function (k) {
135 npm.config.set(k, extra[k], 'user')
138 t.ifError(err, 'no error')
145 function cleanup (t) {
146 server.close(function () {
153 test('setup basic', function (t) {
154 setup(t, mocks.basic)
157 test('request basic', function (t) {
158 updateIndex(0, function (er) {
159 t.ifError(er, 'no error')
164 test('cleanup basic', cleanup)
166 test('setup auth', function (t) {
170 test('request auth failure', function (t) {
171 updateIndex(0, function (er) {
172 t.equals(er.code, 'E401', 'gotta get that auth')
173 t.ok(/^unauthorized/.test(er.message), 'unauthorized message')
178 test('cleanup auth failure', cleanup)
180 test('setup auth', function (t) {
181 // mimic as if alwaysAuth had been set
182 setup(t, mocks.auth, {
183 _auth: new Buffer('bobby:tables').toString('base64'),
188 test('request auth success', function (t) {
189 updateIndex(0, function (er) {
190 t.ifError(er, 'no error')
195 test('cleanup auth', cleanup)