mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-30 22:34:10 -05:00
refactor: improve code with es6 style
This commit is contained in:
parent
32e64c0fe3
commit
3f5a5c2345
33 changed files with 147 additions and 139 deletions
|
@ -39,7 +39,7 @@ test/
|
||||||
__mocks__/
|
__mocks__/
|
||||||
jestEnvironment.js
|
jestEnvironment.js
|
||||||
test/jest.e2e.config.js
|
test/jest.e2e.config.js
|
||||||
test/jest.config.func.js
|
test/jest.config.functional.js
|
||||||
jest.config.unit.js
|
jest.config.unit.js
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@
|
||||||
"pretest": "npm run code:build",
|
"pretest": "npm run code:build",
|
||||||
"test": "npm run test:unit",
|
"test": "npm run test:unit",
|
||||||
"test:unit": "cross-env NODE_ENV=test BABEL_ENV=test TZ=UTC jest --config ./jest.config.unit.js --maxWorkers 2",
|
"test:unit": "cross-env NODE_ENV=test BABEL_ENV=test TZ=UTC jest --config ./jest.config.unit.js --maxWorkers 2",
|
||||||
"test:functional": "cross-env NODE_ENV=testOldEnv jest --config ./test/jest.config.func.js --testPathPattern ./test/functional/index*",
|
"test:functional": "cross-env NODE_ENV=testOldEnv jest --config ./test/jest.config.functional.js --testPathPattern ./test/functional/index*",
|
||||||
"test:e2e": "cross-env BABEL_ENV=testOldEnv jest --config ./test/jest.config.e2e.js",
|
"test:e2e": "cross-env BABEL_ENV=testOldEnv jest --config ./test/jest.config.e2e.js",
|
||||||
"test:all": "npm run test && npm run test:functional && npm run test:e2e",
|
"test:all": "npm run test && npm run test:functional && npm run test:e2e",
|
||||||
"pre:ci": "npm run lint && npm run build:webui",
|
"pre:ci": "npm run lint && npm run build:webui",
|
||||||
|
|
|
@ -53,9 +53,9 @@ class Auth {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.name) {
|
if (user.name) {
|
||||||
cb(ErrorCode.getForbidden('user ' + user.name + ' is not allowed to ' + action + ' package ' + pkg.name));
|
cb(ErrorCode.getForbidden(`user ${user.name} is not allowed to ${action} package ${pkg.name}`));
|
||||||
} else {
|
} else {
|
||||||
cb(ErrorCode.getForbidden('unregistered users are not allowed to ' + action + ' package ' + pkg.name));
|
cb(ErrorCode.getForbidden(`unregistered users are not allowed to ${action} package ${pkg.name}`));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -52,7 +52,7 @@ export const API_ERROR = {
|
||||||
NOT_ALLOWED: 'not allowed to access package',
|
NOT_ALLOWED: 'not allowed to access package',
|
||||||
INTERNAL_SERVER_ERROR: 'internal server error',
|
INTERNAL_SERVER_ERROR: 'internal server error',
|
||||||
UNKNOWN_ERROR: 'unknown error',
|
UNKNOWN_ERROR: 'unknown error',
|
||||||
NOT_PACKAGE_UPLINK: 'package doesn\'t exist on uplink',
|
NOT_PACKAGE_UPLINK: 'package does not 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',
|
MAX_USERS_REACHED: 'maximum amount of users reached',
|
||||||
|
|
|
@ -467,12 +467,8 @@ function parseReadme(packageName: string, readme: string): string {
|
||||||
return marked('ERROR: No README data found!');
|
return marked('ERROR: No README data found!');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function capitalizeFirstLetter(character: string) {
|
|
||||||
return character[0].toUpperCase() + character.slice(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function buildToken(type: string, token: string) {
|
export function buildToken(type: string, token: string) {
|
||||||
return `${capitalizeFirstLetter(type)} ${token}`;
|
return `${_.capitalize(type)} ${token}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
require("babel-polyfill");
|
require('babel-polyfill');
|
||||||
require('babel-register');
|
require('babel-register');
|
||||||
module.exports = require('./setup');
|
module.exports = require('./setup');
|
||||||
|
|
|
@ -4,7 +4,7 @@ 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, DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2, TARBALL} from "../config.func";
|
import {CREDENTIALS, DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2, TARBALL} from "../config.functional";
|
||||||
import whoIam from './whoIam';
|
import whoIam from './whoIam';
|
||||||
import ping from './ping';
|
import ping from './ping';
|
||||||
import {DIST_TAGS} from '../../../src/lib/utils';
|
import {DIST_TAGS} from '../../../src/lib/utils';
|
||||||
|
@ -125,10 +125,6 @@ export default function(server: any, server2: any) {
|
||||||
.body_ok(/published/);
|
.body_ok(/published/);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('uploading new package version', () => {
|
|
||||||
/* test for before() */
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('should download a package', () => {
|
describe('should download a package', () => {
|
||||||
beforeAll(function() {
|
beforeAll(function() {
|
||||||
return server.auth(CREDENTIALS.user, CREDENTIALS.password)
|
return server.auth(CREDENTIALS.user, CREDENTIALS.password)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {CREDENTIALS} from "../config.func";
|
import {CREDENTIALS} from "../config.functional";
|
||||||
|
|
||||||
module.exports = function(server) {
|
module.exports = function(server) {
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {DOMAIN_SERVERS, PORT_SERVER_1, TARBALL} from '../config.func';
|
import {DOMAIN_SERVERS, PORT_SERVER_1, TARBALL} from '../config.functional';
|
||||||
|
|
||||||
module.exports = function(name, version = '0.0.0', port = PORT_SERVER_1, domain= `http://${DOMAIN_SERVERS}:${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') {
|
||||||
|
|
29
test/functional/fixtures/publish.json
Normal file
29
test/functional/fixtures/publish.json
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
{ _id: "__NAME__",
|
||||||
|
name: "__NAME__",
|
||||||
|
description: "",
|
||||||
|
"dist-tags": { latest: "__VERSION__" },
|
||||||
|
versions:
|
||||||
|
{ "__VERSION__":
|
||||||
|
{ name: "__NAME__",
|
||||||
|
version: "__VERSION__",
|
||||||
|
description: "",
|
||||||
|
main: "index.js",
|
||||||
|
scripts: { test: "echo "Error: no test specified" && exit 1" },
|
||||||
|
author: "",
|
||||||
|
license: "ISC",
|
||||||
|
readme: "ERROR: No README data found!",
|
||||||
|
_id: "__NAME__@__VERSION__",
|
||||||
|
dist:
|
||||||
|
{ shasum: "071c8dd9fd775bf3ebc0d5108431110f5f857ce3",
|
||||||
|
tarball: "http://localhost:4873/__NAME__/-/__NAME__-__VERSION__.tgz" },
|
||||||
|
_from: ".",
|
||||||
|
_npmVersion: "1.3.21",
|
||||||
|
_npmUser: { name: "username", email: "user@domain.com" },
|
||||||
|
maintainers: [ { name: "username", email: "user@domain.com" } ] } },
|
||||||
|
readme: "ERROR: No README data found!",
|
||||||
|
maintainers: [ { name: "username", email: "user@domain.com" } ],
|
||||||
|
_attachments:
|
||||||
|
{ "__NAME__-__VERSION__.tgz":
|
||||||
|
{ content_type: "application/octet-stream",
|
||||||
|
data: "H4sIAAAAAAAAA+2SP2vDMBDFPftTHDdkah3Zim3IGjJ0zppFyNdE+SMJSSmBkO8eWS6mQ7cGSsC/5cG9p7uTkBXyKHY0t4MWB2909mQYY81iAVHLtmY/NcGrCrKyquq25Q1vm4yVnPEm+s9e5DcuPggXV/lrn+EuMOqLcMsBUIsz4RIwkA/v9rjDt1iN4Bc5r4zuPVawok4GduSlUzZ8O2P6LFQqKN3RNf6kIT1kfTRuKZem9DGSewNbXDtn3BK0gd4Ab0mqT0XdFmE2A7qqACXGk/fUTVzC3rhxLJ6UJO3T9h+bFeb3/L9fdGJiYuI1eACk8AYWAAgAAA==",
|
||||||
|
length: 250 } } }
|
|
@ -1,29 +1,27 @@
|
||||||
{ _id: '__NAME__',
|
{ "_id": "__NAME__",
|
||||||
name: '__NAME__',
|
"name": "__NAME__",
|
||||||
description: '',
|
"dist-tags": { "latest": "__VERSION__" },
|
||||||
'dist-tags': { latest: '__VERSION__' },
|
"versions":
|
||||||
versions:
|
{ "__VERSION__":
|
||||||
{ '__VERSION__':
|
{ "name": "__NAME__",
|
||||||
{ name: '__NAME__',
|
"version": "__VERSION__",
|
||||||
version: '__VERSION__',
|
"description": "",
|
||||||
description: '',
|
"main": "index.js",
|
||||||
main: 'index.js',
|
"author": "",
|
||||||
scripts: { test: 'echo "Error: no test specified" && exit 1' },
|
"license": "ISC",
|
||||||
author: '',
|
"readme": "ERROR: No README data found!",
|
||||||
license: 'ISC',
|
"_id": "__NAME__@__VERSION__",
|
||||||
readme: 'ERROR: No README data found!',
|
"dist":
|
||||||
_id: '__NAME__@__VERSION__',
|
{ "shasum": "071c8dd9fd775bf3ebc0d5108431110f5f857ce3",
|
||||||
dist:
|
"tarball": "http://localhost:4873/__NAME__/-/__NAME__-__VERSION__.tgz" },
|
||||||
{ shasum: '071c8dd9fd775bf3ebc0d5108431110f5f857ce3',
|
"_from": ".",
|
||||||
tarball: 'http://localhost:4873/__NAME__/-/__NAME__-__VERSION__.tgz' },
|
"_npmVersion": "1.3.21",
|
||||||
_from: '.',
|
"_npmUser": { "name": "username", "email": "user@domain.com" },
|
||||||
_npmVersion: '1.3.21',
|
"maintainers": [ { "name": "username", "email": "user@domain.com" } ] } },
|
||||||
_npmUser: { name: 'rlidwka', email: 'user@domain.com' },
|
"readme": "ERROR: No README data found!",
|
||||||
maintainers: [ { name: 'rlidwka', email: 'user@domain.com' } ] } },
|
"maintainers": [ { "name": "username", "email": "user@domain.com" } ],
|
||||||
readme: 'ERROR: No README data found!',
|
"_attachments":
|
||||||
maintainers: [ { name: 'rlidwka', email: 'user@domain.com' } ],
|
{ "__NAME__-__VERSION__.tgz":
|
||||||
_attachments:
|
{ "content_type": "application/octet-stream",
|
||||||
{ '__NAME__-__VERSION__.tgz':
|
"data": "H4sIAAAAAAAAA+2SP2vDMBDFPftTHDdkah3Zim3IGjJ0zppFyNdE+SMJSSmBkO8eWS6mQ7cGSsC/5cG9p7uTkBXyKHY0t4MWB2909mQYY81iAVHLtmY/NcGrCrKyquq25Q1vm4yVnPEm+s9e5DcuPggXV/lrn+EuMOqLcMsBUIsz4RIwkA/v9rjDt1iN4Bc5r4zuPVawok4GduSlUzZ8O2P6LFQqKN3RNf6kIT1kfTRuKZem9DGSewNbXDtn3BK0gd4Ab0mqT0XdFmE2A7qqACXGk/fUTVzC3rhxLJ6UJO3T9h+bFeb3/L9fdGJiYuI1eACk8AYWAAgAAA==",
|
||||||
{ content_type: 'application/octet-stream',
|
"length": 250 } } }
|
||||||
data: 'H4sIAAAAAAAAA+2SP2vDMBDFPftTHDdkah3Zim3IGjJ0zppFyNdE+SMJSSmBkO8eWS6mQ7cGSsC/5cG9p7uTkBXyKHY0t4MWB2909mQYY81iAVHLtmY/NcGrCrKyquq25Q1vm4yVnPEm+s9e5DcuPggXV/lrn+EuMOqLcMsBUIsz4RIwkA/v9rjDt1iN4Bc5r4zuPVawok4GduSlUzZ8O2P6LFQqKN3RNf6kIT1kfTRuKZem9DGSewNbXDtn3BK0gd4Ab0mqT0XdFmE2A7qqACXGk/fUTVzC3rhxLJ6UJO3T9h+bFeb3/L9fdGJiYuI1eACk8AYWAAgAAA==',
|
|
||||||
length: 250 } } }
|
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import NodeEnvironment from 'jest-environment-node';
|
import NodeEnvironment from 'jest-environment-node';
|
||||||
import {VerdaccioConfig} from "../../lib/verdaccio-server";
|
import {VerdaccioConfig} from '../../lib/verdaccio-server';
|
||||||
import VerdaccioProcess from "../../lib/server_process";
|
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 {DOMAIN_SERVERS, 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.functional';
|
||||||
|
|
||||||
const EXPRESS_PORT = 55550;
|
const EXPRESS_PORT = 55550;
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ export default class ExpressServer {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.app = express();
|
this.app = express();
|
||||||
this.server;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start(port: number): Promise<any> {
|
start(port: number): Promise<any> {
|
||||||
|
|
|
@ -2,7 +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';
|
import {DOMAIN_SERVERS, PORT_SERVER_APP} from '../config.functional';
|
||||||
|
|
||||||
export default function(express) {
|
export default function(express) {
|
||||||
const config = {
|
const config = {
|
||||||
|
@ -126,11 +126,11 @@ export default function(express) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("publisher property should not be overridden if it exists in metadata", done => {
|
test('publisher property should not be overridden if it exists in metadata', done => {
|
||||||
const metadata = {
|
const metadata = {
|
||||||
name: "pkg-test",
|
name: 'pkg-test',
|
||||||
publisher: {
|
publisher: {
|
||||||
name: "existing-publisher-name"
|
name: 'existing-publisher-name'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ export default function(express) {
|
||||||
function(body) {
|
function(body) {
|
||||||
const jsonBody = parseBody(body);
|
const jsonBody = parseBody(body);
|
||||||
expect(`New package published: * ${metadata.name}*. Publisher name: * ${metadata.publisher.name} *.`)
|
expect(`New package published: * ${metadata.name}*. Publisher name: * ${metadata.publisher.name} *.`)
|
||||||
.toBe(jsonBody.message, "Body notify message should be equal");
|
.toBe(jsonBody.message, 'Body notify message should be equal');
|
||||||
done();
|
done();
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {buildToken} from "../../../src/lib/utils";
|
import {buildToken} from "../../../src/lib/utils";
|
||||||
import {HTTP_STATUS, TOKEN_BASIC} from "../../../src/lib/constants";
|
import {API_ERROR, HTTP_STATUS, TOKEN_BASIC} from "../../../src/lib/constants";
|
||||||
import {CREDENTIALS} from "../config.func";
|
import {CREDENTIALS} from "../config.functional";
|
||||||
|
|
||||||
export default function(server) {
|
export default function(server) {
|
||||||
|
|
||||||
|
@ -17,13 +17,14 @@ export default function(server) {
|
||||||
*/
|
*/
|
||||||
function checkAccess(auth, pkg, ok) {
|
function checkAccess(auth, pkg, ok) {
|
||||||
test(
|
test(
|
||||||
(ok ? 'allows' : 'forbids') + ' access ' + auth + ' to ' + pkg, () => {
|
`${(ok ? 'allows' : 'forbids')} access ${auth} to ${pkg}`, () => {
|
||||||
server.authstr = auth ? buildAccesToken(auth) : undefined;
|
server.authstr = auth ? buildAccesToken(auth) : undefined;
|
||||||
const req = server.getPackage(pkg);
|
const req = server.getPackage(pkg);
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
return req.status(HTTP_STATUS.NOT_FOUND).body_error(/no such package available/);
|
return req.status(HTTP_STATUS.NOT_FOUND).body_error(API_ERROR.NO_PACKAGE);
|
||||||
} else {
|
} else {
|
||||||
return req.status(HTTP_STATUS.FORBIDDEN).body_error(/not allowed to access package/);
|
return req.status(HTTP_STATUS.FORBIDDEN).body_error(API_ERROR.NOT_ALLOWED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,30 +4,25 @@ import {HEADER_TYPE, HEADERS, HTTP_STATUS} from "../../../src/lib/constants";
|
||||||
|
|
||||||
export default function(server, express) {
|
export default function(server, express) {
|
||||||
const PKG_NAME = 'testexp_gzip';
|
const PKG_NAME = 'testexp_gzip';
|
||||||
|
const PKG_VERSION = '0.0.1';
|
||||||
|
const PKG_BAD_DATA = 'testexp_baddata';
|
||||||
|
const VERSION_TOTAL = 4;
|
||||||
|
|
||||||
|
|
||||||
describe('test gzip support', () => {
|
describe('test gzip support', () => {
|
||||||
beforeAll(function() {
|
beforeAll(function() {
|
||||||
express.get(`/${PKG_NAME}`, function(req, res) {
|
express.get(`/${PKG_NAME}`, function(req, res) {
|
||||||
const version = '0.0.1';
|
const pkg = JSON.parse(readFile('../fixtures/publish.json5')
|
||||||
const pkg = eval(
|
|
||||||
'(' + readFile('../fixtures/publish.json5')
|
|
||||||
.toString('utf8')
|
.toString('utf8')
|
||||||
.replace(/__NAME__/g, PKG_NAME)
|
.replace(/__NAME__/g, PKG_NAME)
|
||||||
.replace(/__VERSION__/g, version)
|
.replace(/__VERSION__/g, PKG_VERSION));
|
||||||
+ ')'
|
|
||||||
);
|
|
||||||
|
|
||||||
// overcoming compress threshold
|
// overcoming compress threshold
|
||||||
pkg.versions['0.0.2'] = pkg.versions[version];
|
for (let i = 1; i <= VERSION_TOTAL; i++) {
|
||||||
pkg.versions['0.0.3'] = pkg.versions[version];
|
pkg.versions[`0.0.${i}`] = pkg.versions[PKG_VERSION];
|
||||||
pkg.versions['0.0.4'] = pkg.versions[version];
|
}
|
||||||
pkg.versions['0.0.5'] = pkg.versions[version];
|
|
||||||
pkg.versions['0.0.6'] = pkg.versions[version];
|
|
||||||
pkg.versions['0.0.7'] = pkg.versions[version];
|
|
||||||
pkg.versions['0.0.8'] = pkg.versions[version];
|
|
||||||
pkg.versions['0.0.9'] = pkg.versions[version];
|
|
||||||
|
|
||||||
zlib.gzip(JSON.stringify(pkg), function(err, buf) {
|
zlib.gzip(JSON.stringify(pkg), (err, buf) => {
|
||||||
expect(err).toBeNull();
|
expect(err).toBeNull();
|
||||||
expect(req.headers[HEADER_TYPE.ACCEPT_ENCODING]).toBe(HEADERS.GZIP);
|
expect(req.headers[HEADER_TYPE.ACCEPT_ENCODING]).toBe(HEADERS.GZIP);
|
||||||
res.header(HEADER_TYPE.CONTENT_ENCODING, HEADERS.GZIP);
|
res.header(HEADER_TYPE.CONTENT_ENCODING, HEADERS.GZIP);
|
||||||
|
@ -35,7 +30,9 @@ export default function(server, express) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
express.get('/testexp_baddata', function(req, res) {
|
express.get(`/${PKG_BAD_DATA}`, function(req, res) {
|
||||||
|
expect(req).toBeDefined();
|
||||||
|
expect(res).toBeDefined();
|
||||||
expect(req.headers[HEADER_TYPE.ACCEPT_ENCODING]).toBe(HEADERS.GZIP);
|
expect(req.headers[HEADER_TYPE.ACCEPT_ENCODING]).toBe(HEADERS.GZIP);
|
||||||
res.header(HEADER_TYPE.CONTENT_ENCODING, HEADERS.GZIP);
|
res.header(HEADER_TYPE.CONTENT_ENCODING, HEADERS.GZIP);
|
||||||
res.send(new Buffer([1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1]));
|
res.send(new Buffer([1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1]));
|
||||||
|
@ -43,24 +40,23 @@ export default function(server, express) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should not fail on bad gzip', () => {
|
test('should not fail on bad gzip', () => {
|
||||||
return server.getPackage('testexp_baddata').status(HTTP_STATUS.NOT_FOUND);
|
return server.getPackage(PKG_BAD_DATA).status(HTTP_STATUS.NOT_FOUND);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should understand gzipped data from uplink', () => {
|
test('should understand non gzipped data from uplink', () => {
|
||||||
return server.getPackage(PKG_NAME)
|
return server.getPackage(PKG_NAME)
|
||||||
.status(HTTP_STATUS.OK)
|
.status(HTTP_STATUS.OK)
|
||||||
.response(function(res) {
|
.response((res) => {
|
||||||
expect(res.headers[HEADER_TYPE.CONTENT_ENCODING]).toBeUndefined();
|
expect(res.headers[HEADER_TYPE.CONTENT_ENCODING]).toBeUndefined();
|
||||||
})
|
}).then(body => {
|
||||||
.then(function(body) {
|
expect(body.name).toBe(PKG_NAME);
|
||||||
expect(body.name).toBe(PKG_NAME);
|
expect(Object.keys(body.versions)).toHaveLength(VERSION_TOTAL);
|
||||||
expect(Object.keys(body.versions)).toHaveLength(9);
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should serve gzipped data', () => {
|
test('should serve gzipped data', () => {
|
||||||
return server.request({
|
return server.request({
|
||||||
uri: '/testexp_gzip',
|
uri: `/${PKG_NAME}`,
|
||||||
encoding: null,
|
encoding: null,
|
||||||
headers: {
|
headers: {
|
||||||
[HEADER_TYPE.ACCEPT_ENCODING]: HEADERS.GZIP,
|
[HEADER_TYPE.ACCEPT_ENCODING]: HEADERS.GZIP,
|
||||||
|
@ -70,17 +66,21 @@ export default function(server, express) {
|
||||||
.response(function(res) {
|
.response(function(res) {
|
||||||
expect(res.headers[HEADER_TYPE.CONTENT_ENCODING]).toBe(HEADERS.GZIP);
|
expect(res.headers[HEADER_TYPE.CONTENT_ENCODING]).toBe(HEADERS.GZIP);
|
||||||
})
|
})
|
||||||
.then(function(body) {
|
.then(async function(body) {
|
||||||
|
// should fails since is zipped
|
||||||
expect(function() {
|
expect(function() {
|
||||||
JSON.parse(body.toString('utf8'));
|
JSON.parse(body.toString('utf8'));
|
||||||
}).toThrow(/Unexpected/);
|
}).toThrow(/Unexpected/);
|
||||||
|
|
||||||
return new Promise(function(resolve) {
|
// we unzip content and check content
|
||||||
zlib.gunzip(body, function(err, buf) {
|
await new Promise(function(resolve) {
|
||||||
|
zlib.gunzip(body, function(err, buffer) {
|
||||||
expect(err).toBeNull();
|
expect(err).toBeNull();
|
||||||
body = JSON.parse(buf);
|
expect(buffer).not.toBeNull();
|
||||||
expect(body.name).toBe(PKG_NAME);
|
const unzipedBody = JSON.parse(buffer);
|
||||||
expect(Object.keys(body.versions)).toHaveLength(9)
|
|
||||||
|
expect(unzipedBody.name).toBe(PKG_NAME);
|
||||||
|
expect(Object.keys(unzipedBody.versions)).toHaveLength(VERSION_TOTAL);
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import {HEADERS, HTTP_STATUS} from '../../../src/lib/constants';
|
import {HEADERS, HTTP_STATUS} from '../../../src/lib/constants';
|
||||||
import {DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2} from '../config.func';
|
import {DOMAIN_SERVERS, PORT_SERVER_1, PORT_SERVER_2} from '../config.functional';
|
||||||
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";
|
||||||
|
|
||||||
|
@ -53,13 +53,8 @@ export default function(server, server2) {
|
||||||
expect(body[DIST_TAGS]).toEqual({latest: PKG_VERSION});
|
expect(body[DIST_TAGS]).toEqual({latest: PKG_VERSION});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('scoped package on server1', () => {
|
test('scoped package on server1', () => testScopePackage(server, PORT_SERVER_1));
|
||||||
return testScopePackage(server, PORT_SERVER_1);
|
test('scoped package on server2', () => testScopePackage(server2, PORT_SERVER_2));
|
||||||
});
|
|
||||||
|
|
||||||
test('scoped package on server2', () => {
|
|
||||||
return testScopePackage(server2, PORT_SERVER_2);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should retrieve a scoped packages under nginx', () => {
|
describe('should retrieve a scoped packages under nginx', () => {
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
require("babel-polyfill");
|
require('babel-polyfill');
|
||||||
require('babel-register');
|
require('babel-register');
|
||||||
module.exports = require('./lib/setup');
|
module.exports = require('./lib/setup');
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import {API_ERROR, HEADER_TYPE, HTTP_STATUS} from '../../../src/lib/constants';
|
import {API_ERROR, HEADER_TYPE, HTTP_STATUS} from '../../../src/lib/constants';
|
||||||
import {DOMAIN_SERVERS, PORT_SERVER_APP} from '../config.func';
|
import {DOMAIN_SERVERS, PORT_SERVER_APP} from '../config.functional';
|
||||||
|
|
||||||
const defaultPkg = {
|
const defaultPkg = {
|
||||||
'name': 'testexp-incomplete',
|
'name': 'testexp-incomplete',
|
||||||
|
@ -34,10 +34,10 @@ export default function (server, express) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
listofCalls.forEach(function (type) {
|
listofCalls.forEach((type) => {
|
||||||
test('should not store tarballs / ' + type, callback => {
|
test(`should not store tarballs / ${type}`, callback => {
|
||||||
let called;
|
let called;
|
||||||
express.get('/testexp-incomplete/-/' + type + '.tar.gz', function (_, response) {
|
express.get(`/testexp-incomplete/-/${type}.tar.gz`, function (_, response) {
|
||||||
if (called) {
|
if (called) {
|
||||||
return response.socket.destroy();
|
return response.socket.destroy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {readFile} from '../lib/test.utils';
|
import {readFile} from '../lib/test.utils';
|
||||||
import {HTTP_STATUS} from "../../../src/lib/constants";
|
import {API_MESSAGE, HTTP_STATUS} from "../../../src/lib/constants";
|
||||||
import generatePkg from '../fixtures/package';
|
import generatePkg from '../fixtures/package';
|
||||||
import {TARBALL} from '../config.func';
|
import {TARBALL} from '../config.functional';
|
||||||
|
|
||||||
const getBinary = () => readFile('../fixtures/binary');
|
const getBinary = () => readFile('../fixtures/binary');
|
||||||
|
|
||||||
|
@ -19,13 +19,13 @@ export default function (server, server2) {
|
||||||
|
|
||||||
pkgList.forEach(function (pkg) {
|
pkgList.forEach(function (pkg) {
|
||||||
let prefix = pkg;
|
let prefix = pkg;
|
||||||
pkg = 'test-mirror-' + pkg;
|
pkg = `test-mirror-${pkg}`;
|
||||||
|
|
||||||
describe(`testing mirror for ${pkg}`, () => {
|
describe(`testing mirror for ${pkg}`, () => {
|
||||||
beforeAll(function () {
|
beforeAll(function () {
|
||||||
return server2.putPackage(pkg, generatePkg(pkg))
|
return server2.putPackage(pkg, generatePkg(pkg))
|
||||||
.status(HTTP_STATUS.CREATED)
|
.status(HTTP_STATUS.CREATED)
|
||||||
.body_ok(/created new package/);
|
.body_ok(API_MESSAGE.PKG_CREATED);
|
||||||
});
|
});
|
||||||
|
|
||||||
test(prefix + 'creating new package', () => {});
|
test(prefix + 'creating new package', () => {});
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
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 {API_ERROR, HTTP_STATUS} from "../../../src/lib/constants";
|
import {API_ERROR, HTTP_STATUS} from "../../../src/lib/constants";
|
||||||
import {DOMAIN_SERVERS, PORT_SERVER_1, TARBALL} from '../config.func';
|
import {DOMAIN_SERVERS, PORT_SERVER_1, TARBALL} from '../config.functional';
|
||||||
import generatePkg from '../fixtures/package';
|
import generatePkg from '../fixtures/package';
|
||||||
import {DIST_TAGS} from '../../../src/lib/utils';
|
import {DIST_TAGS} from '../../../src/lib/utils';
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {DOMAIN_SERVERS, PORT_SERVER_APP} from '../config.func';
|
import {DOMAIN_SERVERS, PORT_SERVER_APP} from '../config.functional';
|
||||||
import {API_ERROR, HEADER_TYPE, HTTP_STATUS} from '../../../src/lib/constants';
|
import {API_ERROR, HEADER_TYPE, HTTP_STATUS} from '../../../src/lib/constants';
|
||||||
|
|
||||||
export default function(server, express) {
|
export default function(server, express) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {TARBALL} from '../config.func';
|
import {TARBALL} from '../config.functional';
|
||||||
import {HTTP_STATUS} from "../../../src/lib/constants";
|
import {HTTP_STATUS} from "../../../src/lib/constants";
|
||||||
import {createTarballHash} from "../../../src/lib/crypto-utils";
|
import {createTarballHash} from "../../../src/lib/crypto-utils";
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ packages:
|
||||||
proxy: express
|
proxy: express
|
||||||
|
|
||||||
# used by gzip.spec.js
|
# used by gzip.spec.js
|
||||||
'testexp_gzi*':
|
'testexp_gzip':
|
||||||
access: $all
|
access: $all
|
||||||
publish: $all
|
publish: $all
|
||||||
proxy: express
|
proxy: express
|
||||||
|
|
|
@ -17,13 +17,10 @@ export default function(server) {
|
||||||
|
|
||||||
describe('should test add tag to a package', () => {
|
describe('should test add tag to a package', () => {
|
||||||
beforeAll(function() {
|
beforeAll(function() {
|
||||||
return server.putPackage(PKG_NAME, eval(
|
return server.putPackage(PKG_NAME,
|
||||||
'(' + readTags()
|
JSON.parse(readTags().toString('utf8').replace(/__NAME__/g, PKG_NAME)
|
||||||
.toString('utf8')
|
.replace(/__VERSION__/g, PKG_VERSION))
|
||||||
.replace(/__NAME__/g, PKG_NAME)
|
).status(HTTP_STATUS.CREATED);
|
||||||
.replace(/__VERSION__/g, PKG_VERSION)
|
|
||||||
+ ')'
|
|
||||||
)).status(HTTP_STATUS.CREATED);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should test valid formats tags', () => {
|
describe('should test valid formats tags', () => {
|
||||||
|
@ -42,7 +39,7 @@ export default function(server) {
|
||||||
|
|
||||||
describe('should test handle invalid tag and version names', () => {
|
describe('should test handle invalid tag and version names', () => {
|
||||||
const INVALID_TAG ='tag/tag/tag';
|
const INVALID_TAG ='tag/tag/tag';
|
||||||
const handleInvalidTag = function handleInvalidTag(tag, version) {
|
const handleInvalidTag = function(tag, version) {
|
||||||
return server.addTag(PKG_NAME, tag, version)
|
return server.addTag(PKG_NAME, tag, version)
|
||||||
.status(HTTP_STATUS.FORBIDDEN)
|
.status(HTTP_STATUS.FORBIDDEN)
|
||||||
.body_error(/invalid tag/);
|
.body_error(/invalid tag/);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import {generateSha} from '../lib/test.utils';
|
import {generateSha} from '../lib/test.utils';
|
||||||
import {API_MESSAGE, HTTP_STATUS} from '../../../src/lib/constants';
|
import {API_MESSAGE, HTTP_STATUS} from '../../../src/lib/constants';
|
||||||
import {DOMAIN_SERVERS, 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.functional';
|
||||||
import {DIST_TAGS} from '../../../src/lib/utils';
|
import {DIST_TAGS} from '../../../src/lib/utils';
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,13 +29,9 @@ export default function(server, server2, server3) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
test('server1 should match with sha key from published package', () => {
|
test('server1 should match with sha key from published package', () => matchTarBallSha(server));
|
||||||
return matchTarBallSha(server);
|
test('server2 should match with sha key from published package', () => matchTarBallSha(server2));
|
||||||
});
|
|
||||||
|
|
||||||
test('server2 should match with sha key from published package', () => {
|
|
||||||
return matchTarBallSha(server2);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('should match dist-tags', () => {
|
describe('should match dist-tags', () => {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import assert from 'assert';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import {readFile} from '../lib/test.utils';
|
import {readFile} from '../lib/test.utils';
|
||||||
import {HTTP_STATUS} from "../../../src/lib/constants";
|
import {HTTP_STATUS} from "../../../src/lib/constants";
|
||||||
import {TARBALL} from '../config.func';
|
import {TARBALL} from '../config.functional';
|
||||||
|
|
||||||
function getBinary() {
|
function getBinary() {
|
||||||
return readFile('../fixtures/binary');
|
return readFile('../fixtures/binary');
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* eslint comma-dangle: 0 */
|
/* eslint comma-dangle: 0 */
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'verdaccio-func-jest',
|
name: 'verdaccio-functional-jest',
|
||||||
verbose: true,
|
verbose: true,
|
||||||
globalSetup: './functional/pre-setup.js',
|
globalSetup: './functional/pre-setup.js',
|
||||||
globalTeardown: './functional/teardown.js',
|
globalTeardown: './functional/teardown.js',
|
|
@ -6,7 +6,7 @@ import smartRequest from './request';
|
||||||
import type {IServerBridge} from '../types';
|
import type {IServerBridge} from '../types';
|
||||||
import {HEADERS, HTTP_STATUS, TOKEN_BASIC} from '../../src/lib/constants';
|
import {HEADERS, HTTP_STATUS, TOKEN_BASIC} from '../../src/lib/constants';
|
||||||
import {buildToken} from "../../src/lib/utils";
|
import {buildToken} from "../../src/lib/utils";
|
||||||
import {CREDENTIALS} from "../functional/config.func";
|
import {CREDENTIALS} from "../functional/config.functional";
|
||||||
|
|
||||||
const buildAuthHeader = (user, pass): string => {
|
const buildAuthHeader = (user, pass): string => {
|
||||||
return buildToken(TOKEN_BASIC, new Buffer(`${user}:${pass}`).toString('base64'));
|
return buildToken(TOKEN_BASIC, new Buffer(`${user}:${pass}`).toString('base64'));
|
||||||
|
|
|
@ -3,7 +3,7 @@ import _ from 'lodash';
|
||||||
import rimRaf from 'rimraf';
|
import rimRaf from 'rimraf';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {fork} from 'child_process';
|
import {fork} from 'child_process';
|
||||||
import {CREDENTIALS} from '../functional/config.func';
|
import {CREDENTIALS} from '../functional/config.functional';
|
||||||
import {HTTP_STATUS} from '../../src/lib/constants';
|
import {HTTP_STATUS} from '../../src/lib/constants';
|
||||||
import type {IVerdaccioConfig, IServerBridge, IServerProcess} from '../types';
|
import type {IVerdaccioConfig, IServerBridge, IServerProcess} from '../types';
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import {setup} from '../../../src/lib/logger';
|
||||||
|
|
||||||
import type {Config} from '@verdaccio/types';
|
import type {Config} from '@verdaccio/types';
|
||||||
import type {IStorageHandler} from '../../../types/index';
|
import type {IStorageHandler} from '../../../types/index';
|
||||||
|
import {API_ERROR} from '../../../src/lib/constants';
|
||||||
|
|
||||||
setup(configExample.logs);
|
setup(configExample.logs);
|
||||||
|
|
||||||
|
@ -75,7 +76,7 @@ describe('StorageTest', () => {
|
||||||
storage._syncUplinksMetadata('@verdaccio/404', null, {}, (err, metadata, errors) => {
|
storage._syncUplinksMetadata('@verdaccio/404', null, {}, (err, metadata, errors) => {
|
||||||
expect(errors).toBeInstanceOf(Array);
|
expect(errors).toBeInstanceOf(Array);
|
||||||
expect(errors[0][0].statusCode).toBe(404);
|
expect(errors[0][0].statusCode).toBe(404);
|
||||||
expect(errors[0][0].message).toMatch(/package doesn't exist on uplink/);
|
expect(errors[0][0].message).toMatch(API_ERROR.NOT_PACKAGE_UPLINK);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {setup} from '../../../src/lib/logger';
|
||||||
|
|
||||||
import type {Config, UpLinkConf} from '@verdaccio/types';
|
import type {Config, UpLinkConf} from '@verdaccio/types';
|
||||||
import type {IProxy} from '../../../types/index';
|
import type {IProxy} from '../../../types/index';
|
||||||
import {DEFAULT_REGISTRY} from "../../../src/lib/constants";
|
import {API_ERROR, DEFAULT_REGISTRY} from "../../../src/lib/constants";
|
||||||
|
|
||||||
setup([]);
|
setup([]);
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ describe('UpStorge', () => {
|
||||||
proxy.getRemoteMetadata('@verdaccio/fake-package', {etag: '123456'}, (err) => {
|
proxy.getRemoteMetadata('@verdaccio/fake-package', {etag: '123456'}, (err) => {
|
||||||
expect(err).not.toBeNull();
|
expect(err).not.toBeNull();
|
||||||
expect(err.statusCode).toBe(404);
|
expect(err.statusCode).toBe(404);
|
||||||
expect(err.message).toMatch(/package doesn't exist on uplink/);
|
expect(err.message).toMatch(API_ERROR.NOT_PACKAGE_UPLINK);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue