diff --git a/package.json b/package.json index 467a6f0b1..9a5f413a8 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "@verdaccio/file-locking": "0.0.7", - "@verdaccio/local-storage": "1.2.0", + "@verdaccio/local-storage": "2.0.0-beta.0", "@verdaccio/streams": "2.0.0-beta.0", "JSONStream": "1.3.4", "async": "2.6.1", 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 276bb4e36..3d62a56bc 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..9260c79b4 100644 --- a/test/functional/package/access.js +++ b/test/functional/package/access.js @@ -5,6 +5,7 @@ import {CREDENTIALS} from "../config.functional"; export default function(server) { describe('package access control', () => { + jest.setTimeout(20000000); const buildAccesToken = (auth) => { return buildToken(TOKEN_BASIC, `${(new Buffer(auth).toString('base64'))}`); }; @@ -13,17 +14,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 +35,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 +65,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/search/simple.search.js b/test/functional/search/simple.search.js index 51cd250d9..2d5e881fb 100644 --- a/test/functional/search/simple.search.js +++ b/test/functional/search/simple.search.js @@ -5,6 +5,7 @@ const pkgExample = require('./search.json'); export default function(server, server2, express) { describe('should test search a published package', () => { + jest.setTimeout(20000000); const PKG_NAME = 'testpkg-search'; beforeAll(function() { @@ -15,6 +16,7 @@ export default function(server, server2, express) { describe('should test simple search', () => { const check = (medatada) => { + console.log('medatada->', medatada); medatada[PKG_NAME].time.modified = '2014-10-02T07:07:51.000Z'; expect(medatada[PKG_NAME]).toEqual( { 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/test/lib/request.js b/test/lib/request.js index 41e81a0e9..9d7c31d9e 100644 --- a/test/lib/request.js +++ b/test/lib/request.js @@ -19,6 +19,7 @@ export class PromiseAssert extends Promise implements IRequestPromise{ return injectResponse(this, this.then(function(body) { try { + // console.log("selfData.response.statusCode", selfData.response.statusCode); assert.equal(selfData.response.statusCode, expected); } catch(err) { selfData.error.message = err.message; diff --git a/test/lib/server_process.js b/test/lib/server_process.js index 7b7b8122d..30875ba7e 100644 --- a/test/lib/server_process.js +++ b/test/lib/server_process.js @@ -47,7 +47,7 @@ export default class VerdaccioProcess implements IServerProcess { _start(verdaccioPath: string, resolve: Function, reject: Function) { const verdaccioRegisterWrap: string = path.join(__dirname, verdaccioPath); let childOptions = { - silent: this.silence + silent: false }; if (this.isDebug) { diff --git a/test/unit/webui/components/__snapshots__/packagelist.spec.js.snap b/test/unit/webui/components/__snapshots__/packagelist.spec.js.snap index 722652740..68256a02f 100644 --- a/test/unit/webui/components/__snapshots__/packagelist.spec.js.snap +++ b/test/unit/webui/components/__snapshots__/packagelist.spec.js.snap @@ -1,3 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[` component should load the component with packages 1`] = `""`; +exports[` component should load the component with packages 1`] = `""`; diff --git a/yarn.lock b/yarn.lock index 429b88b44..618ebd0d2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1224,23 +1224,18 @@ lockfile "1.0.3" lodash "4.17.10" -"@verdaccio/local-storage@1.2.0": - version "1.2.0" - resolved "https://registry.verdaccio.org/@verdaccio%2flocal-storage/-/local-storage-1.2.0.tgz#dccbfd0710639c197567c555374eb926c535b071" - integrity sha512-ybuNgcHJg4GWm47TrB7NVTJk9eiuSwmby3ed8mlDUp0gsn383AF/5rcHuw+yGMm3/5d/uhuGDDyf9kWhjCzpaw== +"@verdaccio/local-storage@2.0.0-beta.0": + version "2.0.0-beta.0" + resolved "http://localhost:4873/@verdaccio%2flocal-storage/-/local-storage-2.0.0-beta.0.tgz#130e8ddca1831a6c0e3bfd5abf7db219be4c1ed8" + integrity sha512-LGZS8l4TLvprVq82IZFPXyYKMgK4WFWSuujRO7ATtF6WxzstiamIE/B44r3SZx4RwJFtFuaKh16NYmNkjbnqcg== dependencies: "@verdaccio/file-locking" "0.0.7" - "@verdaccio/streams" "1.0.0" + "@verdaccio/streams" "2.0.0-beta.0" async "2.6.1" - http-errors "1.7.0" - lodash "4.17.10" + http-errors "1.7.1" + lodash "4.17.11" mkdirp "0.5.1" -"@verdaccio/streams@1.0.0": - version "1.0.0" - resolved "https://registry.verdaccio.org/@verdaccio%2fstreams/-/streams-1.0.0.tgz#d5d24c6747208728b9fd16b908e3932c3fb1f864" - integrity sha512-AjEo5LXk4Yf0SaXSc3y4i1t+wxY552O7WrVJPtnC6H7nUsSrygg/ODCG1RSKelskOq6b5p/LyXnsTkmCFXyjDQ== - "@verdaccio/streams@2.0.0-beta.0": version "2.0.0-beta.0" resolved "https://registry.verdaccio.org/@verdaccio%2fstreams/-/streams-2.0.0-beta.0.tgz#af8c7e673a3c368deacc8024c6f5671aa2ec32ac" @@ -6113,17 +6108,6 @@ http-errors@1.6.3, http-errors@~1.6.2, http-errors@~1.6.3: setprototypeof "1.1.0" statuses ">= 1.4.0 < 2" -http-errors@1.7.0: - version "1.7.0" - resolved "https://registry.verdaccio.org/http-errors/-/http-errors-1.7.0.tgz#b6d36492a201c7888bdcb5dd0471140423c4ad2a" - integrity sha512-hz3BtSHB7Z6dNWzYc+gUbWqG4dIpJedwwOhe1cvGUq5tGmcTTIRkPiAbyh/JlZx+ksSJyGJlgcHo5jGahiXnKw== - dependencies: - depd "~1.1.2" - inherits "2.0.3" - setprototypeof "1.1.0" - statuses ">= 1.5.0 < 2" - toidentifier "1.0.0" - http-errors@1.7.1: version "1.7.1" resolved "https://registry.verdaccio.org/http-errors/-/http-errors-1.7.1.tgz#6a4ffe5d35188e1c39f872534690585852e1f027"