1'use strict' 2 3const BB = require('bluebird') 4 5var fs = require('graceful-fs') 6var path = require('path') 7 8var mkdirp = require('mkdirp') 9var requireInject = require('require-inject') 10var test = require('tap').test 11 12var common = require('../common-tap.js') 13 14var pkg = common.pkg 15 16var json = { 17 name: 'bitbucket-https-url-with-creds', 18 version: '0.0.0' 19} 20 21test('setup', function (t) { 22 setup() 23 t.end() 24}) 25 26test('bitbucket-https-url-with-creds', function (t) { 27 var cloneUrls = [ 28 ['https://user:pass@bitbucket.org/foo/private.git', 'Bitbucket URLs with passwords try only that.'] 29 ] 30 31 var npm = requireInject.installGlobally('../../lib/npm.js', { 32 'pacote/lib/util/git': { 33 'revs': (repo, opts) => { 34 return BB.resolve().then(() => { 35 var cloneUrl = cloneUrls.shift() 36 if (cloneUrl) { 37 t.is(repo, cloneUrl[0], cloneUrl[1]) 38 } else { 39 t.fail('too many attempts to clone') 40 } 41 throw new Error('git.revs mock fails on purpose') 42 }) 43 } 44 } 45 }) 46 47 var opts = { 48 cache: common.cache, 49 prefix: pkg, 50 registry: common.registry, 51 loglevel: 'silent' 52 } 53 npm.load(opts, function (er) { 54 t.ifError(er, 'npm loaded without error') 55 npm.commands.install(['git+https://user:pass@bitbucket.org/foo/private.git'], function (err) { 56 t.match(err, /mock fails on purpose/, 'mocked install failed as expected') 57 t.end() 58 }) 59 }) 60}) 61 62function setup () { 63 mkdirp.sync(pkg) 64 fs.writeFileSync( 65 path.join(pkg, 'package.json'), 66 JSON.stringify(json, null, 2) 67 ) 68 process.chdir(pkg) 69} 70