Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorForrest L Norvell <forrest@npmjs.com>2015-04-11 20:54:02 +0300
committerForrest L Norvell <forrest@npmjs.com>2015-04-11 20:54:02 +0300
commit15efe124753257728a0ddc64074fa5a4b9c2eb30 (patch)
tree3081e728c2faf3ef616891e05f44dcb6d36161ba
parent66377c6ece2cf4d53d9a618b7d9824e1452bc293 (diff)
git: ensure Bitbucket with auth passes on creds
-rw-r--r--lib/cache/add-remote-git.js2
-rw-r--r--test/tap/bitbucket-https-url-with-creds-package.js83
-rw-r--r--test/tap/bitbucket-https-url-with-creds.js80
3 files changed, 165 insertions, 0 deletions
diff --git a/lib/cache/add-remote-git.js b/lib/cache/add-remote-git.js
index 0f7751f0f..ce4163375 100644
--- a/lib/cache/add-remote-git.js
+++ b/lib/cache/add-remote-git.js
@@ -36,6 +36,8 @@ module.exports = function addRemoteGit (uri, _cb) {
assert(typeof _cb === 'function', 'must have callback')
var cb = dezalgo(_cb)
+ log.verbose('addRemoteGit', 'caching', uri)
+
// the URL comes in exactly as it was passed on the command line, or as
// normalized by normalize-package-data / read-package-json / read-installed,
// so figure out what to do with it using hosted-git-info
diff --git a/test/tap/bitbucket-https-url-with-creds-package.js b/test/tap/bitbucket-https-url-with-creds-package.js
new file mode 100644
index 000000000..e5a4142ef
--- /dev/null
+++ b/test/tap/bitbucket-https-url-with-creds-package.js
@@ -0,0 +1,83 @@
+'use strict'
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var requireInject = require('require-inject')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+
+var pkg = path.resolve(__dirname, 'bitbucket-https-url-with-creds-package')
+
+var json = {
+ name: 'bitbucket-https-url-with-creds-package',
+ version: '0.0.0',
+ dependencies: {
+ 'private': 'git+https://user:pass@bitbucket.org/foo/private.git'
+ }
+}
+
+test('setup', function (t) {
+ setup()
+ t.end()
+})
+
+test('bitbucket-https-url-with-creds-package', function (t) {
+ var cloneUrls = [
+ ['https://user:pass@bitbucket.org/foo/private.git', 'Bitbucket URLs with passwords try only that.']
+ ]
+
+ var npm = requireInject.installGlobally('../../lib/npm.js', {
+ 'child_process': {
+ 'execFile': function (cmd, args, options, cb) {
+ process.nextTick(function () {
+ if (args[0] !== 'clone') return cb(null, '', '')
+ var cloneUrl = cloneUrls.shift()
+ if (cloneUrl) {
+ t.is(args[3], cloneUrl[0], cloneUrl[1])
+ } else {
+ t.fail('too many attempts to clone')
+ }
+ cb(new Error())
+ })
+ }
+ }
+ })
+
+ var opts = {
+ cache: path.resolve(pkg, 'cache'),
+ prefix: pkg,
+ registry: common.registry,
+ loglevel: 'silent'
+ }
+ npm.load(opts, function (er) {
+ t.ifError(er, 'npm loaded without error')
+ npm.commands.install([], function (er) {
+ t.ok(er, 'mocked install failed as expected')
+ t.end()
+ })
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function setup () {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
+}
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
diff --git a/test/tap/bitbucket-https-url-with-creds.js b/test/tap/bitbucket-https-url-with-creds.js
new file mode 100644
index 000000000..3f39e3be4
--- /dev/null
+++ b/test/tap/bitbucket-https-url-with-creds.js
@@ -0,0 +1,80 @@
+'use strict'
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var requireInject = require('require-inject')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+
+var pkg = path.resolve(__dirname, 'bitbucket-https-url-with-creds')
+
+var json = {
+ name: 'bitbucket-https-url-with-creds',
+ version: '0.0.0'
+}
+
+test('setup', function (t) {
+ setup()
+ t.end()
+})
+
+test('bitbucket-https-url-with-creds', function (t) {
+ var cloneUrls = [
+ ['https://user:pass@bitbucket.org/foo/private.git', 'Bitbucket URLs with passwords try only that.']
+ ]
+
+ var npm = requireInject.installGlobally('../../lib/npm.js', {
+ 'child_process': {
+ 'execFile': function (cmd, args, options, cb) {
+ process.nextTick(function () {
+ if (args[0] !== 'clone') return cb(null, '', '')
+ var cloneUrl = cloneUrls.shift()
+ if (cloneUrl) {
+ t.is(args[3], cloneUrl[0], cloneUrl[1])
+ } else {
+ t.fail('too many attempts to clone')
+ }
+ cb(new Error())
+ })
+ }
+ }
+ })
+
+ var opts = {
+ cache: path.resolve(pkg, 'cache'),
+ prefix: pkg,
+ registry: common.registry,
+ loglevel: 'silent'
+ }
+ npm.load(opts, function (er) {
+ t.ifError(er, 'npm loaded without error')
+ npm.commands.install(['git+https://user:pass@bitbucket.org/foo/private.git'], function (er) {
+ t.ok(er, 'mocked install failed as expected')
+ t.end()
+ })
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function setup () {
+ cleanup()
+ mkdirp.sync(pkg)
+ fs.writeFileSync(
+ path.join(pkg, 'package.json'),
+ JSON.stringify(json, null, 2)
+ )
+ process.chdir(pkg)
+}
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}