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