2018-06-21 01:10:33 -05:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
import {createTarballHash} from "../../../src/lib/crypto-utils";
|
|
|
|
import {HTTP_STATUS} from "../../../src/lib/constants";
|
|
|
|
import {CREDENTIALS} from "../config.func";
|
|
|
|
import whoIam from './whoIam';
|
|
|
|
import ping from './ping';
|
2017-08-06 14:54:15 -05:00
|
|
|
|
2017-06-30 16:10:30 -05:00
|
|
|
function readfile(folderPath) {
|
2018-06-21 01:10:33 -05:00
|
|
|
return fs.readFileSync(path.join(__dirname, '/', folderPath));
|
2017-06-30 16:10:30 -05:00
|
|
|
}
|
|
|
|
|
2017-07-01 02:09:44 -05:00
|
|
|
function getPackage(name) {
|
2017-12-02 05:19:08 -05:00
|
|
|
return require('../fixtures/package')(name);
|
2017-07-01 02:09:44 -05:00
|
|
|
}
|
|
|
|
|
2018-06-21 01:10:33 -05:00
|
|
|
export default function(server: any, server2: any) {
|
2017-12-02 05:19:08 -05:00
|
|
|
describe('basic test endpoints', () => {
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2018-06-21 01:10:33 -05:00
|
|
|
const PKG_NAME:string = 'testpkg';
|
|
|
|
|
2018-01-27 20:40:07 -05:00
|
|
|
beforeAll(function() {
|
2018-06-21 01:10:33 -05:00
|
|
|
return server.auth(CREDENTIALS.user, CREDENTIALS.password)
|
|
|
|
.status(HTTP_STATUS.CREATED)
|
2018-01-27 20:40:07 -05:00
|
|
|
.body_ok(/'test'/);
|
|
|
|
});
|
|
|
|
|
2018-06-21 01:10:33 -05:00
|
|
|
whoIam(server);
|
|
|
|
ping(server);
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
describe('handling packages', () => {
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
beforeAll(function () {
|
2018-06-21 01:10:33 -05:00
|
|
|
return server.addPackage(PKG_NAME);
|
2017-07-01 02:09:44 -05:00
|
|
|
});
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
beforeAll(function () {
|
2017-07-30 10:55:41 -05:00
|
|
|
return server.addPackage('testpkg-single-tarball');
|
|
|
|
});
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
test('creating new package', () => {/* test for before() */
|
2017-08-06 14:54:15 -05:00
|
|
|
});
|
2017-07-01 02:09:44 -05:00
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
test('downloading non-existent tarball', () => {
|
2018-06-21 01:10:33 -05:00
|
|
|
return server.getTarball(PKG_NAME, 'blahblah')
|
|
|
|
.status(HTTP_STATUS.NOT_FOUND)
|
|
|
|
.body_error(/no such file/);
|
2017-07-01 02:09:44 -05:00
|
|
|
});
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
test('uploading incomplete tarball', () => {
|
2018-06-21 01:10:33 -05:00
|
|
|
return server.putTarballIncomplete(PKG_NAME, 'blahblah1', readfile('../fixtures/binary'), 3000);
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
describe('publishing package', () => {
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
beforeAll(function () {
|
2018-06-21 01:10:33 -05:00
|
|
|
return server.putTarball(PKG_NAME, 'blahblah', readfile('../fixtures/binary'))
|
|
|
|
.status(HTTP_STATUS.CREATED)
|
2017-08-06 14:54:15 -05:00
|
|
|
.body_ok(/.*/);
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2014-11-12 06:14:37 -05:00
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
beforeAll(function () {
|
|
|
|
return server.putTarball('testpkg-single-tarball', 'single', readfile('../fixtures/binary'))
|
2018-06-21 01:10:33 -05:00
|
|
|
.status(HTTP_STATUS.CREATED)
|
2017-07-30 10:55:41 -05:00
|
|
|
.body_ok(/.*/);
|
|
|
|
});
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
afterAll(function () {
|
2018-06-21 01:10:33 -05:00
|
|
|
return server.removeTarball(PKG_NAME).status(HTTP_STATUS.CREATED);
|
2017-07-01 17:05:58 -05:00
|
|
|
});
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
test('remove a tarball', () => {
|
2017-07-01 02:09:44 -05:00
|
|
|
/* test for before() */
|
|
|
|
});
|
2015-04-11 12:11:04 -05:00
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
test('uploading new tarball', () => {
|
2017-07-01 17:05:58 -05:00
|
|
|
/* test for after() */
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
test('remove non existing tarball', () => {
|
2018-06-21 01:10:33 -05:00
|
|
|
return server.removeTarball('testpkg404').status(HTTP_STATUS.NOT_FOUND);
|
2017-07-01 17:05:58 -05:00
|
|
|
});
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
test('remove non existing single tarball', () => {
|
2018-06-21 01:10:33 -05:00
|
|
|
return server.removeSingleTarball('', 'fakeFile').status(HTTP_STATUS.NOT_FOUND);
|
2017-07-30 10:55:41 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
// testexp-incomplete
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
test('remove existing single tarball', () => {
|
2018-06-21 01:10:33 -05:00
|
|
|
return server.removeSingleTarball('testpkg-single-tarball', 'single').status(HTTP_STATUS.CREATED);
|
2017-07-30 10:55:41 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
// testexp-incomplete
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
test('downloading newly created tarball', () => {
|
2018-06-21 01:10:33 -05:00
|
|
|
return server.getTarball(PKG_NAME, 'blahblah')
|
2017-08-06 14:54:15 -05:00
|
|
|
.status(200)
|
|
|
|
.then(function (body) {
|
2018-06-21 01:10:33 -05:00
|
|
|
expect(body).toEqual(readfile('../fixtures/binary'));
|
2017-08-06 14:54:15 -05:00
|
|
|
});
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2017-07-01 17:05:58 -05:00
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
test('uploading new package version (bad sha)', () => {
|
2018-06-21 01:10:33 -05:00
|
|
|
let pkg = getPackage(PKG_NAME);
|
|
|
|
pkg.dist.shasum = createTarballHash().update('fake').digest('hex');
|
2017-07-01 17:05:58 -05:00
|
|
|
|
2018-06-21 01:10:33 -05:00
|
|
|
return server.putVersion(PKG_NAME, '0.0.1', pkg)
|
|
|
|
.status(HTTP_STATUS.BAD_REQUEST)
|
2017-08-06 14:54:15 -05:00
|
|
|
.body_error(/shasum error/);
|
2017-07-01 17:05:58 -05:00
|
|
|
});
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
describe('publishing version', () => {
|
2017-07-01 17:05:58 -05:00
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
beforeAll(function () {
|
2018-06-21 01:10:33 -05:00
|
|
|
const pkg = getPackage(PKG_NAME);
|
2017-07-01 17:05:58 -05:00
|
|
|
|
2018-06-21 01:10:33 -05:00
|
|
|
pkg.dist.shasum = createTarballHash().update(readfile('../fixtures/binary')).digest('hex');
|
|
|
|
return server.putVersion(PKG_NAME, '0.0.1', pkg)
|
|
|
|
.status(HTTP_STATUS.CREATED)
|
2017-08-06 14:54:15 -05:00
|
|
|
.body_ok(/published/);
|
2017-07-01 17:05:58 -05:00
|
|
|
});
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
test('uploading new package version', () => {
|
2017-07-01 17:05:58 -05:00
|
|
|
/* test for before() */
|
|
|
|
});
|
|
|
|
|
2018-01-27 20:40:07 -05:00
|
|
|
describe('should download a package', () => {
|
|
|
|
beforeAll(function() {
|
|
|
|
return server.auth('test', 'test')
|
2018-06-21 01:10:33 -05:00
|
|
|
.status(HTTP_STATUS.CREATED)
|
2018-01-27 20:40:07 -05:00
|
|
|
.body_ok(/'test'/);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should download a newly created package from server1', () => {
|
2018-06-21 01:10:33 -05:00
|
|
|
return server.getPackage(PKG_NAME)
|
2018-01-27 20:40:07 -05:00
|
|
|
.status(200)
|
|
|
|
.then(function (body) {
|
2018-06-21 01:10:33 -05:00
|
|
|
expect(body.name).toEqual(PKG_NAME);
|
|
|
|
expect(body.versions['0.0.1'].name).toEqual(PKG_NAME);
|
|
|
|
expect(body.versions['0.0.1'].dist.tarball).toEqual('http://localhost:55551/testpkg/-/blahblah');
|
|
|
|
expect(body['dist-tags']).toEqual({
|
2018-01-27 20:40:07 -05:00
|
|
|
latest: '0.0.1'
|
|
|
|
});
|
2017-08-06 14:54:15 -05:00
|
|
|
});
|
2018-01-27 20:40:07 -05:00
|
|
|
});
|
2017-07-01 17:05:58 -05:00
|
|
|
|
2018-01-27 20:40:07 -05:00
|
|
|
test('should downloading a package from server2', () => {
|
2018-06-21 01:10:33 -05:00
|
|
|
return server2.getPackage(PKG_NAME)
|
2018-01-27 20:40:07 -05:00
|
|
|
.status(200)
|
|
|
|
.then(function (body) {
|
2018-06-21 01:10:33 -05:00
|
|
|
expect(body.name).toEqual(PKG_NAME);
|
|
|
|
expect(body.versions['0.0.1'].name).toEqual(PKG_NAME);
|
|
|
|
expect(body.versions['0.0.1'].dist.tarball).toEqual('http://localhost:55552/testpkg/-/blahblah');
|
|
|
|
expect(body['dist-tags']).toEqual({
|
2018-01-27 20:40:07 -05:00
|
|
|
latest: '0.0.1'
|
|
|
|
});
|
2017-08-06 14:54:15 -05:00
|
|
|
});
|
2018-01-27 20:40:07 -05:00
|
|
|
});
|
|
|
|
|
2017-07-01 17:05:58 -05:00
|
|
|
});
|
2018-01-27 20:40:07 -05:00
|
|
|
|
2017-07-01 17:05:58 -05:00
|
|
|
});
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
describe('handle failures on endpoints', () => {
|
2014-11-12 06:14:37 -05:00
|
|
|
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
test('should fails trying to fetch non-existent package', () => {
|
2018-06-21 01:10:33 -05:00
|
|
|
return server.getPackage(PKG_NAME).status(HTTP_STATUS.NOT_FOUND).body_error(/no such package/);
|
2017-07-01 17:05:58 -05:00
|
|
|
});
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
test(
|
|
|
|
'should fails on publish a version for non existing package',
|
|
|
|
() => {
|
|
|
|
return server.putVersion('testpxg', '0.0.1', getPackage('testpxg'))
|
2018-06-21 01:10:33 -05:00
|
|
|
.status(HTTP_STATUS.NOT_FOUND)
|
2017-12-02 05:19:08 -05:00
|
|
|
.body_error(/no such package/);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
test('should be a package not found', () => {
|
|
|
|
return server.putTarball('nonExistingPackage', 'blahblah', readfile('../fixtures/binary'))
|
2018-06-21 01:10:33 -05:00
|
|
|
.status(HTTP_STATUS.NOT_FOUND)
|
2017-08-06 14:54:15 -05:00
|
|
|
.body_error(/no such/);
|
2017-07-01 17:05:58 -05:00
|
|
|
});
|
|
|
|
|
2017-12-02 05:19:08 -05:00
|
|
|
test('should fails on publish package in a bad uplink', () => {
|
2017-07-01 17:05:58 -05:00
|
|
|
return server.putPackage('baduplink', getPackage('baduplink'))
|
2018-06-21 01:10:33 -05:00
|
|
|
.status(HTTP_STATUS.SERVICE_UNAVAILABLE)
|
2017-08-06 14:54:15 -05:00
|
|
|
.body_error(/one of the uplinks is down, refuse to publish/);
|
2017-07-01 17:05:58 -05:00
|
|
|
});
|
2017-04-19 14:15:28 -05:00
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2017-12-02 05:20:27 -05:00
|
|
|
}
|