2017-12-02 11:19:08 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import crypto from 'crypto';
|
2017-08-06 21:54:15 +02:00
|
|
|
|
2017-06-30 23:10:30 +02:00
|
|
|
function readfile(folderPath) {
|
|
|
|
return require('fs').readFileSync(__dirname + '/' + folderPath);
|
|
|
|
}
|
|
|
|
|
2017-07-01 09:09:44 +02:00
|
|
|
function getPackage(name) {
|
2017-12-02 11:19:08 +01:00
|
|
|
return require('../fixtures/package')(name);
|
2017-07-01 09:09:44 +02:00
|
|
|
}
|
|
|
|
|
2017-06-30 23:10:30 +02:00
|
|
|
function createHash() {
|
|
|
|
return crypto.createHash('sha1');
|
2013-12-19 16:11:54 +01:00
|
|
|
}
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
export default function(server, server2) {
|
|
|
|
describe('basic test endpoints', () => {
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2018-01-28 02:40:07 +01:00
|
|
|
beforeAll(function() {
|
|
|
|
return server.auth('test', 'test')
|
|
|
|
.status(201)
|
|
|
|
.body_ok(/'test'/);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
require('./whoIam')(server);
|
|
|
|
require('./ping')(server);
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
describe('handling packages', () => {
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2017-07-02 00:05:58 +02:00
|
|
|
return server.addPackage('testpkg');
|
2017-07-01 09:09:44 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2017-07-30 17:55:41 +02:00
|
|
|
return server.addPackage('testpkg-single-tarball');
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('creating new package', () => {/* test for before() */
|
2017-08-06 21:54:15 +02:00
|
|
|
});
|
2017-07-01 09:09:44 +02:00
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('downloading non-existent tarball', () => {
|
2017-07-02 00:05:58 +02:00
|
|
|
return server.getTarball('testpkg', 'blahblah').status(404).body_error(/no such file/);
|
2017-07-01 09:09:44 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('uploading incomplete tarball', () => {
|
|
|
|
return server.putTarballIncomplete('testpkg', 'blahblah1', readfile('../fixtures/binary'), 3000);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
describe('publishing package', () => {
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
|
|
|
return server.putTarball('testpkg', 'blahblah', readfile('../fixtures/binary'))
|
2017-08-06 21:54:15 +02:00
|
|
|
.status(201)
|
|
|
|
.body_ok(/.*/);
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2014-11-12 12:14:37 +01:00
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
|
|
|
return server.putTarball('testpkg-single-tarball', 'single', readfile('../fixtures/binary'))
|
2017-07-30 17:55:41 +02:00
|
|
|
.status(201)
|
|
|
|
.body_ok(/.*/);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
afterAll(function () {
|
2017-07-02 00:05:58 +02:00
|
|
|
return server.removeTarball('testpkg').status(201);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('remove a tarball', () => {
|
2017-07-01 09:09:44 +02:00
|
|
|
/* test for before() */
|
|
|
|
});
|
2015-04-11 19:11:04 +02:00
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('uploading new tarball', () => {
|
2017-07-02 00:05:58 +02:00
|
|
|
/* test for after() */
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('remove non existing tarball', () => {
|
2017-07-02 00:05:58 +02:00
|
|
|
return server.removeTarball('testpkg404').status(404);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('remove non existing single tarball', () => {
|
2017-07-30 17:55:41 +02:00
|
|
|
return server.removeSingleTarball('', 'fakeFile').status(404);
|
|
|
|
});
|
|
|
|
|
|
|
|
// testexp-incomplete
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('remove existing single tarball', () => {
|
2017-07-30 17:55:41 +02:00
|
|
|
return server.removeSingleTarball('testpkg-single-tarball', 'single').status(201);
|
|
|
|
});
|
|
|
|
|
|
|
|
// testexp-incomplete
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('downloading newly created tarball', () => {
|
2017-07-02 00:05:58 +02:00
|
|
|
return server.getTarball('testpkg', 'blahblah')
|
2017-08-06 21:54:15 +02:00
|
|
|
.status(200)
|
|
|
|
.then(function (body) {
|
2017-12-02 11:19:08 +01:00
|
|
|
assert.deepEqual(body, readfile('../fixtures/binary'));
|
2017-08-06 21:54:15 +02:00
|
|
|
});
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
2017-07-02 00:05:58 +02:00
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('uploading new package version (bad sha)', () => {
|
2017-07-02 00:05:58 +02:00
|
|
|
let pkg = getPackage('testpkg');
|
|
|
|
pkg.dist.shasum = createHash().update('fake').digest('hex');
|
|
|
|
|
|
|
|
return server.putVersion('testpkg', '0.0.1', pkg)
|
2017-08-06 21:54:15 +02:00
|
|
|
.status(400)
|
|
|
|
.body_error(/shasum error/);
|
2017-07-02 00:05:58 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
describe('publishing version', () => {
|
2017-07-02 00:05:58 +02:00
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
beforeAll(function () {
|
2017-07-02 00:05:58 +02:00
|
|
|
const pkg = getPackage('testpkg');
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
pkg.dist.shasum = createHash().update(readfile('../fixtures/binary')).digest('hex');
|
2017-07-02 00:05:58 +02:00
|
|
|
return server.putVersion('testpkg', '0.0.1', pkg)
|
2017-08-06 21:54:15 +02:00
|
|
|
.status(201)
|
|
|
|
.body_ok(/published/);
|
2017-07-02 00:05:58 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('uploading new package version', () => {
|
2017-07-02 00:05:58 +02:00
|
|
|
/* test for before() */
|
|
|
|
});
|
|
|
|
|
2018-01-28 02:40:07 +01:00
|
|
|
describe('should download a package', () => {
|
|
|
|
beforeAll(function() {
|
|
|
|
return server.auth('test', 'test')
|
|
|
|
.status(201)
|
|
|
|
.body_ok(/'test'/);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should download a newly created package from server1', () => {
|
|
|
|
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'
|
|
|
|
});
|
2017-08-06 21:54:15 +02:00
|
|
|
});
|
2018-01-28 02:40:07 +01:00
|
|
|
});
|
2017-07-02 00:05:58 +02:00
|
|
|
|
2018-01-28 02:40:07 +01:00
|
|
|
test('should downloading a package from server2', () => {
|
|
|
|
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-08-06 21:54:15 +02:00
|
|
|
});
|
2018-01-28 02:40:07 +01:00
|
|
|
});
|
|
|
|
|
2017-07-02 00:05:58 +02:00
|
|
|
});
|
2018-01-28 02:40:07 +01:00
|
|
|
|
2017-07-02 00:05:58 +02:00
|
|
|
});
|
2017-04-19 21:15:28 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
describe('handle failures on endpoints', () => {
|
2014-11-12 12:14:37 +01:00
|
|
|
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('should fails trying to fetch non-existent package', () => {
|
2017-07-02 00:05:58 +02:00
|
|
|
return server.getPackage('testpkg').status(404).body_error(/no such package/);
|
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test(
|
|
|
|
'should fails on publish a version for non existing package',
|
|
|
|
() => {
|
|
|
|
return server.putVersion('testpxg', '0.0.1', getPackage('testpxg'))
|
|
|
|
.status(404)
|
|
|
|
.body_error(/no such package/);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
test('should be a package not found', () => {
|
|
|
|
return server.putTarball('nonExistingPackage', 'blahblah', readfile('../fixtures/binary'))
|
2017-08-06 21:54:15 +02:00
|
|
|
.status(404)
|
|
|
|
.body_error(/no such/);
|
2017-07-02 00:05:58 +02:00
|
|
|
});
|
|
|
|
|
2017-12-02 11:19:08 +01:00
|
|
|
test('should fails on publish package in a bad uplink', () => {
|
2017-07-02 00:05:58 +02:00
|
|
|
return server.putPackage('baduplink', getPackage('baduplink'))
|
2017-08-06 21:54:15 +02:00
|
|
|
.status(503)
|
|
|
|
.body_error(/one of the uplinks is down, refuse to publish/);
|
2017-07-02 00:05:58 +02:00
|
|
|
});
|
2017-04-19 21:15:28 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2017-12-02 11:20:27 +01:00
|
|
|
}
|