2017-04-19 14:15:28 -05:00
|
|
|
'use strict';
|
2013-12-19 10:11:54 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
const assert = require('assert');
|
|
|
|
const crypto = require('crypto');
|
2013-12-19 10:11:54 -05:00
|
|
|
|
2017-06-30 16:10:30 -05:00
|
|
|
function readfile(folderPath) {
|
|
|
|
return require('fs').readFileSync(__dirname + '/' + folderPath);
|
|
|
|
}
|
|
|
|
|
2017-07-01 02:09:44 -05:00
|
|
|
function getPackage(name) {
|
|
|
|
return require('./lib/package')(name);
|
|
|
|
}
|
|
|
|
|
2017-06-30 16:10:30 -05:00
|
|
|
function createHash() {
|
|
|
|
return crypto.createHash('sha1');
|
2013-12-19 10:11:54 -05:00
|
|
|
}
|
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
module.exports = function() {
|
|
|
|
let server = process.server;
|
|
|
|
let server2 = process.server2;
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-07-01 17:05:58 -05:00
|
|
|
describe('basic test endpoints', function() {
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-07-01 17:05:58 -05:00
|
|
|
require('./basic/whoIam')(server);
|
|
|
|
require('./basic/ping')(server);
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-07-01 17:05:58 -05:00
|
|
|
describe('handling packages', function() {
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
before(function() {
|
2017-07-01 17:05:58 -05:00
|
|
|
return server.addPackage('testpkg');
|
2017-07-01 02:09:44 -05:00
|
|
|
});
|
|
|
|
|
2017-07-30 10:55:41 -05:00
|
|
|
before(function() {
|
|
|
|
return server.addPackage('testpkg-single-tarball');
|
|
|
|
});
|
|
|
|
|
2017-07-01 17:05:58 -05:00
|
|
|
it('creating new package', function() {/* test for before() */});
|
2017-07-01 02:09:44 -05:00
|
|
|
|
2017-07-01 17:05:58 -05:00
|
|
|
it('downloading non-existent tarball', function() {
|
|
|
|
return server.getTarball('testpkg', 'blahblah').status(404).body_error(/no such file/);
|
2017-07-01 02:09:44 -05:00
|
|
|
});
|
|
|
|
|
2017-07-01 17:05:58 -05:00
|
|
|
it('uploading incomplete tarball', function() {
|
|
|
|
return server.putTarballIncomplete('testpkg', 'blahblah1', readfile('fixtures/binary'), 3000);
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-07-01 17:05:58 -05:00
|
|
|
describe('publishing package', function() {
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-04-19 14:15:28 -05:00
|
|
|
before(function() {
|
2017-07-01 17:05:58 -05:00
|
|
|
return server.putTarball('testpkg', 'blahblah', readfile('fixtures/binary'))
|
2015-04-11 12:11:04 -05:00
|
|
|
.status(201)
|
2017-07-01 17:05:58 -05:00
|
|
|
.body_ok(/.*/);
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-07-30 10:55:41 -05:00
|
|
|
before(function() {
|
|
|
|
return server.putTarball('testpkg-single-tarball', 'single', readfile('fixtures/binary'))
|
|
|
|
.status(201)
|
|
|
|
.body_ok(/.*/);
|
|
|
|
});
|
|
|
|
|
2017-07-01 17:05:58 -05:00
|
|
|
after(function() {
|
|
|
|
return server.removeTarball('testpkg').status(201);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('remove a tarball', function() {
|
2017-07-01 02:09:44 -05:00
|
|
|
/* test for before() */
|
|
|
|
});
|
2015-04-11 12:11:04 -05:00
|
|
|
|
2017-07-01 17:05:58 -05:00
|
|
|
it('uploading new tarball', function() {
|
|
|
|
/* test for after() */
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
|
|
|
|
2017-07-01 17:05:58 -05:00
|
|
|
it('remove non existing tarball', function() {
|
|
|
|
return server.removeTarball('testpkg404').status(404);
|
|
|
|
});
|
|
|
|
|
2017-07-30 10:55:41 -05:00
|
|
|
it('remove non existing single tarball', function() {
|
|
|
|
return server.removeSingleTarball('', 'fakeFile').status(404);
|
|
|
|
});
|
|
|
|
|
|
|
|
// testexp-incomplete
|
|
|
|
|
|
|
|
it('remove existing single tarball', function() {
|
|
|
|
return server.removeSingleTarball('testpkg-single-tarball', 'single').status(201);
|
|
|
|
});
|
|
|
|
|
|
|
|
// testexp-incomplete
|
|
|
|
|
2017-07-01 17:05:58 -05:00
|
|
|
it('downloading newly created tarball', function() {
|
|
|
|
return server.getTarball('testpkg', 'blahblah')
|
2015-04-11 12:11:04 -05:00
|
|
|
.status(200)
|
2017-04-19 14:15:28 -05:00
|
|
|
.then(function(body) {
|
2017-07-01 17:05:58 -05:00
|
|
|
assert.deepEqual(body, readfile('fixtures/binary'));
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
|
|
|
});
|
2017-07-01 17:05:58 -05:00
|
|
|
|
|
|
|
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/);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('publishing version', 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/);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('uploading new package version', function() {
|
|
|
|
/* test for before() */
|
|
|
|
});
|
|
|
|
|
|
|
|
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'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-07-01 17:05:58 -05:00
|
|
|
describe('handle failures on endpoints', function() {
|
2014-11-12 06:14:37 -05:00
|
|
|
|
|
|
|
|
2017-07-01 17:05:58 -05:00
|
|
|
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() {
|
|
|
|
return server.putVersion('testpxg', '0.0.1', getPackage('testpxg'))
|
|
|
|
.status(404)
|
|
|
|
.body_error(/no such package/);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be a package not found', function() {
|
|
|
|
return server.putTarball('nonExistingPackage', 'blahblah', readfile('fixtures/binary'))
|
|
|
|
.status(404)
|
|
|
|
.body_error(/no such/);
|
|
|
|
});
|
|
|
|
|
|
|
|
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/);
|
|
|
|
});
|
2017-04-19 14:15:28 -05:00
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2013-12-19 10:11:54 -05:00
|
|
|
|