1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-08 23:25:51 +01:00

refactor: naming clean up, relocation, organize by category

This commit is contained in:
Juan Picado @jotadeveloper 2017-08-06 21:54:15 +02:00
parent b804e96f4a
commit 8b93b579d3
No known key found for this signature in database
GPG Key ID: 18AC54485952D158
27 changed files with 520 additions and 491 deletions

@ -1,13 +1,13 @@
'use strict';
const Server = require('./lib/server');
const Server = require('../lib/server');
const fs = require('fs');
const path = require('path');
module.exports = function() {
const server = new Server('http://localhost:55551/');
describe('adduser', function() {
describe('npm adduser', function() {
const user = String(Math.random());
const pass = String(Math.random());
before(function() {
@ -16,7 +16,7 @@ module.exports = function() {
.body_ok(/user .* created/);
});
it('creating new user', function() {});
it('should create new user', function() {});
it('should log in', function() {
return server.auth(user, pass)
@ -31,15 +31,17 @@ module.exports = function() {
});
});
describe('adduser created with htpasswd', function() {
let user = 'preexisting';
let pass = 'preexisting';
describe('should adduser created with htpasswd', function() {
const user = 'preexisting';
const pass = 'preexisting';
before(function() {
return fs.appendFileSync(
path.join(__dirname, 'store/test-storage', '.htpasswd'),
path.join(__dirname, '../store/test-storage', '.htpasswd'),
'preexisting:$apr1$4YSboUa9$yVKjE7.PxIOuK3M4D7VjX.'
);
});
it('should log in', function() {
return server.auth(user, pass)
.status(201)

@ -3,173 +3,175 @@
const assert = require('assert');
const crypto = require('crypto');
function readfile(folderPath) {
return require('fs').readFileSync(__dirname + '/' + folderPath);
}
function getPackage(name) {
return require('./lib/package')(name);
return require('./fixtures/package')(name);
}
function createHash() {
return crypto.createHash('sha1');
}
module.exports = function() {
module.exports = function () {
let server = process.server;
let server2 = process.server2;
describe('basic test endpoints', function() {
describe('basic test endpoints', function () {
require('./basic/whoIam')(server);
require('./basic/ping')(server);
describe('handling packages', function() {
describe('handling packages', function () {
before(function() {
before(function () {
return server.addPackage('testpkg');
});
before(function() {
before(function () {
return server.addPackage('testpkg-single-tarball');
});
it('creating new package', function() {/* test for before() */});
it('creating new package', function () {/* test for before() */
});
it('downloading non-existent tarball', function() {
it('downloading non-existent tarball', function () {
return server.getTarball('testpkg', 'blahblah').status(404).body_error(/no such file/);
});
it('uploading incomplete tarball', function() {
it('uploading incomplete tarball', function () {
return server.putTarballIncomplete('testpkg', 'blahblah1', readfile('fixtures/binary'), 3000);
});
describe('publishing package', function() {
describe('publishing package', function () {
before(function() {
before(function () {
return server.putTarball('testpkg', 'blahblah', readfile('fixtures/binary'))
.status(201)
.body_ok(/.*/);
.status(201)
.body_ok(/.*/);
});
before(function() {
before(function () {
return server.putTarball('testpkg-single-tarball', 'single', readfile('fixtures/binary'))
.status(201)
.body_ok(/.*/);
});
after(function() {
after(function () {
return server.removeTarball('testpkg').status(201);
});
it('remove a tarball', function() {
it('remove a tarball', function () {
/* test for before() */
});
it('uploading new tarball', function() {
it('uploading new tarball', function () {
/* test for after() */
});
it('remove non existing tarball', function() {
it('remove non existing tarball', function () {
return server.removeTarball('testpkg404').status(404);
});
it('remove non existing single tarball', function() {
it('remove non existing single tarball', function () {
return server.removeSingleTarball('', 'fakeFile').status(404);
});
// testexp-incomplete
it('remove existing single tarball', function() {
it('remove existing single tarball', function () {
return server.removeSingleTarball('testpkg-single-tarball', 'single').status(201);
});
// testexp-incomplete
it('downloading newly created tarball', function() {
it('downloading newly created tarball', function () {
return server.getTarball('testpkg', 'blahblah')
.status(200)
.then(function(body) {
assert.deepEqual(body, readfile('fixtures/binary'));
});
.status(200)
.then(function (body) {
assert.deepEqual(body, readfile('fixtures/binary'));
});
});
it('uploading new package version (bad sha)', function() {
it('uploading new package version (bad sha)', function () {
let pkg = getPackage('testpkg');
pkg.dist.shasum = createHash().update('fake').digest('hex');
return server.putVersion('testpkg', '0.0.1', pkg)
.status(400)
.body_error(/shasum error/);
.status(400)
.body_error(/shasum error/);
});
describe('publishing version', function() {
describe('publishing version', function () {
before(function() {
before(function () {
const pkg = getPackage('testpkg');
pkg.dist.shasum = createHash().update(readfile('fixtures/binary')).digest('hex');
return server.putVersion('testpkg', '0.0.1', pkg)
.status(201)
.body_ok(/published/);
.status(201)
.body_ok(/published/);
});
it('uploading new package version', function() {
it('uploading new package version', function () {
/* test for before() */
});
it('downloading newly created package', function() {
it('downloading newly created package', function () {
return server.getPackage('testpkg')
.status(200)
.then(function(body) {
assert.equal(body.name, 'testpkg');
assert.equal(body.versions['0.0.1'].name, 'testpkg');
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55551/testpkg/-/blahblah');
assert.deepEqual(body['dist-tags'], {
latest: '0.0.1'
});
});
.status(200)
.then(function (body) {
assert.equal(body.name, 'testpkg');
assert.equal(body.versions['0.0.1'].name, 'testpkg');
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55551/testpkg/-/blahblah');
assert.deepEqual(body['dist-tags'], {
latest: '0.0.1'
});
});
});
it('downloading package via server2', function() {
it('downloading package via server2', function () {
return server2.getPackage('testpkg')
.status(200)
.then(function(body) {
assert.equal(body.name, 'testpkg');
assert.equal(body.versions['0.0.1'].name, 'testpkg');
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55552/testpkg/-/blahblah');
assert.deepEqual(body['dist-tags'], {
latest: '0.0.1'
});
});
.status(200)
.then(function (body) {
assert.equal(body.name, 'testpkg');
assert.equal(body.versions['0.0.1'].name, 'testpkg');
assert.equal(body.versions['0.0.1'].dist.tarball, 'http://localhost:55552/testpkg/-/blahblah');
assert.deepEqual(body['dist-tags'], {
latest: '0.0.1'
});
});
});
});
});
});
describe('handle failures on endpoints', function() {
describe('handle failures on endpoints', function () {
it('should fails trying to fetch non-existent package', function() {
it('should fails trying to fetch non-existent package', function () {
return server.getPackage('testpkg').status(404).body_error(/no such package/);
});
it('should fails on publish a version for non existing package', function() {
it('should fails on publish a version for non existing package', function () {
return server.putVersion('testpxg', '0.0.1', getPackage('testpxg'))
.status(404)
.body_error(/no such package/);
.status(404)
.body_error(/no such package/);
});
it('should be a package not found', function() {
it('should be a package not found', function () {
return server.putTarball('nonExistingPackage', 'blahblah', readfile('fixtures/binary'))
.status(404)
.body_error(/no such/);
.status(404)
.body_error(/no such/);
});
it('should fails on publish package in a bad uplink', function() {
it('should fails on publish package in a bad uplink', function () {
return server.putPackage('baduplink', getPackage('baduplink'))
.status(503)
.body_error(/one of the uplinks is down, refuse to publish/);
.status(503)
.body_error(/one of the uplinks is down, refuse to publish/);
});
});

@ -1,7 +1,5 @@
'use strict';
module.exports = Plugin;
function Plugin(config) {
let self = Object.create(Plugin.prototype);
self._config = config;
@ -23,3 +21,5 @@ Plugin.prototype.authenticate = function(user, password, cb) {
}
return cb(null, [user]);
};
module.exports = Plugin;

@ -8,8 +8,8 @@ function readfile(x) {
}
module.exports = function() {
let server = process.server;
let server2 = process.server2;
const server = process.server;
const server2 = process.server2;
it('downloading non-existent tarball #1 / srv2', function() {
return server2.getTarball('testpkg-gh29', 'blahblah')
@ -19,7 +19,7 @@ module.exports = function() {
describe('pkg-gh29', function() {
before(function() {
return server.putPackage('testpkg-gh29', require('./lib/package')('testpkg-gh29'))
return server.putPackage('testpkg-gh29', require('./fixtures/package')('testpkg-gh29'))
.status(201)
.body_ok(/created new package/);
});
@ -43,7 +43,8 @@ module.exports = function() {
describe('pkg version', function() {
before(function() {
let pkg = require('./lib/package')('testpkg-gh29');
const pkg = require('./fixtures/package')('testpkg-gh29');
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex');
return server.putVersion('testpkg-gh29', '0.0.1', pkg)
.status(201)

@ -1,71 +0,0 @@
'use strict';
let assert = require('assert');
module.exports = function() {
let server = process.server;
let express = process.express;
describe('Incomplete', function() {
before(function() {
express.get('/testexp-incomplete', function(_, res) {
res.send({
'name': 'testexp-incomplete',
'versions': {
'0.1.0': {
'name': 'testexp_tags',
'version': '0.1.0',
'dist': {
'shasum': 'fake',
'tarball': 'http://localhost:55550/testexp-incomplete/-/content-length.tar.gz',
},
},
'0.1.1': {
'name': 'testexp_tags',
'version': '0.1.1',
'dist': {
'shasum': 'fake',
'tarball': 'http://localhost:55550/testexp-incomplete/-/chunked.tar.gz',
},
},
},
});
});
})
;['content-length', 'chunked'].forEach(function(type) {
it('should not store tarballs / ' + type, function(_cb) {
let called;
express.get('/testexp-incomplete/-/'+type+'.tar.gz', function(_, res) {
if (called) return res.socket.destroy();
called = true;
if (type !== 'chunked') res.header('content-length', 1e6);
res.write('test test test\n');
setTimeout(function() {
res.socket.write('200\nsss\n');
res.socket.destroy();
cb();
}, 10);
});
server.request({uri: '/testexp-incomplete/-/'+type+'.tar.gz'})
.status(200)
.response(function(res) {
if (type !== 'chunked') assert.equal(res.headers['content-length'], 1e6);
})
.then(function(body) {
assert(body.match(/test test test/));
});
function cb() {
server.request({uri: '/testexp-incomplete/-/'+type+'.tar.gz'})
.body_error('internal server error')
.then(function() {
_cb();
});
}
});
});
});
};

@ -59,24 +59,24 @@ describe('Create registry servers', function() {
require('./package/access')();
require('./basic')();
require('./gh29')();
require('./tags')();
require('./gzip')();
require('./incomplete')();
require('./mirror')();
require('./tags/preserve_tags')();
require('./tags/tags')();
require('./package/gzip.spec')();
require('./sanity/incomplete')();
require('./sanity/mirror')();
require('./tags/preserve_tags.spec')();
require('./readme/readme.spec')();
require('./nullstorage')();
require('./race')();
require('./racycrash')();
require('./sanity/nullstorage')();
require('./performance/race')();
require('./sanity/racycrash')();
require('./package/scoped.spec')();
require('./security')();
require('./adduser')();
require('./sanity/security')();
require('./adduser/adduser')();
require('./adduser/logout')();
require('./addtag')();
require('./plugins')();
require('./tags/addtag.spec')();
require('./plugins/auth.spec')();
require('./notifications/notify')();
// requires packages published to server1/server2
require('./uplink.cache')();
require('./uplink.cache.spec')();
after(function(done) {
const check = (server) => {

@ -173,7 +173,7 @@ class Server {
}
addPackage(name) {
return this.putPackage(name, require('./package')(name))
return this.putPackage(name, require('../fixtures/package')(name))
.status(201)
.body_ok('created new package');
}

@ -1,66 +0,0 @@
'use strict';
let assert = require('assert');
function readfile(x) {
return require('fs').readFileSync(__dirname + '/' + x);
}
module.exports = function() {
let server = process.server;
let server2 = process.server2;
it('testing anti-loop', function() {
return server2.getPackage('testloop')
.status(404)
.body_error(/no such package/);
})
;['fwd'].forEach(function(pkg) {
let prefix = pkg + ': ';
pkg = 'test' + pkg;
describe(pkg, function() {
before(function() {
return server.putPackage(pkg, require('./lib/package')(pkg))
.status(201)
.body_ok(/created new package/);
});
it(prefix+'creating new package', function() {});
describe(pkg, function() {
before(function() {
return server.putVersion(pkg, '0.1.1', require('./lib/package')(pkg))
.status(201)
.body_ok(/published/);
});
it(prefix+'uploading new package version', function() {});
it(prefix+'uploading incomplete tarball', function() {
return server.putTarballIncomplete(pkg, pkg+'.bad', readfile('fixtures/binary'), 3000);
});
describe('tarball', function() {
before(function() {
return server.putTarball(pkg, pkg+'.file', readfile('fixtures/binary'))
.status(201)
.body_ok(/.*/);
});
it(prefix+'uploading new tarball', function() {});
it(prefix+'downloading tarball from server1', function() {
return server.getTarball(pkg, pkg+'.file')
.status(200)
.then(function(body) {
assert.deepEqual(body, readfile('fixtures/binary'));
});
});
});
});
});
});
};

@ -44,7 +44,7 @@ module.exports = function() {
function checkPublish(auth, pkg, ok) {
it(`${(ok ? 'allows' : 'forbids')} publish ${auth} to ${pkg}`, function() {
server.authstr = auth ? buildToken(auth) : undefined;
const req = server.putPackage(pkg, require('../lib/package')(pkg));
const req = server.putPackage(pkg, require('../fixtures/package')(pkg));
if (ok) {
return req.status(404).body_error(/this package cannot be added/);
} else {

@ -1,22 +1,20 @@
'use strict';
require('./lib/startup');
require('../lib/startup');
let assert = require('assert');
function readfile(x) {
return require('fs').readFileSync(__dirname + '/' + x);
}
const assert = require('assert');
const zlib = require('zlib');
const utils = require('../lib/test.utils');
module.exports = function() {
let server = process.server;
let express = process.express;
describe('testexp_gzip', function() {
describe('test gzip support', function() {
before(function() {
express.get('/testexp_gzip', function(req, res) {
let x = eval(
'(' + readfile('fixtures/publish.json5')
const pkg = eval(
'(' + utils.readFile('../fixtures/publish.json5')
.toString('utf8')
.replace(/__NAME__/g, 'testexp_gzip')
.replace(/__VERSION__/g, '0.0.1')
@ -24,16 +22,16 @@ module.exports = function() {
);
// overcoming compress threshold
x.versions['0.0.2'] = x.versions['0.0.1'];
x.versions['0.0.3'] = x.versions['0.0.1'];
x.versions['0.0.4'] = x.versions['0.0.1'];
x.versions['0.0.5'] = x.versions['0.0.1'];
x.versions['0.0.6'] = x.versions['0.0.1'];
x.versions['0.0.7'] = x.versions['0.0.1'];
x.versions['0.0.8'] = x.versions['0.0.1'];
x.versions['0.0.9'] = x.versions['0.0.1'];
pkg.versions['0.0.2'] = pkg.versions['0.0.1'];
pkg.versions['0.0.3'] = pkg.versions['0.0.1'];
pkg.versions['0.0.4'] = pkg.versions['0.0.1'];
pkg.versions['0.0.5'] = pkg.versions['0.0.1'];
pkg.versions['0.0.6'] = pkg.versions['0.0.1'];
pkg.versions['0.0.7'] = pkg.versions['0.0.1'];
pkg.versions['0.0.8'] = pkg.versions['0.0.1'];
pkg.versions['0.0.9'] = pkg.versions['0.0.1'];
require('zlib').gzip(JSON.stringify(x), function(err, buf) {
zlib.gzip(JSON.stringify(pkg), function(err, buf) {
assert.equal(err, null);
assert.equal(req.headers['accept-encoding'], 'gzip');
res.header('content-encoding', 'gzip');
@ -49,8 +47,7 @@ module.exports = function() {
});
it('should not fail on bad gzip', function() {
return server.getPackage('testexp_baddata')
.status(404);
return server.getPackage('testexp_baddata').status(404);
});
it('should understand gzipped data from uplink', function() {
@ -83,7 +80,7 @@ module.exports = function() {
});
return new Promise(function(resolve) {
require('zlib').gunzip(body, function(err, buf) {
zlib.gunzip(body, function(err, buf) {
assert.equal(err, null);
body = JSON.parse(buf);
assert.equal(body.name, 'testexp_gzip');

@ -0,0 +1,119 @@
'use strict';
let assert = require('assert');
let async = require('async');
let _oksum = 0;
const racePkg = require('../fixtures/package');
module.exports = function () {
let server = process.server;
describe('race', function () {
before(function () {
return server.putPackage('race', racePkg('race'))
.status(201)
.body_ok(/created new package/);
});
it('creating new package', function () {});
it('uploading 10 same versions', function (callback) {
let fns = [];
for (let i = 0; i < 10; i++) {
fns.push(function (cb_) {
let data = racePkg('race');
data.rand = Math.random();
let _res;
server.putVersion('race', '0.0.1', data)
.response(function (res) {
_res = res;
})
.then(function (body) {
cb_(null, [_res, body]);
});
});
}
async.parallel(fns, function (err, res) {
let okcount = 0;
let failcount = 0;
assert.equal(err, null);
res.forEach(function (arr) {
let resp = arr[0];
let body = arr[1];
if (resp.statusCode === 201 && ~body.ok.indexOf('published')) {
okcount++;
}
if (resp.statusCode === 409 && ~body.error.indexOf('already present')) {
failcount++;
}
if (resp.statusCode === 503 && ~body.error.indexOf('unavailable')) {
failcount++;
}
});
assert.equal(okcount + failcount, 10);
assert.equal(okcount, 1);
_oksum += okcount;
callback();
});
});
it('uploading 10 diff versions', function (callback) {
let fns = [];
for (let i = 0; i < 10; i++) {
(function (i) {
fns.push(function (cb_) {
let _res;
server.putVersion('race', '0.1.' + String(i), require('../fixtures/package')('race'))
.response(function (res) {
_res = res;
})
.then(function (body) {
cb_(null, [_res, body]);
});
});
})(i);
}
async.parallel(fns, function (err, res) {
let okcount = 0;
let failcount = 0;
assert.equal(err, null);
res.forEach(function (arr) {
let resp = arr[0];
let body = arr[1];
if (resp.statusCode === 201 && ~body.ok.indexOf('published')) {
okcount++;
}
if (resp.statusCode === 409 && ~body.error.indexOf('already present')) {
failcount++;
}
if (resp.statusCode === 503 && ~body.error.indexOf('unavailable')) {
failcount++;
}
});
assert.equal(okcount + failcount, 10);
assert.notEqual(okcount, 1);
_oksum += okcount;
callback();
});
});
after('downloading package', function () {
return server.getPackage('race')
.status(200)
.then(function (body) {
assert.equal(Object.keys(body.versions).length, _oksum);
});
});
});
};

@ -1,13 +1,36 @@
'use strict';
require('./lib/startup');
require('../lib/startup');
let assert = require('assert');
module.exports = function() {
let server2 = process.server2;
const server2 = process.server2;
const requestAuthFail = (user, pass, message) => {
return server2.auth(user, pass)
.status(409)
.body_error(message)
.then(function() {
return server2.whoami();
})
.then(function(username) {
assert.equal(username, null);
});
};
const requestAuthOk = (user, pass, regex) => {
return server2.auth(user, pass)
.status(201)
.body_ok(regex)
.then(function() {
return server2.whoami();
})
.then(function(username) {
assert.equal(username, user);
});
describe('authentication', function() {
};
describe('test default authentication', function() {
let authstr;
before(function() {
@ -15,39 +38,15 @@ module.exports = function() {
});
it('should not authenticate with wrong password', function() {
return server2.auth('authtest', 'wrongpass')
.status(409)
.body_error('this user already exists')
.then(function() {
return server2.whoami();
})
.then(function(username) {
assert.equal(username, null);
});
return requestAuthFail('authtest', 'wrongpass', 'this user already exists');
});
it('wrong password handled by plugin', function() {
return server2.auth('authtest2', 'wrongpass')
.status(409)
.body_error('registration is disabled')
.then(function() {
return server2.whoami();
})
.then(function(username) {
assert.equal(username, null);
});
it('should be wrong password handled by plugin', function() {
return requestAuthFail('authtest2', 'wrongpass', 'registration is disabled');
});
it('right password handled by plugin', function() {
return server2.auth('authtest2', 'blahblah')
.status(201)
.body_ok(/'authtest2'/)
.then(function() {
return server2.whoami();
})
.then(function(username) {
assert.equal(username, 'authtest2');
});
it('should right password handled by plugin', function() {
return requestAuthOk('authtest2', 'blahblah', /'authtest2'/);
});
after(function() {
@ -55,14 +54,14 @@ module.exports = function() {
});
});
describe('authorization', function() {
describe('test access authorization', function() {
let authstr;
before(function() {
authstr = server2.authstr;
});
describe('authtest', function() {
describe('access with user authtest', function() {
before(function() {
return server2.auth('authtest', 'test')
.status(201)
@ -88,7 +87,7 @@ module.exports = function() {
});
});
describe('authtest2', function() {
describe('access with user authtest2', function() {
before(function() {
return server2.auth('authtest2', 'blahblah')
.status(201)

@ -1,105 +0,0 @@
'use strict';
let assert = require('assert');
let async = require('async');
let _oksum = 0;
module.exports = function() {
let server = process.server;
describe('race', function() {
before(function() {
return server.putPackage('race', require('./lib/package')('race'))
.status(201)
.body_ok(/created new package/);
});
it('creating new package', function() {});
it('uploading 10 same versions', function(callback) {
let fns = [];
for (let i=0; i<10; i++) {
fns.push(function(cb_) {
let data = require('./lib/package')('race');
data.rand = Math.random();
let _res;
server.putVersion('race', '0.0.1', data)
.response(function(res) {
_res = res;
})
.then(function(body) {
cb_(null, [_res, body]);
});
});
}
async.parallel(fns, function(err, res) {
let okcount = 0;
let failcount = 0;
assert.equal(err, null);
res.forEach(function(arr) {
let resp = arr[0];
let body = arr[1];
if (resp.statusCode === 201 && ~body.ok.indexOf('published')) okcount++;
if (resp.statusCode === 409 && ~body.error.indexOf('already present')) failcount++;
if (resp.statusCode === 503 && ~body.error.indexOf('unavailable')) failcount++;
});
assert.equal(okcount + failcount, 10);
assert.equal(okcount, 1);
_oksum += okcount;
callback();
});
});
it('uploading 10 diff versions', function(callback) {
let fns = [];
for (let i=0; i<10; i++) {
(function(i) {
fns.push(function(cb_) {
let _res;
server.putVersion('race', '0.1.'+String(i), require('./lib/package')('race'))
.response(function(res) {
_res = res;
})
.then(function(body) {
cb_(null, [_res, body]);
});
});
})(i);
}
async.parallel(fns, function(err, res) {
let okcount = 0;
let failcount = 0;
assert.equal(err, null);
res.forEach(function(arr) {
let resp = arr[0];
let body = arr[1];
if (resp.statusCode === 201 && ~body.ok.indexOf('published')) okcount++;
if (resp.statusCode === 409 && ~body.error.indexOf('already present')) failcount++;
if (resp.statusCode === 503 && ~body.error.indexOf('unavailable')) failcount++;
});
assert.equal(okcount + failcount, 10);
assert.notEqual(okcount, 1);
_oksum += okcount;
callback();
});
});
after('downloading package', function() {
return server.getPackage('race')
.status(200)
.then(function(body) {
assert.equal(Object.keys(body.versions).length, _oksum);
});
});
});
};

@ -0,0 +1,83 @@
'use strict';
let assert = require('assert');
const defaultPkg = {
'name': 'testexp-incomplete',
'versions': {
'0.1.0': {
'name': 'testexp_tags',
'version': '0.1.0',
'dist': {
'shasum': 'fake',
'tarball': 'http://localhost:55550/testexp-incomplete/-/content-length.tar.gz',
},
},
'0.1.1': {
'name': 'testexp_tags',
'version': '0.1.1',
'dist': {
'shasum': 'fake',
'tarball': 'http://localhost:55550/testexp-incomplete/-/chunked.tar.gz',
},
},
},
};
module.exports = function () {
const server = process.server;
const express = process.express;
const ddd = ['content-length', 'chunked'];
describe('test send incomplete packages', function () {
before(function () {
express.get('/testexp-incomplete', function (_, res) {
res.send(defaultPkg);
});
});
ddd.forEach(function (type) {
it('should not store tarballs / ' + type, function (callback) {
let called;
express.get('/testexp-incomplete/-/' + type + '.tar.gz', function (_, response) {
if (called) {
return response.socket.destroy();
}
called = true;
if (type !== 'chunked') {
response.header('content-length', 1e6);
}
response.write('test test test\n');
setTimeout(function () {
response.socket.write('200\nsss\n');
response.socket.destroy();
cb();
}, 10);
});
server.request({uri: '/testexp-incomplete/-/' + type + '.tar.gz'})
.status(200)
.response(function (res) {
if (type !== 'chunked') {
assert.equal(res.headers['content-length'], 1e6);
}
}).then(function (body) {
assert(body.match(/test test test/));
});
function cb() {
server.request({uri: '/testexp-incomplete/-/' + type + '.tar.gz'})
.body_error('internal server error')
.then(function () {
callback();
});
}
});
});
});
};

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

@ -1,17 +1,18 @@
'use strict';
require('./lib/startup');
require('../lib/startup');
let assert = require('assert');
let crypto = require('crypto');
const assert = require('assert');
const crypto = require('crypto');
const util = require('../lib/test.utils');
function readfile(x) {
return require('fs').readFileSync(__dirname + '/' + x);
function getBinary() {
return util.readFile('../fixtures/binary');
}
module.exports = function() {
let server = process.server;
let server2 = process.server2;
const server = process.server;
const server2 = process.server2;
it('trying to fetch non-existent package / null storage', function() {
return server.getPackage('test-nullstorage-nonexist')
@ -34,14 +35,14 @@ module.exports = function() {
describe('tarball', function() {
before(function() {
return server2.putTarball('test-nullstorage2', 'blahblah', readfile('fixtures/binary'))
return server2.putTarball('test-nullstorage2', 'blahblah', getBinary())
.status(201)
.body_ok(/.*/);
});
before(function() {
let pkg = require('./lib/package')('test-nullstorage2');
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex');
let pkg = require('../fixtures/package')('test-nullstorage2');
pkg.dist.shasum = crypto.createHash('sha1').update(getBinary()).digest('hex');
return server2.putVersion('test-nullstorage2', '0.0.1', pkg)
.status(201)
.body_ok(/published/);
@ -53,7 +54,7 @@ module.exports = function() {
return server.getTarball('test-nullstorage2', 'blahblah')
.status(200)
.then(function(body) {
assert.deepEqual(body, readfile('fixtures/binary'));
assert.deepEqual(body, getBinary());
});
});

@ -1,17 +1,17 @@
'use strict';
let assert = require('assert');
const assert = require('assert');
module.exports = function() {
let server = process.server;
let express = process.express;
const server = process.server;
const express = process.express;
describe('Racy', function() {
describe('test for unexpected client hangs', function() {
let on_tarball;
before(function() {
express.get('/testexp-racycrash', function(_, res) {
res.send({
express.get('/testexp-racycrash', function(request, response) {
response.send({
'name': 'testexp-racycrash',
'versions': {
'0.1.0': {
@ -26,12 +26,12 @@ module.exports = function() {
});
});
express.get('/testexp-racycrash/-/test.tar.gz', function(_, res) {
on_tarball(res);
express.get('/testexp-racycrash/-/test.tar.gz', function(request, response) {
on_tarball(response);
});
});
it('should not crash on error if client disconnects', function(_cb) {
it('should not crash on error if client disconnects', function(callback) {
on_tarball = function(res) {
res.header('content-length', 1e6);
res.write('test test test\n');
@ -52,8 +52,8 @@ module.exports = function() {
server.request({uri: '/testexp-racycrash'})
.status(200)
.then(function() {
_cb();
});
callback();
});
}
});

@ -2,29 +2,29 @@
const assert = require('assert');
module.exports = function() {
module.exports = function () {
let server = process.server;
describe('Security', function() {
before(function() {
describe('Security', function () {
before(function () {
return server.addPackage('testpkg-sec');
});
it('bad pkg #1', function() {
it('bad pkg #1', function () {
return server.getPackage('package.json')
.status(403)
.body_error(/invalid package/);
.status(403)
.body_error(/invalid package/);
});
it('bad pkg #2', function() {
it('bad pkg #2', function () {
return server.getPackage('__proto__')
.status(403)
.body_error(/invalid package/);
.status(403)
.body_error(/invalid package/);
});
it('__proto__, connect stuff', function() {
it('__proto__, connect stuff', function () {
return server.request({uri: '/testpkg-sec?__proto__=1'})
.then(function(body) {
.then(function (body) {
// test for NOT outputting stack trace
assert(!body || typeof(body) === 'object' || body.indexOf('node_modules') === -1);
@ -33,39 +33,39 @@ module.exports = function() {
});
});
it('do not return package.json as an attachment', function() {
it('do not return package.json as an attachment', function () {
return server.request({uri: '/testpkg-sec/-/package.json'})
.status(403)
.body_error(/invalid filename/);
.status(403)
.body_error(/invalid filename/);
});
it('silly things - reading #1', function() {
it('silly things - reading #1', function () {
return server.request({uri: '/testpkg-sec/-/../../../../../../../../etc/passwd'})
.status(404);
.status(404);
});
it('silly things - reading #2', function() {
it('silly things - reading #2', function () {
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)
.body_error(/invalid filename/);
.status(403)
.body_error(/invalid filename/);
});
it('silly things - writing #1', function() {
it('silly things - writing #1', function () {
return server.putTarball('testpkg-sec', 'package.json', '{}')
.status(403)
.body_error(/invalid filename/);
.status(403)
.body_error(/invalid filename/);
});
it('silly things - writing #3', function() {
it('silly things - writing #3', function () {
return server.putTarball('testpkg-sec', 'node_modules', '{}')
.status(403)
.body_error(/invalid filename/);
.status(403)
.body_error(/invalid filename/);
});
it('silly things - writing #4', function() {
it('silly things - writing #4', function () {
return server.putTarball('testpkg-sec', '../testpkg.tgz', '{}')
.status(403)
.body_error(/invalid filename/);
.status(403)
.body_error(/invalid filename/);
});
});
};

@ -15,11 +15,11 @@ web:
enable: true
auth:
../plugins/authenticate:
../fixtures/plugins/authenticate:
accept_user: authtest2
with_password: blahblah
../plugins/authorize:
../fixtures/plugins/authorize:
allow_user: authtest
to_access: test-auth-allow

@ -1,8 +1,7 @@
'use strict';
function readfile(x) {
return require('fs').readFileSync(__dirname + '/' + x);
}
const util = require('../lib/test.utils');
const readTags = () => util.readFile('../fixtures/publish.json5');
module.exports = function() {
let server = process.server;
@ -14,7 +13,7 @@ module.exports = function() {
describe('addtag', function() {
before(function() {
return server.putPackage('testpkg-tag', eval(
'(' + readfile('fixtures/publish.json5')
'(' + readTags()
.toString('utf8')
.replace(/__NAME__/g, 'testpkg-tag')
.replace(/__VERSION__/g, '0.0.1')

@ -1,10 +1,8 @@
'use strict';
const assert = require('assert');
function readfile(x) {
return require('fs').readFileSync(__dirname + '/' + x);
}
const util = require('../lib/test.utils');
const readTags = () => util.readFile('../fixtures/tags.json');
module.exports = function() {
let server = process.server;
@ -20,7 +18,7 @@ module.exports = function() {
describe('tags', function() {
before(function() {
express.get('/testexp_tags', function(req, res) {
let f = readfile('fixtures/tags.json').toString().replace(/__NAME__/g, 'testexp_tags');
let f = readTags().toString().replace(/__NAME__/g, 'testexp_tags');
res.send(JSON.parse(f));
});
});
@ -35,9 +33,11 @@ module.exports = function() {
assert.equal(body['dist-tags'].latest, '0.1.3alpha');
assert.equal(body['dist-tags'].bad, null);
});
})
});
;['0.1.1alpha', '0.1.1-alpha', '0000.00001.001-alpha'].forEach(function(ver) {
const versions = ['0.1.1alpha', '0.1.1-alpha', '0000.00001.001-alpha'];
versions.forEach(function(ver) {
it('fetching '+ver, function() {
return server.request({uri: '/testexp_tags/'+ver})
.status(200)
@ -51,7 +51,7 @@ module.exports = function() {
describe('dist-tags methods', function() {
before(function() {
express.get('/testexp_tags2', function(req, res) {
let f = readfile('fixtures/tags.json').toString().replace(/__NAME__/g, 'testexp_tags2');
let f = readTags().toString().replace(/__NAME__/g, 'testexp_tags2');
res.send(JSON.parse(f));
});
});

@ -5,6 +5,12 @@ const path = require('path');
const assert = require('assert');
const crypto = require('crypto');
const util = require('./lib/test.utils');
function getBinary() {
return util.readFile('../fixtures/binary');
}
const STORAGE = 'store/test-storage3';
const TARBALL = 'blahblah';
const PKG_GH131 = 'pkg-gh131';
@ -14,10 +20,6 @@ function isCached(pkgName, tarballName) {
return fs.existsSync(path.join(__dirname, STORAGE, pkgName, tarballName));
}
function readfile(x) {
return fs.readFileSync(path.join(__dirname, x));
}
module.exports = function() {
const server = process.server;
const server2 = process.server2;
@ -32,14 +34,14 @@ module.exports = function() {
});
before(function () {
return server.putTarball(PKG_GH131, TARBALL, readfile('fixtures/binary'))
return server.putTarball(PKG_GH131, TARBALL, getBinary())
.status(201)
.body_ok(/.*/);
});
before(function () {
const pkg = require('./lib/package')(PKG_GH131);
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex');
const pkg = require('./fixtures/package')(PKG_GH131);
pkg.dist.shasum = crypto.createHash('sha1').update(getBinary()).digest('hex');
return server.putVersion(PKG_GH131, '0.0.1', pkg)
.status(201)
@ -65,14 +67,14 @@ module.exports = function() {
});
before(function () {
return server2.putTarball(PKG_GH1312, TARBALL, readfile('fixtures/binary'))
return server2.putTarball(PKG_GH1312, TARBALL, getBinary())
.status(201)
.body_ok(/.*/);
});
before(function () {
const pkg = require('./lib/package')(PKG_GH1312);
pkg.dist.shasum = crypto.createHash('sha1').update(readfile('fixtures/binary')).digest('hex');
const pkg = require('./fixtures/package')(PKG_GH1312);
pkg.dist.shasum = crypto.createHash('sha1').update(getBinary()).digest('hex');
return server2.putVersion(PKG_GH1312, '0.0.1', pkg)
.status(201)

@ -1,4 +1,4 @@
--reporter spec
--timeout 20000
--timeout 6000
--full-trace
--colors

@ -5,86 +5,86 @@ let Storage = require('../../src/lib/storage/up-storage');
require('../../src/lib/logger').setup([]);
function setup(host, config, mainconfig) {
function setupProxy(host, config, mainconfig) {
config.url = host;
return new Storage(config, mainconfig);
}
describe('Use proxy', function() {
it('should work fine without proxy', function() {
let x = setup('http://x/x', {}, {});
let x = setupProxy('http://x/x', {}, {});
assert.equal(x.proxy, null);
});
it('local config should take priority', function() {
let x = setup('http://x/x', {http_proxy: '123'}, {http_proxy: '456'});
let x = setupProxy('http://x/x', {http_proxy: '123'}, {http_proxy: '456'});
assert.equal(x.proxy, '123');
});
it('no_proxy is invalid', function() {
let x = setup('http://x/x', {http_proxy: '123', no_proxy: false}, {});
let x = setupProxy('http://x/x', {http_proxy: '123', no_proxy: false}, {});
assert.equal(x.proxy, '123');
x = setup('http://x/x', {http_proxy: '123', no_proxy: null}, {});
x = setupProxy('http://x/x', {http_proxy: '123', no_proxy: null}, {});
assert.equal(x.proxy, '123');
x = setup('http://x/x', {http_proxy: '123', no_proxy: []}, {});
x = setupProxy('http://x/x', {http_proxy: '123', no_proxy: []}, {});
assert.equal(x.proxy, '123');
x = setup('http://x/x', {http_proxy: '123', no_proxy: ''}, {});
x = setupProxy('http://x/x', {http_proxy: '123', no_proxy: ''}, {});
assert.equal(x.proxy, '123');
});
it('no_proxy - simple/include', function() {
let x = setup('http://localhost', {http_proxy: '123'}, {no_proxy: 'localhost'});
let x = setupProxy('http://localhost', {http_proxy: '123'}, {no_proxy: 'localhost'});
assert.equal(x.proxy, undefined);
});
it('no_proxy - simple/not', function() {
let x = setup('http://localhost', {http_proxy: '123'}, {no_proxy: 'blah'});
let x = setupProxy('http://localhost', {http_proxy: '123'}, {no_proxy: 'blah'});
assert.equal(x.proxy, '123');
});
it('no_proxy - various, single string', function() {
let x = setup('http://blahblah', {http_proxy: '123'}, {no_proxy: 'blah'});
let x = setupProxy('http://blahblah', {http_proxy: '123'}, {no_proxy: 'blah'});
assert.equal(x.proxy, '123');
x = setup('http://blah.blah', {}, {http_proxy: '123', no_proxy: 'blah'});
x = setupProxy('http://blah.blah', {}, {http_proxy: '123', no_proxy: 'blah'});
assert.equal(x.proxy, null);
x = setup('http://blahblah', {}, {http_proxy: '123', no_proxy: '.blah'});
x = setupProxy('http://blahblah', {}, {http_proxy: '123', no_proxy: '.blah'});
assert.equal(x.proxy, '123');
x = setup('http://blah.blah', {http_proxy: '123', no_proxy: '.blah'}, {});
x = setupProxy('http://blah.blah', {http_proxy: '123', no_proxy: '.blah'}, {});
assert.equal(x.proxy, null);
x = setup('http://blah', {http_proxy: '123', no_proxy: '.blah'}, {});
x = setupProxy('http://blah', {http_proxy: '123', no_proxy: '.blah'}, {});
assert.equal(x.proxy, null);
x = setup('http://blahh', {http_proxy: '123', no_proxy: 'blah'}, {});
x = setupProxy('http://blahh', {http_proxy: '123', no_proxy: 'blah'}, {});
assert.equal(x.proxy, '123');
});
it('no_proxy - various, array', function() {
let x = setup('http://blahblah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
let x = setupProxy('http://blahblah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
assert.equal(x.proxy, '123');
x = setup('http://blah.blah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
x = setupProxy('http://blah.blah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
assert.equal(x.proxy, null);
x = setup('http://blah.foo', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
x = setupProxy('http://blah.foo', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
assert.equal(x.proxy, null);
x = setup('http://foo.baz', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
x = setupProxy('http://foo.baz', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
assert.equal(x.proxy, '123');
x = setup('http://blahblah', {http_proxy: '123'}, {no_proxy: ['foo', 'bar', 'blah']});
x = setupProxy('http://blahblah', {http_proxy: '123'}, {no_proxy: ['foo', 'bar', 'blah']});
assert.equal(x.proxy, '123');
x = setup('http://blah.blah', {http_proxy: '123'}, {no_proxy: ['foo', 'bar', 'blah']});
x = setupProxy('http://blah.blah', {http_proxy: '123'}, {no_proxy: ['foo', 'bar', 'blah']});
assert.equal(x.proxy, null);
});
it('no_proxy - hostport', function() {
let x = setup('http://localhost:80', {http_proxy: '123'}, {no_proxy: 'localhost'});
let x = setupProxy('http://localhost:80', {http_proxy: '123'}, {no_proxy: 'localhost'});
assert.equal(x.proxy, null);
x = setup('http://localhost:8080', {http_proxy: '123'}, {no_proxy: 'localhost'});
x = setupProxy('http://localhost:8080', {http_proxy: '123'}, {no_proxy: 'localhost'});
assert.equal(x.proxy, null);
});
it('no_proxy - secure', function() {
let x = setup('https://something', {http_proxy: '123'}, {});
let x = setupProxy('https://something', {http_proxy: '123'}, {});
assert.equal(x.proxy, null);
x = setup('https://something', {https_proxy: '123'}, {});
x = setupProxy('https://something', {https_proxy: '123'}, {});
assert.equal(x.proxy, '123');
x = setup('https://something', {http_proxy: '456', https_proxy: '123'}, {});
x = setupProxy('https://something', {http_proxy: '456', https_proxy: '123'}, {});
assert.equal(x.proxy, '123');
});
});