0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-06 22:40:26 -05:00

refactor: jest migration completed

This commit is contained in:
Juan Picado @jotadeveloper 2017-12-02 11:19:08 +01:00 committed by juanpicado
parent 4cbbb2f370
commit ca5fd82d95
25 changed files with 362 additions and 401 deletions

View file

@ -9,4 +9,5 @@ module.exports = {
'fixtures' 'fixtures'
], ],
'testRegex': '(/test/unit.*\\.spec|test/functional.*\\.func)\\.js' 'testRegex': '(/test/unit.*\\.spec|test/functional.*\\.func)\\.js'
// 'testRegex': '(test/functional.*\\.func)\\.js'
}; };

View file

@ -138,7 +138,7 @@
"prepublish": "in-publish && npm run build:webui || not-in-publish", "prepublish": "in-publish && npm run build:webui || not-in-publish",
"flow": "flow", "flow": "flow",
"pretest": "npm run code:build", "pretest": "npm run code:build",
"test": "cross-env jest -i", "test": "cross-env jest",
"pre:ci": "npm run build:webui", "pre:ci": "npm run build:webui",
"test:only": "mocha ./test/functional ./test/unit", "test:only": "mocha ./test/functional ./test/unit",
"coverage:publish": "codecov", "coverage:publish": "codecov",

View file

@ -1,51 +1,46 @@
'use strict'; import fs from 'fs';
import path from 'path';
import Server from '../lib/server'; export default function(server) {
const fs = require('fs'); describe('npm adduser', () => {
const path = require('path');
module.exports = function() {
const server = new Server('http://localhost:55551/');
describe('npm adduser', function() {
const user = String(Math.random()); const user = String(Math.random());
const pass = String(Math.random()); const pass = String(Math.random());
before(function() { beforeAll(function() {
return server.auth(user, pass) return server.auth(user, pass)
.status(201) .status(201)
.body_ok(/user .* created/); .body_ok(/user .* created/);
}); });
it('should create new user', function() {}); test('should create new user', () => {});
it('should log in', function() { test('should log in', () => {
return server.auth(user, pass) return server.auth(user, pass)
.status(201) .status(201)
.body_ok(/you are authenticated as/); .body_ok(/you are authenticated as/);
}); });
it('should not register more users', function() { test('should not register more users', () => {
return server.auth(String(Math.random()), String(Math.random())) return server.auth(String(Math.random()), String(Math.random()))
.status(409) .status(409)
.body_error(/maximum amount of users reached/); .body_error(/maximum amount of users reached/);
}); });
}); });
describe('should adduser created with htpasswd', function() { describe('should adduser created with htpasswd', () => {
const user = 'preexisting'; const user = 'preexisting';
const pass = 'preexisting'; const pass = 'preexisting';
before(function() { beforeAll(function() {
return fs.appendFileSync( return fs.appendFileSync(
path.join(__dirname, '../store/test-storage', '.htpasswd'), path.join(__dirname, '../store/test-storage', '.htpasswd'),
'preexisting:$apr1$4YSboUa9$yVKjE7.PxIOuK3M4D7VjX.' 'preexisting:$apr1$4YSboUa9$yVKjE7.PxIOuK3M4D7VjX.'
); );
}); });
it('should log in', function() { test('should log in', () => {
return server.auth(user, pass) return server.auth(user, pass)
.status(201) .status(201)
.body_ok(/you are authenticated as/); .body_ok(/you are authenticated as/);
}); });
}); });
}; }

View file

@ -1,13 +1,10 @@
'use strict'; export default function(server) {
module.exports = function() { describe('logout', () => {
let server = process.server; test('should log out', () => {
describe('logout', function() {
it('should log out', function() {
return server.logout('some-token') return server.logout('some-token')
.status(200) .status(200)
.body_ok(/Logged out/); .body_ok(/Logged out/);
}); });
}); });
}; }

View file

