refactor: usage of constants on sanity test
This commit is contained in:
parent
686f22461f
commit
e59f282a27
|
@ -47,6 +47,7 @@ export const API_ERROR = {
|
||||||
NOT_PACKAGE_UPLINK: 'package doesn\'t exist on uplink',
|
NOT_PACKAGE_UPLINK: 'package doesn\'t exist on uplink',
|
||||||
CONTENT_MISMATCH: 'content length mismatch',
|
CONTENT_MISMATCH: 'content length mismatch',
|
||||||
NOT_FILE_UPLINK: 'file doesn\'t exist on uplink',
|
NOT_FILE_UPLINK: 'file doesn\'t exist on uplink',
|
||||||
|
MAX_USERS_REACHED: 'maximum amount of users reached',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DEFAULT_NO_README = 'ERROR: No README data found!';
|
export const DEFAULT_NO_README = 'ERROR: No README data found!';
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {HTTP_STATUS} from "../../../src/lib/constants";
|
import {API_ERROR, HTTP_STATUS} from "../../../src/lib/constants";
|
||||||
|
|
||||||
export default function(server) {
|
export default function(server) {
|
||||||
describe('npm adduser', () => {
|
describe('npm adduser', () => {
|
||||||
|
@ -22,7 +22,7 @@ export default function(server) {
|
||||||
test('should not register more users', () => {
|
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(HTTP_STATUS.CONFLICT)
|
.status(HTTP_STATUS.CONFLICT)
|
||||||
.body_error(/maximum amount of users reached/);
|
.body_error(API_ERROR.MAX_USERS_REACHED);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,10 @@ import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {createTarballHash} from "../../../src/lib/crypto-utils";
|
import {createTarballHash} from "../../../src/lib/crypto-utils";
|
||||||
import {HTTP_STATUS} from "../../../src/lib/constants";
|
import {HTTP_STATUS} from "../../../src/lib/constants";
|
||||||
import {CREDENTIALS, PORT_SERVER_1, PORT_SERVER_2, TARBALL} from "../config.func";
|
import {CREDENTIALS, DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2, TARBALL} from "../config.func";
|
||||||
import whoIam from './whoIam';
|
import whoIam from './whoIam';
|
||||||
import ping from './ping';
|
import ping from './ping';
|
||||||
|
import {DIST_TAGS} from '../../../src/lib/utils';
|
||||||
|
|
||||||
function readfile(folderPath) {
|
function readfile(folderPath) {
|
||||||
return fs.readFileSync(path.join(__dirname, '/', folderPath));
|
return fs.readFileSync(path.join(__dirname, '/', folderPath));
|
||||||
|
@ -20,6 +21,7 @@ export default function(server: any, server2: any) {
|
||||||
describe('basic test endpoints', () => {
|
describe('basic test endpoints', () => {
|
||||||
|
|
||||||
const PKG_NAME:string = 'testpkg';
|
const PKG_NAME:string = 'testpkg';
|
||||||
|
const PKG_VERSION:string = '0.0.1';
|
||||||
|
|
||||||
beforeAll(function() {
|
beforeAll(function() {
|
||||||
return server.auth(CREDENTIALS.user, CREDENTIALS.password)
|
return server.auth(CREDENTIALS.user, CREDENTIALS.password)
|
||||||
|
@ -107,7 +109,7 @@ export default function(server: any, server2: any) {
|
||||||
let pkg = getPackage(PKG_NAME);
|
let pkg = getPackage(PKG_NAME);
|
||||||
pkg.dist.shasum = createTarballHash().update('fake').digest('hex');
|
pkg.dist.shasum = createTarballHash().update('fake').digest('hex');
|
||||||
|
|
||||||
return server.putVersion(PKG_NAME, '0.0.1', pkg)
|
return server.putVersion(PKG_NAME, PKG_VERSION, pkg)
|
||||||
.status(HTTP_STATUS.BAD_REQUEST)
|
.status(HTTP_STATUS.BAD_REQUEST)
|
||||||
.body_error(/shasum error/);
|
.body_error(/shasum error/);
|
||||||
});
|
});
|
||||||
|
@ -118,7 +120,7 @@ export default function(server: any, server2: any) {
|
||||||
const pkg = getPackage(PKG_NAME);
|
const pkg = getPackage(PKG_NAME);
|
||||||
|
|
||||||
pkg.dist.shasum = createTarballHash().update(readfile('../fixtures/binary')).digest('hex');
|
pkg.dist.shasum = createTarballHash().update(readfile('../fixtures/binary')).digest('hex');
|
||||||
return server.putVersion(PKG_NAME, '0.0.1', pkg)
|
return server.putVersion(PKG_NAME, PKG_VERSION, pkg)
|
||||||
.status(HTTP_STATUS.CREATED)
|
.status(HTTP_STATUS.CREATED)
|
||||||
.body_ok(/published/);
|
.body_ok(/published/);
|
||||||
});
|
});
|
||||||
|
@ -129,33 +131,33 @@ export default function(server: any, server2: any) {
|
||||||
|
|
||||||
describe('should download a package', () => {
|
describe('should download a package', () => {
|
||||||
beforeAll(function() {
|
beforeAll(function() {
|
||||||
return server.auth('test', 'test')
|
return server.auth(CREDENTIALS.user, CREDENTIALS.password)
|
||||||
.status(HTTP_STATUS.CREATED)
|
.status(HTTP_STATUS.CREATED)
|
||||||
.body_ok(/'test'/);
|
.body_ok(new RegExp(CREDENTIALS.user));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should download a newly created package from server1', () => {
|
test('should download a newly created package from server1', () => {
|
||||||
return server.getPackage(PKG_NAME)
|
return server.getPackage(PKG_NAME)
|
||||||
.status(200)
|
.status(HTTP_STATUS.OK)
|
||||||
.then(function (body) {
|
.then(function (body) {
|
||||||
expect(body.name).toEqual(PKG_NAME);
|
expect(body.name).toEqual(PKG_NAME);
|
||||||
expect(body.versions['0.0.1'].name).toEqual(PKG_NAME);
|
expect(body.versions[PKG_VERSION].name).toEqual(PKG_NAME);
|
||||||
expect(body.versions['0.0.1'].dist.tarball).toEqual(`http://localhost:${PORT_SERVER_1}/testpkg/-/${TARBALL}`);
|
expect(body.versions[PKG_VERSION].dist.tarball).toEqual(`http://${DOMAIN_SERVERS}:${PORT_SERVER_1}/${PKG_NAME}/-/${TARBALL}`);
|
||||||
expect(body['dist-tags']).toEqual({
|
expect(body[DIST_TAGS]).toEqual({
|
||||||
latest: '0.0.1'
|
latest: PKG_VERSION
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should downloading a package from server2', () => {
|
test('should downloading a package from server2', () => {
|
||||||
return server2.getPackage(PKG_NAME)
|
return server2.getPackage(PKG_NAME)
|
||||||
.status(200)
|
.status(HTTP_STATUS.OK)
|
||||||
.then(function (body) {
|
.then(function (body) {
|
||||||
expect(body.name).toEqual(PKG_NAME);
|
expect(body.name).toEqual(PKG_NAME);
|
||||||
expect(body.versions['0.0.1'].name).toEqual(PKG_NAME);
|
expect(body.versions[PKG_VERSION].name).toEqual(PKG_NAME);
|
||||||
expect(body.versions['0.0.1'].dist.tarball).toEqual(`http://localhost:${PORT_SERVER_2}/testpkg/-/${TARBALL}`);
|
expect(body.versions[PKG_VERSION].dist.tarball).toEqual(`http://${DOMAIN_SERVERS}:${PORT_SERVER_2}/${PKG_NAME}/-/${TARBALL}`);
|
||||||
expect(body['dist-tags']).toEqual({
|
expect(body[DIST_TAGS]).toEqual({
|
||||||
latest: '0.0.1'
|
latest: PKG_VERSION
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -168,7 +170,6 @@ export default function(server: any, server2: any) {
|
||||||
|
|
||||||
describe('handle failures on endpoints', () => {
|
describe('handle failures on endpoints', () => {
|
||||||
|
|
||||||
|
|
||||||
test('should fails trying to fetch non-existent package', () => {
|
test('should fails trying to fetch non-existent package', () => {
|
||||||
return server.getPackage(PKG_NAME).status(HTTP_STATUS.NOT_FOUND).body_error(/no such package/);
|
return server.getPackage(PKG_NAME).status(HTTP_STATUS.NOT_FOUND).body_error(/no such package/);
|
||||||
});
|
});
|
||||||
|
@ -176,7 +177,7 @@ export default function(server: any, server2: any) {
|
||||||
test(
|
test(
|
||||||
'should fails on publish a version for non existing package',
|
'should fails on publish a version for non existing package',
|
||||||
() => {
|
() => {
|
||||||
return server.putVersion('testpxg', '0.0.1', getPackage('testpxg'))
|
return server.putVersion('testpxg', PKG_VERSION, getPackage('testpxg'))
|
||||||
.status(HTTP_STATUS.NOT_FOUND)
|
.status(HTTP_STATUS.NOT_FOUND)
|
||||||
.body_error(/no such package/);
|
.body_error(/no such package/);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ export const CREDENTIALS = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TARBALL = 'tarball-blahblah-file.name';
|
export const TARBALL = 'tarball-blahblah-file.name';
|
||||||
|
export const PORT_SERVER_APP = '55550';
|
||||||
export const PORT_SERVER_1 = '55551';
|
export const PORT_SERVER_1 = '55551';
|
||||||
export const PORT_SERVER_2 = '55552';
|
export const PORT_SERVER_2 = '55552';
|
||||||
export const PORT_SERVER_3 = '55553';
|
export const PORT_SERVER_3 = '55553';
|
||||||
|
export const DOMAIN_SERVERS = 'localhost';
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {PORT_SERVER_1, TARBALL} from '../config.func';
|
import {DOMAIN_SERVERS, PORT_SERVER_1, TARBALL} from '../config.func';
|
||||||
|
|
||||||
module.exports = function(name, version = '0.0.0', port = PORT_SERVER_1, domain= `http://localhost:${port}`,
|
module.exports = function(name, version = '0.0.0', port = PORT_SERVER_1, domain= `http://${DOMAIN_SERVERS}:${port}`,
|
||||||
fileName = TARBALL, readme = 'this is a readme') {
|
fileName = TARBALL, readme = 'this is a readme') {
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -8,7 +8,7 @@ import VerdaccioProcess from "../../lib/server_process";
|
||||||
import Server from "../../lib/server";
|
import Server from "../../lib/server";
|
||||||
import ExpressServer from "./simple_server";
|
import ExpressServer from "./simple_server";
|
||||||
import type {IServerBridge} from '../../types';
|
import type {IServerBridge} from '../../types';
|
||||||
import {PORT_SERVER_1, PORT_SERVER_2, PORT_SERVER_3} from '../config.func';
|
import {DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2, PORT_SERVER_3} from '../config.func';
|
||||||
|
|
||||||
const EXPRESS_PORT = 55550;
|
const EXPRESS_PORT = 55550;
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ class FunctionalEnvironment extends NodeEnvironment {
|
||||||
const verdaccioConfig = new VerdaccioConfig(
|
const verdaccioConfig = new VerdaccioConfig(
|
||||||
path.join(pathStore, config.storage),
|
path.join(pathStore, config.storage),
|
||||||
path.join(pathStore, config.config),
|
path.join(pathStore, config.config),
|
||||||
`http://localhost:${config.port}/`, config.port);
|
`http://${DOMAIN_SERVERS}:${config.port}/`, config.port);
|
||||||
console.log(chalk.magentaBright(`Running registry ${config.config} on port ${config.port}`));
|
console.log(chalk.magentaBright(`Running registry ${config.config} on port ${config.port}`));
|
||||||
const server: IServerBridge = new Server(verdaccioConfig.domainPath);
|
const server: IServerBridge = new Server(verdaccioConfig.domainPath);
|
||||||
serverList.push(server);
|
serverList.push(server);
|
||||||
|
|
|
@ -2,6 +2,7 @@ import _ from 'lodash';
|
||||||
|
|
||||||
import {HEADERS} from '../../../src/lib/constants';
|
import {HEADERS} from '../../../src/lib/constants';
|
||||||
import {notify} from '../../../src/lib/notify';
|
import {notify} from '../../../src/lib/notify';
|
||||||
|
import {DOMAIN_SERVERS, PORT_SERVER_APP} from '../config.func';
|
||||||
|
|
||||||
export default function(express) {
|
export default function(express) {
|
||||||
const config = {
|
const config = {
|
||||||
|
@ -10,7 +11,7 @@ export default function(express) {
|
||||||
headers: [{
|
headers: [{
|
||||||
'Content-Type': HEADERS.JSON
|
'Content-Type': HEADERS.JSON
|
||||||
}],
|
}],
|
||||||
endpoint: "http://localhost:55550/api/notify",
|
endpoint: `http://${DOMAIN_SERVERS}:${PORT_SERVER_APP}/api/notify`,
|
||||||
content: `{"color":"green","message":"New package published: * {{ name }}*. Publisher name: * {{ publisher.name }} *.","notify":true,"message_format":"text"}`
|
content: `{"color":"green","message":"New package published: * {{ name }}*. Publisher name: * {{ publisher.name }} *.","notify":true,"message_format":"text"}`
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -114,7 +115,7 @@ export default function(express) {
|
||||||
name: "pkg-test"
|
name: "pkg-test"
|
||||||
};
|
};
|
||||||
const configFail = _.cloneDeep(config);
|
const configFail = _.cloneDeep(config);
|
||||||
configFail.notify.endpoint = "http://localhost:55550/api/notify/bad";
|
configFail.notify.endpoint = `http://${DOMAIN_SERVERS}:${PORT_SERVER_APP}/api/notify/bad`;
|
||||||
|
|
||||||
notify(metadata, configFail, publisherInfo).then(function () {
|
notify(metadata, configFail, publisherInfo).then(function () {
|
||||||
expect(false).toBe('This service should fails with status code 400');
|
expect(false).toBe('This service should fails with status code 400');
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import {HEADERS, HTTP_STATUS} from '../../../src/lib/constants';
|
import {HEADERS, HTTP_STATUS} from '../../../src/lib/constants';
|
||||||
import {PORT_SERVER_1, PORT_SERVER_2} from '../config.func';
|
import {DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2} from '../config.func';
|
||||||
import {generateSha} from '../lib/test.utils';
|
import {generateSha} from '../lib/test.utils';
|
||||||
import {DIST_TAGS} from "../../../src/lib/utils";
|
import {DIST_TAGS} from "../../../src/lib/utils";
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ export default function(server, server2) {
|
||||||
expect(body.name).toBe(SCOPE);
|
expect(body.name).toBe(SCOPE);
|
||||||
expect(body.versions[PKG_VERSION].name).toBe(SCOPE);
|
expect(body.versions[PKG_VERSION].name).toBe(SCOPE);
|
||||||
expect(body.versions[PKG_VERSION].dist.tarball).toBe(
|
expect(body.versions[PKG_VERSION].dist.tarball).toBe(
|
||||||
`http://localhost:${port}/@test%2fscoped/-/${PKG_NAME}-${PKG_VERSION}.tgz`);
|
`http://${DOMAIN_SERVERS}:${port}/@test%2fscoped/-/${PKG_NAME}-${PKG_VERSION}.tgz`);
|
||||||
expect(body[DIST_TAGS]).toEqual({latest: PKG_VERSION});
|
expect(body[DIST_TAGS]).toEqual({latest: PKG_VERSION});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ export default function(server, server2) {
|
||||||
.then(function(body) {
|
.then(function(body) {
|
||||||
expect(body.name).toEqual(SCOPE);
|
expect(body.name).toEqual(SCOPE);
|
||||||
expect(body.dist.tarball).toEqual(
|
expect(body.dist.tarball).toEqual(
|
||||||
`http://localhost:${PORT_SERVER_2}/@test%2fscoped/-/${PKG_NAME}-${PKG_VERSION}.tgz`);
|
`http://${DOMAIN_SERVERS}:${PORT_SERVER_2}/@test%2fscoped/-/${PKG_NAME}-${PKG_VERSION}.tgz`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import {readFile} from '../lib/test.utils';
|
import {readFile} from '../lib/test.utils';
|
||||||
import {createTarballHash} from "../../../src/lib/crypto-utils";
|
import {createTarballHash} from "../../../src/lib/crypto-utils";
|
||||||
import {HTTP_STATUS} from "../../../src/lib/constants";
|
import {API_ERROR, HTTP_STATUS} from "../../../src/lib/constants";
|
||||||
import {PORT_SERVER_1, TARBALL} from '../config.func';
|
import {DOMAIN_SERVERS, PORT_SERVER_1, TARBALL} from '../config.func';
|
||||||
|
import generatePkg from '../fixtures/package';
|
||||||
|
import {DIST_TAGS} from '../../../src/lib/utils';
|
||||||
|
|
||||||
function getBinary() {
|
function getBinary() {
|
||||||
return readFile('../fixtures/binary');
|
return readFile('../fixtures/binary');
|
||||||
|
@ -12,42 +14,44 @@ export default function (server, server2) {
|
||||||
const PKG_NAME = 'test-nullstorage2';
|
const PKG_NAME = 'test-nullstorage2';
|
||||||
const PKG_VERSION = '0.0.1';
|
const PKG_VERSION = '0.0.1';
|
||||||
|
|
||||||
describe('should check whether test-nullstorage is on server1', () => {
|
describe('should test a scenario when tarball is being fetch from uplink', () => {
|
||||||
test('trying to fetch non-existent package / null storage', () => {
|
|
||||||
|
describe(`should check whether ${PKG_NAME} is on server1`, () => {
|
||||||
|
test('should fails on fetch non-existent package on server1', () => {
|
||||||
return server.getPackage('test-nullstorage-nonexist').status(HTTP_STATUS.NOT_FOUND)
|
return server.getPackage('test-nullstorage-nonexist').status(HTTP_STATUS.NOT_FOUND)
|
||||||
.body_error(/no such package/);
|
.body_error(API_ERROR.NO_PACKAGE);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should check whether test-nullstorage is on server2', () => {
|
describe(`should check whether ${PKG_NAME} is on server2`, () => {
|
||||||
beforeAll(function() {
|
beforeAll(function() {
|
||||||
return server2.addPackage(PKG_NAME);
|
return server2.addPackage(PKG_NAME);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should creaate a new package on server2', () => {/* test for before() */});
|
test('should create a new package on server2', () => {/* test for before() */});
|
||||||
|
|
||||||
test('should fails on download a non existent tarball', () => {
|
test('should fails on download a non existent tarball from server1', () => {
|
||||||
return server.getTarball(PKG_NAME, TARBALL)
|
return server.getTarball(PKG_NAME, TARBALL)
|
||||||
.status(HTTP_STATUS.NOT_FOUND)
|
.status(HTTP_STATUS.NOT_FOUND)
|
||||||
.body_error(/no such file/);
|
.body_error(/no such file/);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('test and publish test-nullstorage2 package', () => {
|
describe(`should succesfully publish ${PKG_NAME} package on server2`, () => {
|
||||||
beforeAll(function() {
|
beforeAll(function() {
|
||||||
return server2.putTarball(PKG_NAME, TARBALL, getBinary())
|
return server2.putTarball(PKG_NAME, TARBALL, getBinary())
|
||||||
.status(HTTP_STATUS.CREATED).body_ok(/.*/);
|
.status(HTTP_STATUS.CREATED).body_ok(/.*/);
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeAll(function() {
|
beforeAll(function() {
|
||||||
let pkg = require('../fixtures/package')(PKG_NAME);
|
let pkg = generatePkg(PKG_NAME);
|
||||||
pkg.dist.shasum = createTarballHash().update(getBinary()).digest('hex');
|
pkg.dist.shasum = createTarballHash().update(getBinary()).digest('hex');
|
||||||
return server2.putVersion(PKG_NAME, PKG_VERSION, pkg)
|
return server2.putVersion(PKG_NAME, PKG_VERSION, pkg)
|
||||||
.status(HTTP_STATUS.CREATED).body_ok(/published/);
|
.status(HTTP_STATUS.CREATED).body_ok(/published/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should upload a new version for test-nullstorage2', () => {/* test for before() */});
|
test(`should publish a new version for ${PKG_NAME} on server 2`, () => {/* test for before() */});
|
||||||
|
|
||||||
test('should fetch the newly created published tarball for test-nullstorage2', () => {
|
test(`should fetch the newly created published tarball for ${PKG_NAME} from server1 on server2`, () => {
|
||||||
return server.getTarball(PKG_NAME, TARBALL)
|
return server.getTarball(PKG_NAME, TARBALL)
|
||||||
.status(HTTP_STATUS.OK)
|
.status(HTTP_STATUS.OK)
|
||||||
.then(function(body) {
|
.then(function(body) {
|
||||||
|
@ -55,14 +59,15 @@ export default function (server, server2) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should check whether the metadata for test-nullstorage2 match', () => {
|
test(`should fetch metadata for ${PKG_NAME} match from server1`, () => {
|
||||||
return server.getPackage(PKG_NAME)
|
return server.getPackage(PKG_NAME)
|
||||||
.status(HTTP_STATUS.OK)
|
.status(HTTP_STATUS.OK)
|
||||||
.then(function(body) {
|
.then(function(body) {
|
||||||
expect(body.name).toBe(PKG_NAME);
|
expect(body.name).toBe(PKG_NAME);
|
||||||
expect(body.versions[PKG_VERSION].name).toBe(PKG_NAME);
|
expect(body.versions[PKG_VERSION].name).toBe(PKG_NAME);
|
||||||
expect(body.versions[PKG_VERSION].dist.tarball).toBe(`http://localhost:${PORT_SERVER_1}/${PKG_NAME}/-/${TARBALL}`);
|
expect(body.versions[PKG_VERSION].dist.tarball).toBe(`http://${DOMAIN_SERVERS}:${PORT_SERVER_1}/${PKG_NAME}/-/${TARBALL}`);
|
||||||
expect(body['dist-tags']).toEqual({latest: PKG_VERSION});
|
expect(body[DIST_TAGS]).toEqual({latest: PKG_VERSION});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
|
import {DOMAIN_SERVERS, PORT_SERVER_APP} from '../config.func';
|
||||||
|
import {API_ERROR, HEADER_TYPE, HTTP_STATUS} from '../../../src/lib/constants';
|
||||||
|
|
||||||
export default function(server, express) {
|
export default function(server, express) {
|
||||||
|
|
||||||
describe('test for unexpected client hangs', () => {
|
describe('shoul test for unexpected client hangs', () => {
|
||||||
let handleResponseTarball;
|
let handleResponseTarball;
|
||||||
|
|
||||||
beforeAll(function() {
|
beforeAll(function() {
|
||||||
|
@ -13,7 +16,7 @@ export default function(server, express) {
|
||||||
'version': '0.1.0',
|
'version': '0.1.0',
|
||||||
'dist': {
|
'dist': {
|
||||||
'shasum': 'fake',
|
'shasum': 'fake',
|
||||||
'tarball': 'http://localhost:55550/testexp-racycrash/-/test.tar.gz',
|
'tarball': `http://${DOMAIN_SERVERS}:${PORT_SERVER_APP}/testexp-racycrash/-/test.tar.gz`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -27,14 +30,14 @@ export default function(server, express) {
|
||||||
|
|
||||||
test('should not crash on error if client disconnects', callback => {
|
test('should not crash on error if client disconnects', callback => {
|
||||||
handleResponseTarball = function(res) {
|
handleResponseTarball = function(res) {
|
||||||
res.header('content-length', 1e6);
|
res.header(HEADER_TYPE.CONTENT_LENGTH, 1e6);
|
||||||
res.write('test test test');
|
res.write('test test test');
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
res.write('-');
|
res.write('-');
|
||||||
// destroy the connection
|
// destroy the connection
|
||||||
res.socket.destroy();
|
res.socket.destroy();
|
||||||
cb();
|
cb();
|
||||||
}, 200);
|
}, HTTP_STATUS.OK);
|
||||||
};
|
};
|
||||||
|
|
||||||
server.request({uri: '/testexp-racycrash/-/test.tar.gz'})
|
server.request({uri: '/testexp-racycrash/-/test.tar.gz'})
|
||||||
|
@ -45,7 +48,7 @@ export default function(server, express) {
|
||||||
function cb() {
|
function cb() {
|
||||||
// test for NOT crashing
|
// test for NOT crashing
|
||||||
server.request({uri: '/testexp-racycrash'})
|
server.request({uri: '/testexp-racycrash'})
|
||||||
.status(200)
|
.status(HTTP_STATUS.OK)
|
||||||
.then(function() {
|
.then(function() {
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
|
@ -58,7 +61,7 @@ export default function(server, express) {
|
||||||
};
|
};
|
||||||
|
|
||||||
return server.request({uri: '/testexp-racycrash/-/test.tar.gz'})
|
return server.request({uri: '/testexp-racycrash/-/test.tar.gz'})
|
||||||
.body_error('internal server error');
|
.body_error(API_ERROR.INTERNAL_SERVER_ERROR);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,67 +1,68 @@
|
||||||
import assert from 'assert';
|
import _ from 'lodash';
|
||||||
|
import {HTTP_STATUS} from '../../../src/lib/constants';
|
||||||
|
|
||||||
export default function(server) {
|
export default function(server) {
|
||||||
|
|
||||||
describe('Security', () => {
|
describe('should test security on endpoints', () => {
|
||||||
beforeAll(function () {
|
beforeAll(function () {
|
||||||
return server.addPackage('testpkg-sec');
|
return server.addPackage('testpkg-sec');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('bad pkg #1', () => {
|
test('should fails on fetch bad pkg #1', () => {
|
||||||
return server.getPackage('package.json')
|
return server.getPackage('package.json')
|
||||||
.status(403)
|
.status(HTTP_STATUS.FORBIDDEN)
|
||||||
.body_error(/invalid package/);
|
.body_error(/invalid package/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('bad pkg #2', () => {
|
test('should fails on fetch bad pkg #2', () => {
|
||||||
return server.getPackage('__proto__')
|
return server.getPackage('__proto__')
|
||||||
.status(403)
|
.status(HTTP_STATUS.FORBIDDEN)
|
||||||
.body_error(/invalid package/);
|
.body_error(/invalid package/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('__proto__, connect stuff', () => {
|
test('should do not fails on __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
|
||||||
assert(!body || typeof(body) === 'object' || body.indexOf('node_modules') === -1);
|
expect(_.isNil(body) || _.isObject(body) || body.indexOf('node_modules')).toBeTruthy();
|
||||||
|
|
||||||
// test for NOT crashing
|
// test for NOT crashing
|
||||||
return server.request({uri: '/testpkg-sec'}).status(200);
|
return server.request({uri: '/testpkg-sec'}).status(HTTP_STATUS.OK);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('do not return package.json as an attachment', () => {
|
test('should fails and 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(HTTP_STATUS.FORBIDDEN)
|
||||||
.body_error(/invalid filename/);
|
.body_error(/invalid filename/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('silly things - reading #1', () => {
|
test('should fails on fetch silly things - reading #1', () => {
|
||||||
return server.request({uri: '/testpkg-sec/-/../../../../../../../../etc/passwd'})
|
return server.request({uri: '/testpkg-sec/-/../../../../../../../../etc/passwd'})
|
||||||
.status(404);
|
.status(HTTP_STATUS.NOT_FOUND);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('silly things - reading #2', () => {
|
test('should fails on fetch 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(HTTP_STATUS.FORBIDDEN)
|
||||||
.body_error(/invalid filename/);
|
.body_error(/invalid filename/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('silly things - writing #1', () => {
|
test('should fails on fetch silly things - writing #1', () => {
|
||||||
return server.putTarball('testpkg-sec', 'package.json', '{}')
|
return server.putTarball('testpkg-sec', 'package.json', '{}')
|
||||||
.status(403)
|
.status(HTTP_STATUS.FORBIDDEN)
|
||||||
.body_error(/invalid filename/);
|
.body_error(/invalid filename/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('silly things - writing #3', () => {
|
test('should fails on fetch silly things - writing #3', () => {
|
||||||
return server.putTarball('testpkg-sec', 'node_modules', '{}')
|
return server.putTarball('testpkg-sec', 'node_modules', '{}')
|
||||||
.status(403)
|
.status(HTTP_STATUS.FORBIDDEN)
|
||||||
.body_error(/invalid filename/);
|
.body_error(/invalid filename/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('silly things - writing #4', () => {
|
test('should fails on fetch silly things - writing #4', () => {
|
||||||
return server.putTarball('testpkg-sec', '../testpkg.tgz', '{}')
|
return server.putTarball('testpkg-sec', '../testpkg.tgz', '{}')
|
||||||
.status(403)
|
.status(HTTP_STATUS.FORBIDDEN)
|
||||||
.body_error(/invalid filename/);
|
.body_error(/invalid filename/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
import {generateSha} from '../lib/test.utils';
|
import {generateSha} from '../lib/test.utils';
|
||||||
import {HEADERS} from '../../../src/lib/constants';
|
import {HEADERS, HTTP_STATUS} from '../../../src/lib/constants';
|
||||||
import {PORT_SERVER_1, PORT_SERVER_2} from '../config.func';
|
import {DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2} from '../config.func';
|
||||||
|
|
||||||
export default function(server, server2, express) {
|
export default function(server, server2, express) {
|
||||||
describe('should test preserve tags when publishing something', () => {
|
describe('should test preserve tags when publishing something', () => {
|
||||||
|
@ -42,11 +42,11 @@ export default function(server, server2, express) {
|
||||||
describe('should match dist-tags', () => {
|
describe('should match dist-tags', () => {
|
||||||
const matchDisTags = (server, port) => {
|
const matchDisTags = (server, port) => {
|
||||||
return server.getPackage('testpkg-preserve')
|
return server.getPackage('testpkg-preserve')
|
||||||
.status(200)
|
.status(HTTP_STATUS.OK)
|
||||||
.then(function(body) {
|
.then(function(body) {
|
||||||
assert.equal(body.name, 'testpkg-preserve');
|
assert.equal(body.name, 'testpkg-preserve');
|
||||||
assert.equal(body.versions['0.0.1'].name, 'testpkg-preserve');
|
assert.equal(body.versions['0.0.1'].name, 'testpkg-preserve');
|
||||||
assert.equal(body.versions['0.0.1'].dist.tarball, `http://localhost:${port}/testpkg-preserve/-/testpkg-preserve-0.0.1.tgz`);
|
assert.equal(body.versions['0.0.1'].dist.tarball, `http://${DOMAIN_SERVERS}:${port}/testpkg-preserve/-/testpkg-preserve-0.0.1.tgz`);
|
||||||
assert.deepEqual(body['dist-tags'], {foo: '0.0.1', latest: '0.0.1'});
|
assert.deepEqual(body['dist-tags'], {foo: '0.0.1', latest: '0.0.1'});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -96,13 +96,13 @@ export default function(server, server2, express) {
|
||||||
|
|
||||||
test('server1 - search', () => {
|
test('server1 - search', () => {
|
||||||
return server.request({uri: '/-/all'})
|
return server.request({uri: '/-/all'})
|
||||||
.status(200)
|
.status(HTTP_STATUS.OK)
|
||||||
.then(check);
|
.then(check);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('server2 - search', () => {
|
test('server2 - search', () => {
|
||||||
return server2.request({uri: '/-/all'})
|
return server2.request({uri: '/-/all'})
|
||||||
.status(200)
|
.status(HTTP_STATUS.OK)
|
||||||
.then(check);
|
.then(check);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue