diff --git a/.babelrc b/.babelrc index f0d422e80..21cd820bc 100644 --- a/.babelrc +++ b/.babelrc @@ -1,68 +1,3 @@ { - "env": { - "ui": { - "presets": [ - "@babel/react", - "@babel/flow", - ["@babel/env",{ - "targets": { - "browsers": [ - "last 5 versions", - "FireFox >= 44", - "Safari >= 7", - "Explorer 11", - "last 4 Edge versions" - ] - } - }] - ], - "plugins": [ - "react-hot-loader/babel", - "@babel/transform-runtime", - "@babel/proposal-class-properties", - "@babel/plugin-proposal-object-rest-spread", - "@babel/syntax-dynamic-import", - "emotion" - ] - }, - "test": { - "presets": [["@babel/env", { - "targets": { - "node": "6.10" - } - }], "@babel/flow", - "@babel/react"], - "plugins": [ - "@babel/plugin-proposal-class-properties", - "@babel/plugin-proposal-object-rest-spread", - "babel-plugin-dynamic-import-node", - "emotion" - ] - }, - "registry": { - "presets": [ - ["@babel/env", { - "targets": { - "node": "6.10" - } - }], "@babel/flow"], - "plugins": [ - "@babel/plugin-proposal-object-rest-spread", - "@babel/proposal-class-properties" - ] - }, - "registry-docker": { - "presets": [ - ["@babel/env", { - "targets": { - "node": "10" - } - }], - "@babel/flow"], - "plugins": [ - "@babel/plugin-proposal-object-rest-spread", - "@babel/proposal-class-properties" - ] - } - } + "presets": [["@verdaccio", {"flow": true}]] } diff --git a/package.json b/package.json index 3d33084e9..2f7791b4e 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,8 @@ }, "dependencies": { "@verdaccio/file-locking": "0.0.7", - "@verdaccio/local-storage": "1.2.0", - "@verdaccio/streams": "1.0.0", + "@verdaccio/local-storage": "2.0.0-beta.1", + "@verdaccio/streams": "2.0.0-beta.0", "JSONStream": "1.3.4", "async": "2.6.1", "body-parser": "1.18.3", @@ -52,41 +52,13 @@ "verror": "1.10.0" }, "devDependencies": { - "@babel/cli": "7.2.3", - "@babel/core": "7.2.2", - "@babel/node": "7.2.2", - "@babel/plugin-proposal-class-properties": "7.2.3", - "@babel/plugin-proposal-decorators": "7.2.3", - "@babel/plugin-proposal-export-namespace-from": "7.2.0", - "@babel/plugin-proposal-function-sent": "7.2.0", - "@babel/plugin-proposal-json-strings": "7.2.0", - "@babel/plugin-proposal-numeric-separator": "7.2.0", - "@babel/plugin-proposal-object-rest-spread": "7.2.0", - "@babel/plugin-proposal-throw-expressions": "7.2.0", - "@babel/plugin-syntax-dynamic-import": "7.2.0", - "@babel/plugin-syntax-import-meta": "7.2.0", - "@babel/plugin-transform-async-to-generator": "7.2.0", - "@babel/plugin-transform-classes": "7.2.2", - "@babel/plugin-transform-runtime": "7.2.0", - "@babel/polyfill": "7.2.3", - "@babel/preset-env": "7.2.3", - "@babel/preset-flow": "7.0.0", - "@babel/preset-react": "7.0.0", - "@babel/register": "7.0.0", - "@babel/runtime": "^7.2.0", "@commitlint/cli": "7.2.1", "@commitlint/config-conventional": "7.1.2", "@material-ui/core": "3.9.0", "@material-ui/icons": "3.0.2", + "@verdaccio/babel-preset": "0.0.3", "@verdaccio/types": "4.1.4", "autosuggest-highlight": "3.1.1", - "babel-core": "7.0.0-bridge.0", - "babel-eslint": "10.0.1", - "babel-jest": "23.6.0", - "babel-loader": "8.0.4", - "babel-plugin-dynamic-import-node": "2.2.0", - "babel-plugin-emotion": "9.2.10", - "babel-plugin-flow-runtime": "0.17.0", "bundlesize": "0.17.0", "codecov": "3.1.0", "cross-env": "5.2.0", @@ -154,7 +126,7 @@ "typeface-roboto": "0.0.54", "url-loader": "1.1.1", "verdaccio-auth-memory": "0.0.4", - "verdaccio-memory": "1.0.3", + "verdaccio-memory": "2.0.0-beta.0", "webpack": "4.20.2", "webpack-bundle-analyzer": "3.0.2", "webpack-cli": "3.1.1", diff --git a/src/api/web/index.js b/src/api/web/index.js index 5ff2891aa..71bbfe863 100644 --- a/src/api/web/index.js +++ b/src/api/web/index.js @@ -9,7 +9,7 @@ import VError from 'verror'; import chalk from 'chalk'; import express from 'express'; -import { combineBaseUrl, getWebProtocol, spliceURL } from '../../lib/utils'; +import { combineBaseUrl, getWebProtocol } from '../../lib/utils'; import Search from '../../lib/search'; import { HEADERS, HTTP_STATUS, WEB_TITLE } from '../../lib/constants'; import { spliceURL } from '../../utils/string'; diff --git a/src/lib/constants.js b/src/lib/constants.js index c81c5fb26..77a538f08 100644 --- a/src/lib/constants.js +++ b/src/lib/constants.js @@ -102,8 +102,10 @@ export const API_ERROR = { CONFIG_BAD_FORMAT: 'config file must be an object', BAD_USERNAME_PASSWORD: 'bad username/password, access denied', NO_PACKAGE: 'no such package available', + PACKAGE_CANNOT_BE_ADDED: 'this package cannot be added', BAD_DATA: 'bad data', NOT_ALLOWED: 'not allowed to access package', + NOT_ALLOWED_PUBLISH: 'not allowed to publish package', INTERNAL_SERVER_ERROR: 'internal server error', UNKNOWN_ERROR: 'unknown error', NOT_PACKAGE_UPLINK: 'package does not exist on uplink', diff --git a/src/lib/local-storage.js b/src/lib/local-storage.js index e3d4c467f..c62f07e9c 100644 --- a/src/lib/local-storage.js +++ b/src/lib/local-storage.js @@ -631,29 +631,6 @@ class LocalStorage implements IStorage { }); } - _getCustomPackageLocalStorages() { - const storages = {}; - - // add custom storage if exist - if (this.config.storage) { - storages[this.config.storage] = true; - } - - const { packages } = this.config; - - if (packages) { - const listPackagesConf = Object.keys(packages); - - listPackagesConf.map(pkg => { - if (packages[pkg].storage) { - storages[packages[pkg].storage] = true; - } - }); - } - - return storages; - } - /** * Walks through each package and calls `on_package` on them. * @param {*} onPackage diff --git a/test/functional/package/access.js b/test/functional/package/access.js index e92947cc9..6d584924b 100644 --- a/test/functional/package/access.js +++ b/test/functional/package/access.js @@ -13,17 +13,17 @@ export default function(server) { * Check whether the user is allowed to fetch packages * @param auth {object} disable auth * @param pkg {string} package name - * @param ok {boolean} + * @param status {boolean} */ - function checkAccess(auth, pkg, ok) { + function checkAccess(auth, pkg, status) { test( - `${(ok ? 'allows' : 'forbids')} access ${auth} to ${pkg}`, () => { + `${(status ? 'allows' : 'forbids')} access ${auth} to ${pkg}`, () => { server.authstr = auth ? buildAccesToken(auth) : undefined; const req = server.getPackage(pkg); - if (ok) { + if (status === HTTP_STATUS.NOT_FOUND) { return req.status(HTTP_STATUS.NOT_FOUND).body_error(API_ERROR.NO_PACKAGE); - } else { + } else if (status === HTTP_STATUS.FORBIDDEN) { return req.status(HTTP_STATUS.FORBIDDEN).body_error(API_ERROR.NOT_ALLOWED); } } @@ -34,16 +34,20 @@ export default function(server) { * Check whether the user is allowed to publish packages * @param auth {object} disable auth * @param pkg {string} package name - * @param ok {boolean} + * @param status {boolean} */ - function checkPublish(auth, pkg, ok) { - test(`${(ok ? 'allows' : 'forbids')} publish ${auth} to ${pkg}`, () => { + function checkPublish(auth, pkg, status) { + test(`${(status ? 'allows' : 'forbids')} publish ${auth} to ${pkg}`, () => { server.authstr = auth ? buildAccesToken(auth) : undefined; const req = server.putPackage(pkg, require('../fixtures/package')(pkg)); - if (ok) { - return req.status(HTTP_STATUS.NOT_FOUND).body_error(/this package cannot be added/); - } else { - return req.status(HTTP_STATUS.FORBIDDEN).body_error(/not allowed to publish package/); + if (status === HTTP_STATUS.NOT_FOUND) { + return req.status(HTTP_STATUS.NOT_FOUND).body_error(API_ERROR.PACKAGE_CANNOT_BE_ADDED); + } else if (status === HTTP_STATUS.FORBIDDEN) { + return req.status(HTTP_STATUS.FORBIDDEN).body_error(API_ERROR.NOT_ALLOWED_PUBLISH); + } else if (status === HTTP_STATUS.CREATED) { + return req.status(HTTP_STATUS.CREATED); + } else if (status === HTTP_STATUS.CONFLICT) { + return req.status(HTTP_STATUS.CONFLICT); } }); } @@ -60,39 +64,39 @@ export default function(server) { const testOnlyAuth = 'test-only-auth'; describe('all are allowed to access', () => { - checkAccess(validCredentials, testAccessOnly, true); - checkAccess(undefined, testAccessOnly, true); - checkAccess(badCredentials, testAccessOnly, true); - checkPublish(validCredentials, testAccessOnly, false); - checkPublish(undefined, testAccessOnly, false); - checkPublish(badCredentials, testAccessOnly, false); + checkAccess(validCredentials, testAccessOnly, HTTP_STATUS.NOT_FOUND); + checkAccess(undefined, testAccessOnly, HTTP_STATUS.NOT_FOUND); + checkAccess(badCredentials, testAccessOnly, HTTP_STATUS.NOT_FOUND); + checkPublish(validCredentials, testAccessOnly, HTTP_STATUS.FORBIDDEN); + checkPublish(undefined, testAccessOnly, HTTP_STATUS.FORBIDDEN); + checkPublish(badCredentials, testAccessOnly, HTTP_STATUS.FORBIDDEN); }); describe('all are allowed to publish', () => { - checkAccess(validCredentials, testPublishOnly, false); - checkAccess(undefined, testPublishOnly, false); - checkAccess(badCredentials, testPublishOnly, false); - checkPublish(validCredentials, testPublishOnly, true); - checkPublish(undefined, testPublishOnly, true); - checkPublish(badCredentials, testPublishOnly, true); + checkAccess(validCredentials, testPublishOnly, HTTP_STATUS.FORBIDDEN); + checkAccess(undefined, testPublishOnly, HTTP_STATUS.FORBIDDEN); + checkAccess(badCredentials, testPublishOnly, HTTP_STATUS.FORBIDDEN); + checkPublish(validCredentials, testPublishOnly, HTTP_STATUS.CREATED); + checkPublish(undefined, testPublishOnly, HTTP_STATUS.CONFLICT); + checkPublish(badCredentials, testPublishOnly, HTTP_STATUS.CONFLICT); }); describe('only user "test" is allowed to publish and access', () => { - checkAccess(validCredentials, testOnlyTest, true); - checkAccess(undefined, testOnlyTest, false); - checkAccess(badCredentials, testOnlyTest, false); - checkPublish(validCredentials, testOnlyTest, true); - checkPublish(undefined, testOnlyTest, false); - checkPublish(badCredentials, testOnlyTest, false); + checkAccess(validCredentials, testOnlyTest, HTTP_STATUS.NOT_FOUND); + checkAccess(undefined, testOnlyTest, HTTP_STATUS.FORBIDDEN); + checkAccess(badCredentials, testOnlyTest, HTTP_STATUS.FORBIDDEN); + checkPublish(validCredentials, testOnlyTest, HTTP_STATUS.CREATED); + checkPublish(undefined, testOnlyTest, HTTP_STATUS.FORBIDDEN); + checkPublish(badCredentials, testOnlyTest, HTTP_STATUS.FORBIDDEN); }); describe('only authenticated users are allowed', () => { - checkAccess(validCredentials, testOnlyAuth, true); - checkAccess(undefined, testOnlyAuth, false); - checkAccess(badCredentials, testOnlyAuth, false); - checkPublish(validCredentials, testOnlyAuth, true); - checkPublish(undefined, testOnlyAuth, false); - checkPublish(badCredentials, testOnlyAuth, false); + checkAccess(validCredentials, testOnlyAuth, HTTP_STATUS.NOT_FOUND); + checkAccess(undefined, testOnlyAuth, HTTP_STATUS.FORBIDDEN); + checkAccess(badCredentials, testOnlyAuth, HTTP_STATUS.FORBIDDEN); + checkPublish(validCredentials, testOnlyAuth, HTTP_STATUS.CREATED); + checkPublish(undefined, testOnlyAuth, HTTP_STATUS.FORBIDDEN); + checkPublish(badCredentials, testOnlyAuth, HTTP_STATUS.FORBIDDEN); }); }); } diff --git a/test/functional/sanity/nullstorage.js b/test/functional/sanity/nullstorage.js index 905080328..1b5d395be 100644 --- a/test/functional/sanity/nullstorage.js +++ b/test/functional/sanity/nullstorage.js @@ -13,6 +13,7 @@ export default function (server, server2) { const PKG_NAME = 'test-nullstorage2'; const PKG_VERSION = '0.0.1'; + // const TARBALL = `${PKG_NAME}-file.name`; describe('should test a scenario when tarball is being fetch from uplink', () => { @@ -38,8 +39,7 @@ export default function (server, server2) { describe(`should succesfully publish ${PKG_NAME} package on server2`, () => { beforeAll(function() { - return server2.putTarball(PKG_NAME, TARBALL, getBinary()) - .status(HTTP_STATUS.CREATED).body_ok(/.*/); + return server2.putTarball(PKG_NAME, TARBALL, getBinary()).status(HTTP_STATUS.CREATED).body_ok(/.*/); }); beforeAll(function() { diff --git a/test/functional/store/config-1.yaml b/test/functional/store/config-1.yaml index 20e12b73d..7cf35d2b0 100644 --- a/test/functional/store/config-1.yaml +++ b/test/functional/store/config-1.yaml @@ -19,6 +19,7 @@ uplinks: timeout: 100ms server2: url: http://localhost:55552/ + maxage: 0 server3: url: http://localhost:55553/ baduplink: @@ -88,7 +89,7 @@ packages: access: $all publish: $all proxy: server2 - storage: false + storage: sub_storage 'baduplink': access: $all @@ -98,22 +99,22 @@ packages: 'test-access-only': access: $all publish: nobody - storage: false + storage: sub_storage 'test-publish-only': access: nobody publish: $all - storage: false + storage: sub_storage 'test-only-test': access: test publish: test - storage: false + storage: sub_storage 'test-only-auth': access: $authenticated publish: $authenticated - storage: false + storage: sub_storage '*': access: test $anonymous diff --git a/yarn.lock b/yarn.lock index aa110d803..a68bf1594 100644 Binary files a/yarn.lock and b/yarn.lock differ