@ -1,102 +1,96 @@
'use strict'; import assert from 'assert';
import crypto from 'crypto';
const assert = require('assert');
const crypto = require('crypto');
function readfile(folderPath) { function readfile(folderPath) {
return require('fs').readFileSync(__dirname + '/' + folderPath); return require('fs').readFileSync(__dirname + '/' + folderPath);
} }
function getPackage(name) { function getPackage(name) {
return require('./fixtures/package')(name); return require('../fixtures/package')(name);
} }
function createHash() { function createHash() {
return crypto.createHash('sha1'); return crypto.createHash('sha1');
} }
module.exports = function () { export default function(server, server2) {
let server = process.server; describe('basic test endpoints', () => {
let server2 = process.server2;
describe('basic test endpoints', function () { require('./whoIam')(server);
require('./ping')(server);
require('./basic/whoIam')(server); describe('handling packages', () => {
require('./basic/ping')(server);
describe('handling packages', function () { beforeAll(function () {
before(function () {
return server.addPackage('testpkg'); return server.addPackage('testpkg');
}); });
before(function () { beforeAll(function () {
return server.addPackage('testpkg-single-tarball'); return server.addPackage('testpkg-single-tarball');
}); });
it('creating new package', function () {/* test for before() */ test('creating new package', () => {/* test for before() */
}); });
it('downloading non-existent tarball', function () { test('downloading non-existent tarball', () => {
return server.getTarball('testpkg', 'blahblah').status(404).body_error(/no such file/); return server.getTarball('testpkg', 'blahblah').status(404).body_error(/no such file/);
}); });
it('uploading incomplete tarball', function () { test('uploading incomplete tarball', () => {
return server.putTarballIncomplete('testpkg', 'blahblah1', readfile('fixtures/binary'), 3000); return server.putTarballIncomplete('testpkg', 'blahblah1', readfile('../fixtures/binary'), 3000);
}); });
describe('publishing package', function () { describe('publishing package', () => {
before(function () { beforeAll(function () {
return server.putTarball('testpkg', 'blahblah', readfile('fixtures/binary')) return server.putTarball('testpkg', 'blahblah', readfile('../fixtures/binary'))
.status(201) .status(201)
.body_ok(/.*/); .body_ok(/.*/);
}); });
before(function () { beforeAll(function () {
return server.putTarball('testpkg-single-tarball', 'single', readfile('fixtures/binary')) return server.putTarball('testpkg-single-tarball', 'single', readfile('../fixtures/binary'))
.status(201) .status(201)
.body_ok(/.*/); .body_ok(/.*/);
}); });
after(function () { afterAll(function () {
return server.removeTarball('testpkg').status(201); return server.removeTarball('testpkg').status(201);
}); });
it('remove a tarball', function () { test('remove a tarball', () => {
/* test for before() */ /* test for before() */
}); });
it('uploading new tarball', function () { test('uploading new tarball', () => {
/* test for after() */ /* test for after() */
}); });
it('remove non existing tarball', function () { test('remove non existing tarball', () => {
return server.removeTarball('testpkg404').status(404); return server.removeTarball('testpkg404').status(404);
}); });
it('remove non existing single tarball', function () { test('remove non existing single tarball', () => {
return server.removeSingleTarball('', 'fakeFile').status(404); return server.removeSingleTarball('', 'fakeFile').status(404);
}); });
// testexp-incomplete // testexp-incomplete
it('remove existing single tarball', function () { test('remove existing single tarball', () => {
return server.removeSingleTarball('testpkg-single-tarball', 'single').status(201); return server.removeSingleTarball('testpkg-single-tarball', 'single').status(201);
}); });
// testexp-incomplete // testexp-incomplete
it('downloading newly created tarball', function () { test('downloading newly created tarball', () => {
return server.getTarball('testpkg', 'blahblah') return server.getTarball('testpkg', 'blahblah')
.status(200) .status(200)
.then(function (body) { .then(function (body) {
assert.deepEqual(body, readfile('fixtures/binary')); assert.deepEqual(body, readfile('../fixtures/binary'));
}); });
}); });
it('uploading new package version (bad sha)', function () { test('uploading new package version (bad sha)', () => {
let pkg = getPackage('testpkg'); let pkg = getPackage('testpkg');
pkg.dist.shasum = createHash().update('fake').digest('hex'); pkg.dist.shasum = createHash().update('fake').digest('hex');
@ -105,22 +99,22 @@ module.exports = function () {
.body_error(/shasum error/); .body_error(/shasum error/);
}); });
describe('publishing version', function () { describe('publishing version', () => {
before(function () { beforeAll(function () {
const pkg = getPackage('testpkg'); const pkg = getPackage('testpkg');
pkg.dist.shasum = createHash().update(readfile('fixtures/binary')).digest('hex'); pkg.dist.shasum = createHash().update(readfile('../fixtures/binary')).digest('hex');
return server.putVersion('testpkg', '0.0.1', pkg) return server.putVersion('testpkg', '0.0.1', pkg)
.status(201) .status(201)
.body_ok(/published/); .body_ok(/published/);
}); });
it('uploading new package version', function () { test('uploading new package version', () => {
/* test for before() */ /* test for before() */
}); });
it('downloading newly created package', function () { test('downloading newly created package', () => {
return server.getPackage('testpkg') return server.getPackage('testpkg')
.status(200) .status(200)
.then(function (body) { .then(function (body) {
@ -133,7 +127,7 @@ module.exports = function () {
}); });
}); });
it('downloading package via server2', function () { test('downloading package via server2', () => {
return server2.getPackage('testpkg') return server2.getPackage('testpkg')
.status(200) .status(200)
.then(function (body) { .then(function (body) {
@ -149,26 +143,29 @@ module.exports = function () {
}); });
}); });
describe('handle failures on endpoints', function () { describe('handle failures on endpoints', () => {
it('should fails trying to fetch non-existent package', function () { test('should fails trying to fetch non-existent package', () => {
return server.getPackage('testpkg').status(404).body_error(/no such package/); return server.getPackage('testpkg').status(404).body_error(/no such package/);
}); });
it('should fails on publish a version for non existing package', function () { test(
return server.putVersion('testpxg', '0.0.1', getPackage('testpxg')) 'should fails on publish a version for non existing package',
.status(404) () => {
.body_error(/no such package/); return server.putVersion('testpxg', '0.0.1', getPackage('testpxg'))
}); .status(404)
.body_error(/no such package/);
}
);
it('should be a package not found', function () { test('should be a package not found', () => {
return server.putTarball('nonExistingPackage', 'blahblah', readfile('fixtures/binary')) return server.putTarball('nonExistingPackage', 'blahblah', readfile('../fixtures/binary'))
.status(404) .status(404)
.body_error(/no such/); .body_error(/no such/);
}); });
it('should fails on publish package in a bad uplink', function () { test('should fails on publish package in a bad uplink', () => {
return server.putPackage('baduplink', getPackage('baduplink')) return server.putPackage('baduplink', getPackage('baduplink'))
.status(503) .status(503)
.body_error(/one of the uplinks is down, refuse to publish/); .body_error(/one of the uplinks is down, refuse to publish/);

View file

@ -5,7 +5,7 @@ const _ = require('lodash');
module.exports = function(server) { module.exports = function(server) {
it('ping', function () { test('ping', () => {
return server.ping().then(function (data) { return server.ping().then(function (data) {
// it's always an empty object // it's always an empty object
assert.ok(_.isObject(data)); assert.ok(_.isObject(data));

View file

@ -4,7 +4,7 @@ const assert = require('assert');
module.exports = function(server) { module.exports = function(server) {
it('who am I?', function () { test('who am I?', () => {
return server.whoami().then(function (username) { return server.whoami().then(function (username) {
assert.equal(username, 'test'); assert.equal(username, 'test');
}); });

View file

@ -1,48 +1,44 @@
'use strict'; import assert from 'assert';
import crypto from 'crypto';
const assert = require('assert');
const crypto = require('crypto');
function readfile(x) { function readfile(x) {
return require('fs').readFileSync(__dirname + '/' + x); return require('fs').readFileSync(__dirname + '/' + x);
} }
module.exports = function() { export default function (server, server2) {
const server = process.server;
const server2 = process.server2;
it('downloading non-existent tarball #1 / srv2', function() { test('downloading non-existent tarball #1 / srv2', () => {
return server2.getTarball('testpkg-gh29', 'blahblah') return server2.getTarball('testpkg-gh29', 'blahblah')
.status(404) .status(404)
.body_error(/no such package/); .body_error(/no such package/);
}); });
describe('pkg-gh29', function() { describe('pkg-gh29', () => {
before(function() { beforeAll(function() {
return server.putPackage('testpkg-gh29', require('./fixtures/package')('testpkg-gh29')) return server.putPackage('testpkg-gh29', require('./fixtures/package')('testpkg-gh29'))
.status(201) .status(201)
.body_ok(/created new package/); .body_ok(/created new package/);
}); });
it('creating new package / srv1', function() {}); test('creating new package / srv1', () => {});
it('downloading non-existent tarball #2 / srv2', function() { test('downloading non-existent tarball #2 / srv2', () => {
return server2.getTarball('testpkg-gh29', 'blahblah') return server2.getTarball('testpkg-gh29', 'blahblah')
.status(404) .status(404)
.body_error(/no such file/); .body_error(/no such file/);
}); });
describe('tarball', function() { describe('tarball', () => {
before(function() { beforeAll(function() {
return server.putTarball('testpkg-gh29', 'blahblah', readfile('fixtures/binary')) return server.putTarball('testpkg-gh29', 'blahblah', readfile('fixtures/binary'))
.status(201) .status(201)
.body_ok(/.*/); .body_ok(/.*/);
}); });
it('uploading new tarball / srv1', function() {}); test('uploading new tarball / srv1', () => {});
describe('pkg version', function() { describe('pkg version', () => {
before(function() { beforeAll(function() {
const pkg = require('./fixtures/package')('testpkg-gh29'); const pkg = require('./fixtures/package')('testpkg-gh29');
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex'); pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex');
@ -51,9 +47,9 @@ module.exports = function() {
.body_ok(/published/); .body_ok(/published/);
}); });
it('uploading new package version / srv1', function() {}); test('uploading new package version / srv1', () => {});
it('downloading newly created tarball / srv2', function() { test('downloading newly created tarball / srv2', () => {
return server2.getTarball('testpkg-gh29', 'blahblah') return server2.getTarball('testpkg-gh29', 'blahblah')
.status(200) .status(200)
.then(function(body) { .then(function(body) {
@ -63,5 +59,4 @@ module.exports = function() {
}); });
}); });
}); });
}; }

View file

@ -1,18 +1,41 @@
// @flow // @flow
import _ from 'lodash'; import _ from 'lodash';
// we need this for notifications
import {setup} from '../../src/lib/logger';
setup();
import {VerdaccioConfig} from './lib/verdaccio-server'; import {VerdaccioConfig} from './lib/verdaccio-server';
import VerdaccioProcess from './lib/server_process'; import VerdaccioProcess from './lib/server_process';
import ExpressServer from './lib/simple_server'; import ExpressServer from './lib/simple_server';
import Server from './lib/server'; import Server from './lib/server';
import type {IServerProcess, IServerBridge} from './lib/types'; import type {IServerProcess, IServerBridge} from './lib/types';
import basic from './basic/basic.spec';
import packageAccess from './package/access.spec'; import packageAccess from './package/access.spec';
import packageGzip from './package/gzip.spec'; import packageGzip from './package/gzip.spec';
import packageScoped from './package/scoped.spec'; import packageScoped from './package/scoped.spec';
import tags from './tags/tags.spec';
import preserveTags from './tags/preserve_tags.spec';
import addtag from './tags/addtag.spec';
import adduser from './adduser/adduser';
import logout from './adduser/logout';
import notify from './notifications/notify';
import incomplete from './sanity/incomplete';
import mirror from './sanity/mirror';
import readme from './readme/readme.spec';
import gh29 from './gh29';
import nullstorage from './sanity/nullstorage';
import racycrash from './sanity/racycrash';
import security from './sanity/security';
import race from './performance/race';
import pluginsAuth from './plugins/auth.spec';
import upLinkCache from './uplink.cache.spec';
import upLinkAuth from './uplink.auth.spec';
describe('functional test verdaccio', function() { describe('functional test verdaccio', function() {
const EXPRESS_PORT = 55550; const EXPRESS_PORT = 55550;
const SILENCE_LOG = !process.env.VERDACCIO_DEBUG;
const processRunning = []; const processRunning = [];
const config1 = new VerdaccioConfig( const config1 = new VerdaccioConfig(
'./store/test-storage', './store/test-storage',
@ -29,9 +52,9 @@ describe('functional test verdaccio', function() {
const server1: IServerBridge = new Server(config1.domainPath); const server1: IServerBridge = new Server(config1.domainPath);
const server2: IServerBridge = new Server(config2.domainPath); const server2: IServerBridge = new Server(config2.domainPath);
const server3: IServerBridge = new Server(config3.domainPath); const server3: IServerBridge = new Server(config3.domainPath);
const process1: IServerProcess = new VerdaccioProcess(config1, server1); const process1: IServerProcess = new VerdaccioProcess(config1, server1, SILENCE_LOG);
const process2: IServerProcess = new VerdaccioProcess(config2, server2); const process2: IServerProcess = new VerdaccioProcess(config2, server2, SILENCE_LOG);
const process3: IServerProcess = new VerdaccioProcess(config3, server3); const process3: IServerProcess = new VerdaccioProcess(config3, server3, SILENCE_LOG);
const express: any = new ExpressServer(); const express: any = new ExpressServer();
beforeAll((done) => { beforeAll((done) => {
@ -59,25 +82,35 @@ describe('functional test verdaccio', function() {
express.server.close(); express.server.close();
}); });
// list of test
// note: order of the following calls is important
packageAccess(server1); packageAccess(server1);
basic(server1, server2);
gh29(server1, server2);
tags(server1, express.app);
packageGzip(server1, express.app); packageGzip(server1, express.app);
incomplete(server1, express.app);
mirror(server1, server2);
preserveTags(server1, server2, express.app);
readme(server1, server2);
nullstorage(server1, server2);
race(server1);
racycrash(server1, express.app);
packageScoped(server1, server2); packageScoped(server1, server2);
security(server1);
addtag(server1);
pluginsAuth(server2);
notify(express.app);
// requires packages published to server1/server2
upLinkCache(server1, server2, server3);
upLinkAuth();
adduser(server1);
logout(server1);
});
test('process test', () => { process.on('unhandledRejection', function(err) {
expect(true).toBeTruthy(); console.error("unhandledRejection", err);
process.nextTick(function() {
}); throw err;
});
describe('package access control22', () => {
test('process test2', () => {
expect(true).toBeTruthy();
});
process.on('unhandledRejection', function(err) {
console.error("unhandledRejection", err);
process.nextTick(function() {
throw err;
});
}); });
}); });

View file

@ -11,9 +11,10 @@ export default class VerdaccioProcess implements IServerProcess {
config: IVerdaccioConfig; config: IVerdaccioConfig;
childFork: any; childFork: any;
constructor(config: IVerdaccioConfig, bridge: IServerBridge) { constructor(config: IVerdaccioConfig, bridge: IServerBridge, silence = true) {
this.config = config; this.config = config;
this.bridge = bridge; this.bridge = bridge;
this.silence = silence;
} }
init(): Promise<any> { init(): Promise<any> {
@ -30,7 +31,7 @@ export default class VerdaccioProcess implements IServerProcess {
this.childFork = fork(verdaccioRegisterWrap, this.childFork = fork(verdaccioRegisterWrap,
['-c', configPath], ['-c', configPath],
{ {
silent: false silent: this.silence
} }
); );

View file

@ -1,12 +1,9 @@
'use strict'; import assert from 'assert';
import _ from 'lodash';
const assert = require('assert'); import {notify} from '../../../src/lib/notify';
const _ = require('lodash');
const notify = require('../../../src/lib/notify').notify;
module.exports = function() {
const express = process.express;
export default function(express) {
const config = { const config = {
notify: { notify: {
method: 'POST', method: 'POST',
@ -18,9 +15,9 @@ module.exports = function() {
} }
}; };
describe('notifications', function () { describe('notifications', () => {
before(function () { beforeAll(function () {
express.post('/api/notify', function (req, res) { express.post('/api/notify', function (req, res) {
res.send(req.body); res.send(req.body);
}); });
@ -30,7 +27,7 @@ module.exports = function() {
}); });
}); });
it('notification should be send', function (done) { test('notification should be send', done => {
const metadata = { const metadata = {
name: "pkg-test" name: "pkg-test"
}; };
@ -46,7 +43,7 @@ module.exports = function() {
}); });
}); });
it('notification should be send single header', function (done) { test('notification should be send single header', done => {
const metadata = { const metadata = {
name: "pkg-test" name: "pkg-test"
}; };
@ -67,23 +64,25 @@ module.exports = function() {
}); });
}); });
it('notification should be send multiple notifications endpoints', function (done) { test(
const metadata = { 'notification should be send multiple notifications endpoints',
name: "pkg-test" done => {
}; const metadata = {
// let notificationsCounter = 0; name: "pkg-test"
};
// let notificationsCounter = 0;
const multipleNotificationsEndpoint = { const multipleNotificationsEndpoint = {
notify: [] notify: []
}; };
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
const notificationSettings = _.cloneDeep(config.notify); const notificationSettings = _.cloneDeep(config.notify);
// basically we allow al notifications // basically we allow al notifications
notificationSettings.packagePattern = /^pkg-test$/; notificationSettings.packagePattern = /^pkg-test$/;
// notificationSettings.packagePatternFlags = 'i'; // notificationSettings.packagePatternFlags = 'i';
multipleNotificationsEndpoint.notify.push(notificationSettings); multipleNotificationsEndpoint.notify.push(notificationSettings);
} }
notify(metadata, multipleNotificationsEndpoint).then(function (body) { notify(metadata, multipleNotificationsEndpoint).then(function (body) {
body.forEach(function(notification) { body.forEach(function(notification) {
@ -98,7 +97,7 @@ module.exports = function() {
}); });
}); });
it('notification should fails', function (done) { test('notification should fails', done => {
const metadata = { const metadata = {
name: "pkg-test" name: "pkg-test"
}; };
@ -115,4 +114,4 @@ module.exports = function() {
}); });
}); });
}; }

View file

@ -1,23 +1,21 @@
'use strict'; import assert from 'assert';
import async from 'async';
let assert = require('assert');
let async = require('async');
let _oksum = 0; let _oksum = 0;
const racePkg = require('../fixtures/package'); const racePkg = require('../fixtures/package');
module.exports = function () { export default function(server) {
let server = process.server;
describe('race', function () { describe('race', () => {
before(function () { beforeAll(function () {
return server.putPackage('race', racePkg('race')) return server.putPackage('race', racePkg('race'))
.status(201) .status(201)
.body_ok(/created new package/); .body_ok(/created new package/);
}); });
it('creating new package', function () {}); test('creating new package', () => {});
it('uploading 10 same versions', function (callback) { test('uploading 10 same versions', callback => {
let fns = []; let fns = [];
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
fns.push(function (cb_) { fns.push(function (cb_) {
@ -64,7 +62,7 @@ module.exports = function () {
}); });
}); });
it('uploading 10 diff versions', function (callback) { test('uploading 10 diff versions', callback => {
let fns = []; let fns = [];
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10; i++) {
(function (i) { (function (i) {
@ -107,7 +105,7 @@ module.exports = function () {
}); });
}); });
after('downloading package', function () { afterAll(function () {
return server.getPackage('race') return server.getPackage('race')
.status(200) .status(200)
.then(function (body) { .then(function (body) {
@ -115,5 +113,4 @@ module.exports = function () {
}); });
}); });
}); });
}; }

View file

@ -1,11 +1,6 @@
'use strict'; import assert from 'assert';
require('../lib/startup'); export default function(server2){
let assert = require('assert');
module.exports = function() {
const server2 = process.server2;
const requestAuthFail = (user, pass, message) => { const requestAuthFail = (user, pass, message) => {
return server2.auth(user, pass) return server2.auth(user, pass)
.status(409) .status(409)
@ -30,92 +25,91 @@ module.exports = function() {
}; };
describe('test default authentication', function() { describe('test default authentication', () => {
let authstr; let authstr;
before(function() { beforeAll(function() {
authstr = server2.authstr; authstr = server2.authstr;
}); });
it('should not authenticate with wrong password', function() { test('should not authenticate with wrong password', () => {
return requestAuthFail('authtest', 'wrongpass', 'this user already exists'); return requestAuthFail('authtest', 'wrongpass', 'this user already exists');
}); });
it('should be wrong password handled by plugin', function() { test('should be wrong password handled by plugin', () => {
return requestAuthFail('authtest2', 'wrongpass', 'registration is disabled'); return requestAuthFail('authtest2', 'wrongpass', 'registration is disabled');
}); });
it('should right password handled by plugin', function() { test('should right password handled by plugin', () => {
return requestAuthOk('authtest2', 'blahblah', /'authtest2'/); return requestAuthOk('authtest2', 'blahblah', /'authtest2'/);
}); });
after(function() { afterAll(function() {
server2.authstr = authstr; server2.authstr = authstr;
}); });
}); });
describe('test access authorization', function() { describe('test access authorization', () => {
let authstr; let authstr;
before(function() { beforeAll(function() {
authstr = server2.authstr; authstr = server2.authstr;
}); });
describe('access with user authtest', function() { describe('access with user authtest', () => {
before(function() { beforeAll(function() {
return server2.auth('authtest', 'test') return server2.auth('authtest', 'test')
.status(201) .status(201)
.body_ok(/'authtest'/); .body_ok(/'authtest'/);
}); });
it('access test-auth-allow', function() { test('access test-auth-allow', () => {
return server2.getPackage('test-auth-allow') return server2.getPackage('test-auth-allow')
.status(404) .status(404)
.body_error('no such package available'); .body_error('no such package available');
}); });
it('access test-auth-deny', function() { test('access test-auth-deny', () => {
return server2.getPackage('test-auth-deny') return server2.getPackage('test-auth-deny')
.status(403) .status(403)
.body_error('you\'re not allowed here'); .body_error('you\'re not allowed here');
}); });
it('access test-auth-regular', function() { test('access test-auth-regular', () => {
return server2.getPackage('test-auth-regular') return server2.getPackage('test-auth-regular')
.status(404) .status(404)
.body_error('no such package available'); .body_error('no such package available');
}); });
}); });
describe('access with user authtest2', function() { describe('access with user authtest2', () => {
before(function() { beforeAll(function() {
return server2.auth('authtest2', 'blahblah') return server2.auth('authtest2', 'blahblah')
.status(201) .status(201)
.body_ok(/'authtest2'/); .body_ok(/'authtest2'/);
}); });
it('access test-auth-allow', function() { test('access test-auth-allow', () => {
return server2.getPackage('test-auth-allow') return server2.getPackage('test-auth-allow')
.status(403) .status(403)
.body_error('i don\'t know anything about you'); .body_error('i don\'t know anything about you');
}); });
it('access test-auth-deny', function() { test('access test-auth-deny', () => {
return server2.getPackage('test-auth-deny') return server2.getPackage('test-auth-deny')
.status(403) .status(403)
.body_error('i don\'t know anything about you'); .body_error('i don\'t know anything about you');
}); });
it('access test-auth-regular', function() { test('access test-auth-regular', () => {
return server2.getPackage('test-auth-regular') return server2.getPackage('test-auth-regular')
.status(404) .status(404)
.body_error('no such package available'); .body_error('no such package available');
}); });
}); });
after(function() { afterAll(function() {
server2.authstr = authstr; server2.authstr = authstr;
}); });
}); });
}; }

View file

@ -6,8 +6,8 @@ require('../lib/startup');
module.exports = function () { module.exports = function () {
const server2 = process.server2; const server2 = process.server2;
describe('middlewares', function() { describe('middlewares', () => {
it('should serve the registered route', function() { test('should serve the registered route', () => {
return server2.request({ return server2.request({
uri: '/test/route', uri: '/test/route',
method: 'GET' method: 'GET'

View file

@ -1,17 +1,10 @@
/** import assert from 'assert';
* Created by jpicado on 7/24/17.
*/
'use strict';
const assert = require('assert'); export default function (server, server2) {
module.exports = function() {
let server = process.server;
let server2 = process.server2;
describe('should test readme', () => { describe('should test readme', () => {
before(function() { beforeAll(function() {
return server.request({ return server.request({
uri: '/readme-test', uri: '/readme-test',
headers: { headers: {
@ -22,7 +15,7 @@ module.exports = function() {
}).status(201); }).status(201);
}); });
it('add pkg', function() {}); test('add pkg', () => {});
describe('should check readme file', () => { describe('should check readme file', () => {
const matchReadme = (server) => { const matchReadme = (server) => {
@ -33,14 +26,14 @@ module.exports = function() {
}); });
}; };
it('server1 - readme', function() { test('server1 - readme', () => {
return matchReadme(server); return matchReadme(server);
}); });
it('server2 - readme', function() { test('server2 - readme', () => {
return matchReadme(server2); return matchReadme(server2);
}); });
}); });
}); });
}; }

View file

@ -1,6 +1,4 @@
'use strict'; import assert from 'assert';
let assert = require('assert');
const defaultPkg = { const defaultPkg = {
'name': 'testexp-incomplete', 'name': 'testexp-incomplete',
@ -24,21 +22,19 @@ const defaultPkg = {
}, },
}; };
module.exports = function () { export default function (server, express) {
const server = process.server;
const express = process.express;
const ddd = ['content-length', 'chunked']; const ddd = ['content-length', 'chunked'];
describe('test send incomplete packages', function () { describe('test send incomplete packages', () => {
before(function () { beforeAll(function () {
express.get('/testexp-incomplete', function (_, res) { express.get('/testexp-incomplete', function (_, res) {
res.send(defaultPkg); res.send(defaultPkg);
}); });
}); });
ddd.forEach(function (type) { ddd.forEach(function (type) {
it('should not store tarballs / ' + type, function (callback) { test('should not store tarballs / ' + type, callback => {
let called; let called;
express.get('/testexp-incomplete/-/' + type + '.tar.gz', function (_, response) { express.get('/testexp-incomplete/-/' + type + '.tar.gz', function (_, response) {
if (called) { if (called) {
@ -79,5 +75,4 @@ module.exports = function () {
}); });
}); });
}); });
}; }

View file

@ -1,15 +1,11 @@
'use strict'; import assert from 'assert';
import {readFile} from '../lib/test.utils';
const assert = require('assert'); const getBinary = () => readFile('../fixtures/binary');
const util = require('../lib/test.utils');
const getBinary = () => util.readFile('../fixtures/binary'); export default function (server, server2) {
module.exports = function () { test('testing anti-loop', () => {
let server = process.server;
let server2 = process.server2;
it('testing anti-loop', function () {
return server2.getPackage('testloop') return server2.getPackage('testloop')
.status(404) .status(404)
.body_error(/no such package/); .body_error(/no such package/);
@ -19,39 +15,39 @@ module.exports = function () {
let prefix = pkg + ': '; let prefix = pkg + ': ';
pkg = 'test' + pkg; pkg = 'test' + pkg;
describe(pkg, function () { describe(pkg, () => {
before(function () { beforeAll(function () {
return server.putPackage(pkg, require('../fixtures/package')(pkg)) return server.putPackage(pkg, require('../fixtures/package')(pkg))
.status(201) .status(201)
.body_ok(/created new package/); .body_ok(/created new package/);
}); });
it(prefix + 'creating new package', function () {}); test(prefix + 'creating new package', () => {});
describe(pkg, function () { describe(pkg, () => {
before(function () { beforeAll(function () {
return server.putVersion(pkg, '0.1.1', require('../fixtures/package')(pkg)) return server.putVersion(pkg, '0.1.1', require('../fixtures/package')(pkg))
.status(201) .status(201)
.body_ok(/published/); .body_ok(/published/);
}); });
it(prefix + 'uploading new package version', function () {}); test(prefix + 'uploading new package version', () => {});
it(prefix + 'uploading incomplete tarball', function () { test(prefix + 'uploading incomplete tarball', () => {
return server.putTarballIncomplete(pkg, pkg + '.bad', getBinary(), 3000); return server.putTarballIncomplete(pkg, pkg + '.bad', getBinary(), 3000);
}); });
describe('tarball', function () { describe('tarball', () => {
before(function () { beforeAll(function () {
return server.putTarball(pkg, pkg + '.file', getBinary()) return server.putTarball(pkg, pkg + '.file', getBinary())
.status(201) .status(201)
.body_ok(/.*/); .body_ok(/.*/);
}); });
it(prefix + 'uploading new tarball', function () { test(prefix + 'uploading new tarball', () => {
}); });
it(prefix + 'downloading tarball from server1', function () { test(prefix + 'downloading tarball from server1', () => {
return server.getTarball(pkg, pkg + '.file') return server.getTarball(pkg, pkg + '.file')
.status(200) .status(200)
.then(function (body) { .then(function (body) {

View file

@ -1,46 +1,40 @@
'use strict'; import assert from 'assert';
import crypto from 'crypto';
require('../lib/startup'); import {readFile} from '../lib/test.utils';
const assert = require('assert');
const crypto = require('crypto');
const util = require('../lib/test.utils');
function getBinary() { function getBinary() {
return util.readFile('../fixtures/binary'); return readFile('../fixtures/binary');
} }
module.exports = function() { export default function (server, server2) {
const server = process.server;
const server2 = process.server2;
it('trying to fetch non-existent package / null storage', function() { test('trying to fetch non-existent package / null storage', () => {
return server.getPackage('test-nullstorage-nonexist') return server.getPackage('test-nullstorage-nonexist')
.status(404) .status(404)
.body_error(/no such package/); .body_error(/no such package/);
}); });
describe('test-nullstorage on server2', function() { describe('test-nullstorage on server2', () => {
before(function() { beforeAll(function() {
return server2.addPackage('test-nullstorage2'); return server2.addPackage('test-nullstorage2');
}); });
it('creating new package - server2', function() {/* test for before() */}); test('creating new package - server2', () => {/* test for before() */});
it('downloading non-existent tarball', function() { test('downloading non-existent tarball', () => {
return server.getTarball('test-nullstorage2', 'blahblah') return server.getTarball('test-nullstorage2', 'blahblah')
.status(404) .status(404)
.body_error(/no such file/); .body_error(/no such file/);
}); });
describe('tarball', function() { describe('tarball', () => {
before(function() { beforeAll(function() {
return server2.putTarball('test-nullstorage2', 'blahblah', getBinary()) return server2.putTarball('test-nullstorage2', 'blahblah', getBinary())
.status(201) .status(201)
.body_ok(/.*/); .body_ok(/.*/);
}); });
before(function() { beforeAll(function() {
let pkg = require('../fixtures/package')('test-nullstorage2'); let pkg = require('../fixtures/package')('test-nullstorage2');
pkg.dist.shasum = crypto.createHash('sha1').update(getBinary()).digest('hex'); pkg.dist.shasum = crypto.createHash('sha1').update(getBinary()).digest('hex');
return server2.putVersion('test-nullstorage2', '0.0.1', pkg) return server2.putVersion('test-nullstorage2', '0.0.1', pkg)
@ -48,9 +42,9 @@ module.exports = function() {
.body_ok(/published/); .body_ok(/published/);
}); });
it('uploading new tarball', function() {/* test for before() */}); test('uploading new tarball', () => {/* test for before() */});
it('downloading newly created tarball', function() { test('downloading newly created tarball', () => {
return server.getTarball('test-nullstorage2', 'blahblah') return server.getTarball('test-nullstorage2', 'blahblah')
.status(200) .status(200)
.then(function(body) { .then(function(body) {
@ -58,7 +52,7 @@ module.exports = function() {
}); });
}); });
it('downloading newly created package', function() { test('downloading newly created package', () => {
return server.getPackage('test-nullstorage2') return server.getPackage('test-nullstorage2')
.status(200) .status(200)
.then(function(body) { .then(function(body) {
@ -70,5 +64,4 @@ module.exports = function() {
}); });
}); });
}); });
}; }

View file

@ -1,15 +1,11 @@
'use strict'; import assert from 'assert';
const assert = require('assert'); export default function(server, express) {
module.exports = function() { describe('test for unexpected client hangs', () => {
const server = process.server;
const express = process.express;
describe('test for unexpected client hangs', function() {
let on_tarball; let on_tarball;
before(function() { beforeAll(function() {
express.get('/testexp-racycrash', function(request, response) { express.get('/testexp-racycrash', function(request, response) {
response.send({ response.send({
'name': 'testexp-racycrash', 'name': 'testexp-racycrash',
@ -31,7 +27,7 @@ module.exports = function() {
}); });
}); });
it('should not crash on error if client disconnects', function(callback) { test('should not crash on error if client disconnects', callback => {
on_tarball = function(res) { on_tarball = function(res) {
res.header('content-length', 1e6); res.header('content-length', 1e6);
res.write('test test test\n'); res.write('test test test\n');
@ -57,7 +53,7 @@ module.exports = function() {
} }
}); });
it('should not store tarball', function() { test('should not store tarball', () => {
on_tarball = function(res) { on_tarball = function(res) {
res.socket.destroy(); res.socket.destroy();
}; };

View file

@ -1,28 +1,25 @@
'use strict'; import assert from 'assert';
const assert = require('assert'); export default function(server) {
module.exports = function () { describe('Security', () => {
let server = process.server; beforeAll(function () {
describe('Security', function () {
before(function () {
return server.addPackage('testpkg-sec'); return server.addPackage('testpkg-sec');
}); });
it('bad pkg #1', function () { test('bad pkg #1', () => {
return server.getPackage('package.json') return server.getPackage('package.json')
.status(403) .status(403)
.body_error(/invalid package/); .body_error(/invalid package/);
}); });
it('bad pkg #2', function () { test('bad pkg #2', () => {
return server.getPackage('__proto__') return server.getPackage('__proto__')
.status(403) .status(403)
.body_error(/invalid package/); .body_error(/invalid package/);
}); });
it('__proto__, connect stuff', function () { test('__proto__, connect stuff', () => {
return server.request({uri: '/testpkg-sec?__proto__=1'}) return server.request({uri: '/testpkg-sec?__proto__=1'})
.then(function (body) { .then(function (body) {
// test for NOT outputting stack trace // test for NOT outputting stack trace
@ -33,36 +30,36 @@ module.exports = function () {
}); });
}); });
it('do not return package.json as an attachment', function () { test('do not return package.json as an attachment', () => {
return server.request({uri: '/testpkg-sec/-/package.json'}) return server.request({uri: '/testpkg-sec/-/package.json'})
.status(403) .status(403)
.body_error(/invalid filename/); .body_error(/invalid filename/);
}); });
it('silly things - reading #1', function () { test('silly things - reading #1', () => {
return server.request({uri: '/testpkg-sec/-/../../../../../../../../etc/passwd'}) return server.request({uri: '/testpkg-sec/-/../../../../../../../../etc/passwd'})
.status(404); .status(404);
}); });
it('silly things - reading #2', function () { test('silly things - reading #2', () => {
return server.request({uri: '/testpkg-sec/-/%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd'}) return server.request({uri: '/testpkg-sec/-/%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd'})
.status(403) .status(403)
.body_error(/invalid filename/); .body_error(/invalid filename/);
}); });
it('silly things - writing #1', function () { test('silly things - writing #1', () => {
return server.putTarball('testpkg-sec', 'package.json', '{}') return server.putTarball('testpkg-sec', 'package.json', '{}')
.status(403) .status(403)
.body_error(/invalid filename/); .body_error(/invalid filename/);
}); });
it('silly things - writing #3', function () { test('silly things - writing #3', () => {
return server.putTarball('testpkg-sec', 'node_modules', '{}') return server.putTarball('testpkg-sec', 'node_modules', '{}')
.status(403) .status(403)
.body_error(/invalid filename/); .body_error(/invalid filename/);
}); });
it('silly things - writing #4', function () { test('silly things - writing #4', () => {
return server.putTarball('testpkg-sec', '../testpkg.tgz', '{}') return server.putTarball('testpkg-sec', '../testpkg.tgz', '{}')
.status(403) .status(403)
.body_error(/invalid filename/); .body_error(/invalid filename/);

View file

@ -1,17 +1,14 @@
'use strict'; import {readFile} from '../lib/test.utils';
const util = require('../lib/test.utils'); const readTags = () => readFile('../fixtures/publish.json5');
const readTags = () => util.readFile('../fixtures/publish.json5');
module.exports = function() { export default function(server) {
let server = process.server; test('add tag - 404', () => {
it('add tag - 404', function() {
return server.addTag('testpkg-tag', 'tagtagtag', '0.0.1').status(404).body_error(/no such package/); return server.addTag('testpkg-tag', 'tagtagtag', '0.0.1').status(404).body_error(/no such package/);
}); });
describe('addtag', function() { describe('addtag', () => {
before(function() { beforeAll(function() {
return server.putPackage('testpkg-tag', eval( return server.putPackage('testpkg-tag', eval(
'(' + readTags() '(' + readTags()
.toString('utf8') .toString('utf8')
@ -21,26 +18,26 @@ module.exports = function() {
)).status(201); )).status(201);
}); });
it('add testpkg-tag', function() { test('add testpkg-tag', () => {
// TODO: ? // TODO: ?
}); });
it('add tag - bad ver', function() { test('add tag - bad ver', () => {
return server.addTag('testpkg-tag', 'tagtagtag', '0.0.1-x') return server.addTag('testpkg-tag', 'tagtagtag', '0.0.1-x')
.status(404) .status(404)
.body_error(/version doesn't exist/); .body_error(/version doesn't exist/);
}); });
it('add tag - bad tag', function() { test('add tag - bad tag', () => {
return server.addTag('testpkg-tag', 'tag/tag/tag', '0.0.1-x') return server.addTag('testpkg-tag', 'tag/tag/tag', '0.0.1-x')
.status(403) .status(403)
.body_error(/invalid tag/); .body_error(/invalid tag/);
}); });
it('add tag - good', function() { test('add tag - good', () => {
return server.addTag('testpkg-tag', 'tagtagtag', '0.0.1') return server.addTag('testpkg-tag', 'tagtagtag', '0.0.1')
.status(201) .status(201)
.body_ok(/tagged/); .body_ok(/tagged/);
}); });
}); });
}; }

View file

@ -1,16 +1,10 @@
'use strict'; import assert from 'assert';
import {generateSha} from '../lib/test.utils';
const assert = require('assert');
const utils = require ('../lib/test.utils');
module.exports = function() {
let server = process.server;
let server2 = process.server2;
let express = process.express;
export default function(server, server2, express) {
describe('should test preserve tags when publishing something', () => { describe('should test preserve tags when publishing something', () => {
before(function() { beforeAll(function() {
return server.request({ return server.request({
uri: '/testpkg-preserve', uri: '/testpkg-preserve',
headers: { headers: {
@ -21,7 +15,7 @@ module.exports = function() {
}).status(201); }).status(201);
}); });
it('add new package', function() {}); test('add new package', () => {});
describe('should check sha integrity', () => { describe('should check sha integrity', () => {
@ -30,15 +24,15 @@ module.exports = function() {
.status(200) .status(200)
.then(function(body) { .then(function(body) {
// not real sha due to utf8 conversion // not real sha due to utf8 conversion
assert.strictEqual(utils.generateSha(body), '8ee7331cbc641581b1a8cecd9d38d744a8feb863'); assert.strictEqual(generateSha(body), '8ee7331cbc641581b1a8cecd9d38d744a8feb863');
}); });
}; };
it('server1 should match with sha key from published package', () => { test('server1 should match with sha key from published package', () => {
return matchTarBallSha(server); return matchTarBallSha(server);
}); });
it('server2 should match with sha key from published packagel', () => { test('server2 should match with sha key from published packagel', () => {
matchTarBallSha(server2); matchTarBallSha(server2);
}); });
}); });
@ -55,16 +49,16 @@ module.exports = function() {
}); });
}; };
it('server1 should be able to match latest dist-tags correctly', () => { test('server1 should be able to match latest dist-tags correctly', () => {
return matchDisTags(server, '55551'); return matchDisTags(server, '55551');
}); });
it('server2 should be able to match latest dist-tags correctly', function() { test('server2 should be able to match latest dist-tags correctly', () => {
return matchDisTags(server2, '55552'); return matchDisTags(server2, '55552');
}); });
}); });
describe('should test search', function() { describe('should test search', () => {
const check = (obj) => { const check = (obj) => {
obj['testpkg-preserve'].time.modified = '2014-10-02T07:07:51.000Z'; obj['testpkg-preserve'].time.modified = '2014-10-02T07:07:51.000Z';
assert.deepEqual(obj['testpkg-preserve'], assert.deepEqual(obj['testpkg-preserve'],
@ -92,19 +86,19 @@ module.exports = function() {
}); });
}; };
before(function() { beforeAll(function() {
express.get('/-/all', (req, res) => { express.get('/-/all', (req, res) => {
res.send({}); res.send({});
}); });
}); });
it('server1 - search', () => { test('server1 - search', () => {
return server.request({uri: '/-/all'}) return server.request({uri: '/-/all'})
.status(200) .status(200)
.then(check); .then(check);
}); });
it('server2 - search', () => { test('server2 - search', () => {
return server2.request({uri: '/-/all'}) return server2.request({uri: '/-/all'})
.status(200) .status(200)
.then(check); .then(check);
@ -112,4 +106,4 @@ module.exports = function() {
}); });
}); });
}; }

View file

@ -1,30 +1,28 @@
'use strict';
const assert = require('assert'); import _ from 'lodash';
const _ = require('lodash'); import assert from 'assert';
const util = require('../lib/test.utils'); import {readFile} from '../lib/test.utils';
const readTags = () => util.readFile('../fixtures/tags.json');
module.exports = function() { const readTags = () => readFile('../fixtures/tags.json');
let server = process.server;
let express = process.express;
it('tags - testing for 404', function() { export default function(server, express) {
test('tags - testing for 404', () => {
return server.getPackage('testexp_tags') return server.getPackage('testexp_tags')
// shouldn't exist yet // shouldn't exist yet
.status(404) .status(404)
.body_error(/no such package/); .body_error(/no such package/);
}); });
describe('tags', function() { describe('tags', () => {
before(function() { beforeAll(function() {
express.get('/testexp_tags', function(req, res) { express.get('/testexp_tags', function(req, res) {
let f = readTags().toString().replace(/__NAME__/g, 'testexp_tags'); let f = readTags().toString().replace(/__NAME__/g, 'testexp_tags');
res.send(JSON.parse(f)); res.send(JSON.parse(f));
}); });
}); });
it('fetching package again', function() { test('fetching package again', () => {
return server.getPackage('testexp_tags') return server.getPackage('testexp_tags')
.status(200) .status(200)
.then(function(body) { .then(function(body) {
@ -38,7 +36,7 @@ module.exports = function() {
const versions = ['0.1.1alpha', '0.1.1-alpha', '0000.00001.001-alpha']; const versions = ['0.1.1alpha', '0.1.1-alpha', '0000.00001.001-alpha'];
versions.forEach(function(ver) { versions.forEach(function(ver) {
it('fetching '+ver, function() { test('fetching '+ver, () => {
return server.request({uri: '/testexp_tags/'+ver}) return server.request({uri: '/testexp_tags/'+ver})
.status(200) .status(200)
.then(function(body) { .then(function(body) {
@ -48,9 +46,9 @@ module.exports = function() {
}); });
}); });
describe('dist-tags methods', function() { describe('dist-tags methods', () => {
before(function() { beforeAll(function() {
express.get('/testexp_tags2', function(req, res) { express.get('/testexp_tags2', function(req, res) {
let f = readTags().toString().replace(/__NAME__/g, 'testexp_tags2'); let f = readTags().toString().replace(/__NAME__/g, 'testexp_tags2');
@ -60,11 +58,11 @@ module.exports = function() {
}); });
// populate cache // populate cache
before(function() { beforeAll(function() {
return server.getPackage('testexp_tags2').status(200); return server.getPackage('testexp_tags2').status(200);
}); });
it('fetching tags', function() { test('fetching tags', () => {
return server.request({ return server.request({
method: 'GET', method: 'GET',
uri: '/-/package/testexp_tags2/dist-tags', uri: '/-/package/testexp_tags2/dist-tags',
@ -77,7 +75,7 @@ module.exports = function() {
}); });
}); });
it('merging tags', function() { test('merging tags', () => {
return server.request({ return server.request({
method: 'POST', method: 'POST',
uri: '/-/package/testexp_tags2/dist-tags', uri: '/-/package/testexp_tags2/dist-tags',
@ -101,7 +99,7 @@ module.exports = function() {
}); });
}); });
it('should add a dist-tag called foo', function() { test('should add a dist-tag called foo', () => {
return server.request({ return server.request({
method: 'PUT', method: 'PUT',
uri: '/-/package/testexp_tags2/dist-tags/foo', uri: '/-/package/testexp_tags2/dist-tags/foo',
@ -122,7 +120,7 @@ module.exports = function() {
}); });
}); });
it('should remove a dis-tag called quux', function() { test('should remove a dis-tag called quux', () => {
return server.request({ return server.request({
method: 'DELETE', method: 'DELETE',
uri: '/-/package/testexp_tags2/dist-tags/latest', uri: '/-/package/testexp_tags2/dist-tags/latest',
@ -142,7 +140,7 @@ module.exports = function() {
}); });
}); });
it('should remove a dis-tag called foo', function() { test('should remove a dis-tag called foo', () => {
return server.request({ return server.request({
method: 'DELETE', method: 'DELETE',
uri: '/-/package/testexp_tags2/dist-tags/foo', uri: '/-/package/testexp_tags2/dist-tags/foo',
@ -155,7 +153,7 @@ module.exports = function() {
latest: '1.1.0', latest: '1.1.0',
"quux": "0.1.0" "quux": "0.1.0"
}; };
assert.deepEqual(body, expected); assert.deepEqual(body, expected);
}); });
}); });

View file

@ -1,14 +1,12 @@
'use strict'; import assert from 'assert';
import ProxyStorage from '../../src/lib/up-storage';
const uplinkStorage = require('../../src/lib/up-storage');
const assert = require('assert');
function createUplink(config) { function createUplink(config) {
const defaultConfig = { const defaultConfig = {
url: 'https://registry.npmjs.org/' url: 'https://registry.npmjs.org/'
}; };
let mergeConfig = Object.assign({}, defaultConfig, config); let mergeConfig = Object.assign({}, defaultConfig, config);
return new uplinkStorage(mergeConfig, {}); return new ProxyStorage(mergeConfig, {});
} }
function setHeaders(config, headers) { function setHeaders(config, headers) {
@ -20,11 +18,11 @@ function setHeaders(config, headers) {
}); });
} }
module.exports = function () { export default function () {
describe('uplink auth test', function () { describe('uplink auth test', () => {
it('if set headers empty should return default headers', function () { test('if set headers empty should return default headers', () => {
const headers = setHeaders(); const headers = setHeaders();
const keys = Object.keys(headers); const keys = Object.keys(headers);
const keysExpected = ['Accept', 'Accept-Encoding', 'User-Agent']; const keysExpected = ['Accept', 'Accept-Encoding', 'User-Agent'];
@ -33,7 +31,7 @@ module.exports = function () {
assert.equal(keys.length, 3); assert.equal(keys.length, 3);
}); });
it('if assigns value invalid to attribute auth', function () { test('if assigns value invalid to attribute auth', () => {
const fnError = function () { const fnError = function () {
setHeaders({ setHeaders({
auth: '' auth: ''
@ -43,7 +41,7 @@ module.exports = function () {
assert.throws(fnError, 'Auth invalid'); assert.throws(fnError, 'Auth invalid');
}); });
it('if assigns the header authorization', function () { test('if assigns the header authorization', () => {
const headers = setHeaders({}, { const headers = setHeaders({}, {
'authorization': 'basic Zm9vX2Jhcg==' 'authorization': 'basic Zm9vX2Jhcg=='
}); });
@ -52,20 +50,23 @@ module.exports = function () {
assert.equal(headers['authorization'], 'basic Zm9vX2Jhcg=='); assert.equal(headers['authorization'], 'basic Zm9vX2Jhcg==');
}); });
it('if assigns headers authorization and token the header precedes', function () { test(
const headers = setHeaders({ 'if assigns headers authorization and token the header precedes',
auth: { () => {
type: 'bearer', const headers = setHeaders({
token: 'tokenBearer' auth: {
} type: 'bearer',
}, { token: 'tokenBearer'
'authorization': 'basic tokenBasic' }
}); }, {
'authorization': 'basic tokenBasic'
});
assert.equal(headers['authorization'], 'basic tokenBasic'); assert.equal(headers['authorization'], 'basic tokenBasic');
}); }
);
it('set type auth basic', function () { test('set type auth basic', () => {
const headers = setHeaders({ const headers = setHeaders({
auth: { auth: {
type: 'basic', type: 'basic',
@ -77,7 +78,7 @@ module.exports = function () {
assert.equal(headers['authorization'], 'Basic Zm9vX2Jhcg=='); assert.equal(headers['authorization'], 'Basic Zm9vX2Jhcg==');
}); });
it('set type auth bearer', function () { test('set type auth bearer', () => {
const headers = setHeaders({ const headers = setHeaders({
auth: { auth: {
type: 'bearer', type: 'bearer',
@ -89,8 +90,8 @@ module.exports = function () {
assert.equal(headers['authorization'], 'Bearer Zm9vX2Jhcf==='); assert.equal(headers['authorization'], 'Bearer Zm9vX2Jhcf===');
}); });
it('set auth type invalid', function () { test('set auth type invalid', () => {
const fnError = function() { const fnError = function() {
setHeaders({ setHeaders({
auth: { auth: {
type: 'null', type: 'null',
@ -98,11 +99,11 @@ module.exports = function () {
} }
}) })
}; };
assert.throws(fnError, `Auth type 'null' not allowed`); assert.throws(fnError, `Auth type 'null' not allowed`);
}); });
it('set auth with NPM_TOKEN', function () { test('set auth with NPM_TOKEN', () => {
process.env.NPM_TOKEN = 'myToken'; process.env.NPM_TOKEN = 'myToken';
const headers = setHeaders({ const headers = setHeaders({
auth: { auth: {
@ -114,7 +115,7 @@ module.exports = function () {
delete process.env.NPM_TOKEN; delete process.env.NPM_TOKEN;
}); });
it('set auth with token name and assigns in env', function () { test('set auth with token name and assigns in env', () => {
process.env.NPM_TOKEN_TEST = 'myTokenTest'; process.env.NPM_TOKEN_TEST = 'myTokenTest';
const headers = setHeaders({ const headers = setHeaders({
auth: { auth: {
@ -128,7 +129,7 @@ module.exports = function () {
}); });
it('if token not set', function () { test('if token not set', () => {
const fnError = function() { const fnError = function() {
setHeaders({ setHeaders({
auth: { auth: {
@ -140,5 +141,4 @@ module.exports = function () {
assert.throws(fnError, 'Token is required'); assert.throws(fnError, 'Token is required');
}); });
}); });
}; }

View file

@ -1,14 +1,11 @@
'use strict'; import fs from 'fs';
import path from 'path';
const fs = require('fs'); import assert from 'assert';
const path = require('path'); import crypto from 'crypto';
const assert = require('assert'); import {readFile} from './lib/test.utils';
const crypto = require('crypto');
const util = require('./lib/test.utils');
function getBinary() { function getBinary() {
return util.readFile('../fixtures/binary'); return readFile('../fixtures/binary');
} }
const STORAGE = 'store/test-storage3'; const STORAGE = 'store/test-storage3';
@ -20,26 +17,23 @@ function isCached(pkgName, tarballName) {
return fs.existsSync(path.join(__dirname, STORAGE, pkgName, tarballName)); return fs.existsSync(path.join(__dirname, STORAGE, pkgName, tarballName));
} }
module.exports = function() { export default function (server, server2, server3) {
const server = process.server;
const server2 = process.server2;
const server3 = process.server3;
describe('storage tarball cache test', function() { describe('storage tarball cache test', () => {
//more info #131 //more info #131
before(function () { beforeAll(function () {
return server.addPackage(PKG_GH131); return server.addPackage(PKG_GH131);
}); });
before(function () { beforeAll(function () {
return server.putTarball(PKG_GH131, TARBALL, getBinary()) return server.putTarball(PKG_GH131, TARBALL, getBinary())
.status(201) .status(201)
.body_ok(/.*/); .body_ok(/.*/);
}); });
before(function () { beforeAll(function () {
const pkg = require('./fixtures/package')(PKG_GH131); const pkg = require('./fixtures/package')(PKG_GH131);
pkg.dist.shasum = crypto.createHash('sha1').update(getBinary()).digest('hex'); pkg.dist.shasum = crypto.createHash('sha1').update(getBinary()).digest('hex');
@ -48,31 +42,31 @@ module.exports = function() {
.body_ok(/published/); .body_ok(/published/);
}); });
before(function () { beforeAll(function () {
return server3.getPackage(PKG_GH131) return server3.getPackage(PKG_GH131)
.status(200); .status(200);
}); });
before(function () { beforeAll(function () {
return server3.getTarball(PKG_GH131, TARBALL) return server3.getTarball(PKG_GH131, TARBALL)
.status(200); .status(200);
}); });
it('should be caching packages from uplink server1', function () { test('should be caching packages from uplink server1', () => {
assert.equal(isCached(PKG_GH131, TARBALL), true); assert.equal(isCached(PKG_GH131, TARBALL), true);
}); });
before(function () { beforeAll(function () {
return server2.addPackage(PKG_GH1312); return server2.addPackage(PKG_GH1312);
}); });
before(function () { beforeAll(function () {
return server2.putTarball(PKG_GH1312, TARBALL, getBinary()) return server2.putTarball(PKG_GH1312, TARBALL, getBinary())
.status(201) .status(201)
.body_ok(/.*/); .body_ok(/.*/);
}); });
before(function () { beforeAll(function () {
const pkg = require('./fixtures/package')(PKG_GH1312); const pkg = require('./fixtures/package')(PKG_GH1312);
pkg.dist.shasum = crypto.createHash('sha1').update(getBinary()).digest('hex'); pkg.dist.shasum = crypto.createHash('sha1').update(getBinary()).digest('hex');
@ -81,20 +75,19 @@ module.exports = function() {
.body_ok(/published/); .body_ok(/published/);
}); });
before(function () { beforeAll(function () {
return server3.getPackage(PKG_GH1312) return server3.getPackage(PKG_GH1312)
.status(200); .status(200);
}); });
before(function () { beforeAll(function () {
return server3.getTarball(PKG_GH1312, TARBALL) return server3.getTarball(PKG_GH1312, TARBALL)
.status(200); .status(200);
}); });
it('must not be caching packages from uplink server2', function () { test('must not be caching packages from uplink server2', () => {
assert.equal(isCached(PKG_GH1312, TARBALL), false); assert.equal(isCached(PKG_GH1312, TARBALL), false);
}); });
}); });
}; }