From 9b08ac4b79e34eb4e331966558e9330e05fac57a Mon Sep 17 00:00:00 2001 From: zkochan Date: Tue, 25 Apr 2017 22:28:47 +0300 Subject: [PATCH] test: installing of private package from shrinkwrap When resolution is saved in cache and the meta info is on a different path. Correct auth info should be used for downloading the tarball. Close #718 --- test/install/auth.ts | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/test/install/auth.ts b/test/install/auth.ts index a27ddeb9e6..1916d3808b 100644 --- a/test/install/auth.ts +++ b/test/install/auth.ts @@ -1,12 +1,14 @@ import tape = require('tape') import promisifyTape from 'tape-promise' +import path = require('path') import { prepare, testDefaults, } from '../utils' -import {installPkgs} from '../../src' +import {installPkgs, install} from '../../src' import registryMock = require('pnpm-registry-mock') import RegClient = require('anonymous-npm-registry-client') +import rimraf = require('rimraf-then') const test = promisifyTape(tape) @@ -62,3 +64,38 @@ test('a package that need authentication reuses authorization tokens for tarball t.ok(typeof m === 'function', 'needs-auth() is available') }) + +test('a package that need authentication reuses authorization tokens for tarball fetching when meta info is cached', async function (t: tape.Test) { + const project = prepare(t) + + const client = new RegClient() + + const data = await new Promise((resolve, reject) => { + client.adduser('http://localhost:4873', { + auth: { + username: 'foo', + password: 'bar', + email: 'foo@bar.com', + } + }, (err: Error, data: Object) => err ? reject(err) : resolve(data)) + }) + + const opts = { + registry: 'http://127.0.0.1:4873', + rawNpmConfig: { + '//127.0.0.1:4873/:_authToken': data['token'], + }, + } + + await installPkgs(['needs-auth'], opts) + + await rimraf('node_modules') + await rimraf(path.join('..', '.registry')) + await rimraf(path.join('..', '.store')) + + await install(opts) + + const m = project.requireModule('needs-auth') + + t.ok(typeof m === 'function', 'needs-auth() is available') +})