From 3929633f7e5293ad5d119fd3a46b80ac368e9c63 Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sun, 19 May 2019 23:07:17 +0200 Subject: [PATCH] test: relocate test --- .gitignore | 1 + .../__snapshots__/publish.spec.js.snap} | 0 .../publish.spec.js} | 4 +-- .../modules/{ => auth}/auth-utils.spec.js | 32 +++++++++---------- test/unit/modules/{ => plugin}/auth.spec.js | 12 +++---- test/unit/modules/plugin/helper/plugin.js | 12 +++++++ test/unit/modules/{ => storage}/store.spec.js | 20 ++++++------ test/unit/modules/{ => web}/api.web.spec.js | 24 +++++++------- test/unit/partials/config/plugin.js | 10 ------ 9 files changed, 59 insertions(+), 56 deletions(-) rename test/unit/modules/{__snapshots__/api.publish.spec.js.snap => api/__snapshots__/publish.spec.js.snap} (100%) rename test/unit/modules/{api.publish.spec.js => api/publish.spec.js} (97%) rename test/unit/modules/{ => auth}/auth-utils.spec.js (91%) rename test/unit/modules/{ => plugin}/auth.spec.js (91%) create mode 100644 test/unit/modules/plugin/helper/plugin.js rename test/unit/modules/{ => storage}/store.spec.js (84%) rename test/unit/modules/{ => web}/api.web.spec.js (90%) delete mode 100644 test/unit/partials/config/plugin.js diff --git a/.gitignore b/.gitignore index 62c72c80d..ca19b8f3b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ build/ ### Test test/unit/partials/store/test-*-storage/* +test/unit/partials/store/*-storage/* test/unit/partials/store/storage_default_storage/* .verdaccio-db.json .sinopia-db.json diff --git a/test/unit/modules/__snapshots__/api.publish.spec.js.snap b/test/unit/modules/api/__snapshots__/publish.spec.js.snap similarity index 100% rename from test/unit/modules/__snapshots__/api.publish.spec.js.snap rename to test/unit/modules/api/__snapshots__/publish.spec.js.snap diff --git a/test/unit/modules/api.publish.spec.js b/test/unit/modules/api/publish.spec.js similarity index 97% rename from test/unit/modules/api.publish.spec.js rename to test/unit/modules/api/publish.spec.js index 033ff2994..a0cea164c 100644 --- a/test/unit/modules/api.publish.spec.js +++ b/test/unit/modules/api/publish.spec.js @@ -1,8 +1,8 @@ /** * @prettier */ -import { addVersion, uploadPackageTarball, removeTarball, unPublishPackage, publishPackage } from '../../../src/api/endpoint/api/publish'; -import { HTTP_STATUS, API_ERROR } from '../../../src/lib/constants'; +import { addVersion, uploadPackageTarball, removeTarball, unPublishPackage, publishPackage } from '../../../../src/api/endpoint/api/publish'; +import { HTTP_STATUS, API_ERROR } from '../../../../src/lib/constants'; const REVISION_MOCK = '15-e53a77096b0ee33e'; diff --git a/test/unit/modules/auth-utils.spec.js b/test/unit/modules/auth/auth-utils.spec.js similarity index 91% rename from test/unit/modules/auth-utils.spec.js rename to test/unit/modules/auth/auth-utils.spec.js index b630b5b85..874aafd38 100644 --- a/test/unit/modules/auth-utils.spec.js +++ b/test/unit/modules/auth/auth-utils.spec.js @@ -1,25 +1,25 @@ // @flow import _ from 'lodash'; -import Auth from '../../../src/lib/auth'; -import {CHARACTER_ENCODING} from '../../../src/lib/constants'; +import Auth from '../../../../src/lib/auth'; +import {CHARACTER_ENCODING, TOKEN_BEARER} from '../../../../src/lib/constants'; // $FlowFixMe -import configExample from '../partials/config/index'; -import AppConfig from '../../../src/lib/config'; -import {setup} from '../../../src/lib/logger'; +import configExample from '../../partials/config'; +import AppConfig from '../../../../src/lib/config'; +import {setup} from '../../../../src/lib/logger'; -import {convertPayloadToBase64, parseConfigFile} from '../../../src/lib/utils'; +import {buildToken, convertPayloadToBase64, parseConfigFile} from '../../../../src/lib/utils'; import { buildUserBuffer, getApiToken, getAuthenticatedMessage, getMiddlewareCredentials, getSecurity -} from '../../../src/lib/auth-utils'; -import {aesDecrypt, verifyPayload} from '../../../src/lib/crypto-utils'; -import {parseConfigurationFile} from '../__helper'; +} from '../../../../src/lib/auth-utils'; +import {aesDecrypt, verifyPayload} from '../../../../src/lib/crypto-utils'; +import {parseConfigurationFile} from '../../__helper'; -import type {IAuth, } from '../../../types/index'; +import type {IAuth, } from '../../../../types'; import type {Config, Security, RemoteUser} from '@verdaccio/types'; setup([]); @@ -181,7 +181,7 @@ describe('Auth utilities', () => { 'test', 'test', secret, 'aesEncrypt', 'jwtEncrypt'); const config: Config = getConfig('security-legacy', secret); const security: Security = getSecurity(config); - const credentials = getMiddlewareCredentials(security, 'BAD_SECRET', `Bearer ${token}`); + const credentials = getMiddlewareCredentials(security, 'BAD_SECRET', buildToken(TOKEN_BEARER, token)); expect(credentials).not.toBeDefined(); }); @@ -191,7 +191,7 @@ describe('Auth utilities', () => { 'test', 'test', secret, 'aesEncrypt', 'jwtEncrypt'); const config: Config = getConfig('security-legacy', secret); const security: Security = getSecurity(config); - const credentials = getMiddlewareCredentials(security, secret, `BAD_SCHEME ${token}`); + const credentials = getMiddlewareCredentials(security, secret, buildToken('BAD_SCHEME', token)); expect(credentials).not.toBeDefined(); }); @@ -201,7 +201,7 @@ describe('Auth utilities', () => { const auth: IAuth = new Auth(config); const token = auth.aesEncrypt(new Buffer(`corruptedBuffer`)).toString('base64'); const security: Security = getSecurity(config); - const credentials = getMiddlewareCredentials(security, secret, `Bearer ${token}`); + const credentials = getMiddlewareCredentials(security, secret, buildToken(TOKEN_BEARER, token)); expect(credentials).not.toBeDefined(); }); }); @@ -210,7 +210,7 @@ describe('Auth utilities', () => { test('should return anonymous whether token is corrupted', () => { const config: Config = getConfig('security-jwt', '12345'); const security: Security = getSecurity(config); - const credentials = getMiddlewareCredentials(security, '12345', 'Bearer fakeToken'); + const credentials = getMiddlewareCredentials(security, '12345', buildToken(TOKEN_BEARER, 'fakeToken')); expect(credentials).toBeDefined(); // $FlowFixMe @@ -224,7 +224,7 @@ describe('Auth utilities', () => { test('should return anonymous whether token and scheme are corrupted', () => { const config: Config = getConfig('security-jwt', '12345'); const security: Security = getSecurity(config); - const credentials = getMiddlewareCredentials(security, '12345', 'FakeScheme fakeToken'); + const credentials = getMiddlewareCredentials(security, '12345', buildToken('FakeScheme', 'fakeToken')); expect(credentials).not.toBeDefined(); }); @@ -236,7 +236,7 @@ describe('Auth utilities', () => { const token = await signCredentials('security-jwt', user, 'secretTest', secret, 'jwtEncrypt', 'aesEncrypt'); const security: Security = getSecurity(config); - const credentials = getMiddlewareCredentials(security, secret, `Bearer ${token}`); + const credentials = getMiddlewareCredentials(security, secret, buildToken(TOKEN_BEARER, token)); expect(credentials).toBeDefined(); // $FlowFixMe expect(credentials.name).toEqual(user); diff --git a/test/unit/modules/auth.spec.js b/test/unit/modules/plugin/auth.spec.js similarity index 91% rename from test/unit/modules/auth.spec.js rename to test/unit/modules/plugin/auth.spec.js index 4f26ec013..f5e716957 100644 --- a/test/unit/modules/auth.spec.js +++ b/test/unit/modules/plugin/auth.spec.js @@ -1,14 +1,14 @@ import _ from 'lodash'; // @flow -import Auth from '../../../src/lib/auth'; +import Auth from '../../../../src/lib/auth'; // $FlowFixMe -import _configExample from '../partials/config/index'; +import _configExample from '../../partials/config'; // $FlowFixMe -import _configPlugins from '../partials/config/plugin'; -import AppConfig from '../../../src/lib/config'; -import {setup} from '../../../src/lib/logger'; +import _configPlugins from './helper/plugin'; +import AppConfig from '../../../../src/lib/config'; +import {setup} from '../../../../src/lib/logger'; -import type {IAuth} from '../../../types/index'; +import type {IAuth} from '../../../../types'; import type {Config} from '@verdaccio/types'; setup([]); diff --git a/test/unit/modules/plugin/helper/plugin.js b/test/unit/modules/plugin/helper/plugin.js new file mode 100644 index 000000000..5582d408c --- /dev/null +++ b/test/unit/modules/plugin/helper/plugin.js @@ -0,0 +1,12 @@ + +import path from 'path'; +import config from '../../../partials/config'; + +const authProfileConf = { + ...config(), + auth: { + [`${path.join(__dirname, '../../../partials/plugin/authenticate')}`]: { } + } +}; + +export default authProfileConf; diff --git a/test/unit/modules/store.spec.js b/test/unit/modules/storage/store.spec.js similarity index 84% rename from test/unit/modules/store.spec.js rename to test/unit/modules/storage/store.spec.js index d730d74ec..cc2f21f5d 100644 --- a/test/unit/modules/store.spec.js +++ b/test/unit/modules/storage/store.spec.js @@ -4,20 +4,20 @@ import path from 'path'; import fs from 'fs'; import rimraf from 'rimraf'; // $FlowFixMe -import configExample from '../partials/config/index'; -import AppConfig from '../../../src/lib/config'; -import Storage from '../../../src/lib/storage'; -import {setup} from '../../../src/lib/logger'; +import configExample from '../../partials/config'; +import AppConfig from '../../../../src/lib/config'; +import Storage from '../../../../src/lib/storage'; +import {setup} from '../../../../src/lib/logger'; import type {Config} from '@verdaccio/types'; -import type {IStorageHandler} from '../../../types/index'; -import {API_ERROR, HTTP_STATUS} from '../../../src/lib/constants'; -import {mockServer} from '../__helper/mock'; -import {DOMAIN_SERVERS} from '../../functional/config.functional'; +import type {IStorageHandler} from '../../../../types'; +import {API_ERROR, HTTP_STATUS} from '../../../../src/lib/constants'; +import {mockServer} from '../../__helper/mock'; +import {DOMAIN_SERVERS} from '../../../functional/config.functional'; setup([]); -const storagePath = path.join(__dirname, '../partials/store/test-storage-store.spec'); +const storagePath = path.join(__dirname, '../../partials/store/test-storage-store.spec'); const mockServerPort: number = 55548; const generateStorage = async function(port = mockServerPort) { const storageConfig = configExample({ @@ -99,7 +99,7 @@ describe('StorageTest', () => { test('should not touch if the package exists and has no uplinks', async (done) => { const storage: IStorageHandler = await generateStorage(); - const metadataSource = path.join(__dirname, '../partials/metadata'); + const metadataSource = path.join(__dirname, '../../partials/metadata'); const metadataPath = path.join(storagePath, 'npm_test/package.json'); fs.mkdirSync(path.join(storagePath, 'npm_test')); diff --git a/test/unit/modules/api.web.spec.js b/test/unit/modules/web/api.web.spec.js similarity index 90% rename from test/unit/modules/api.web.spec.js rename to test/unit/modules/web/api.web.spec.js index 4a40a5ef6..526f035fd 100644 --- a/test/unit/modules/api.web.spec.js +++ b/test/unit/modules/web/api.web.spec.js @@ -2,17 +2,17 @@ import request from 'supertest'; import path from 'path'; import rimraf from 'rimraf'; -import configDefault from '../partials/config/index'; -import publishMetadata from '../partials/publish-api'; -import forbiddenPlace from '../partials/forbidden-place'; -import endPointAPI from '../../../src/api/index'; +import configDefault from '../../partials/config'; +import publishMetadata from '../../partials/publish-api'; +import forbiddenPlace from '../../partials/forbidden-place'; +import endPointAPI from '../../../../src/api'; -import { HEADERS, API_ERROR, HTTP_STATUS, HEADER_TYPE, DIST_TAGS} from '../../../src/lib/constants'; -import {DOMAIN_SERVERS} from '../../functional/config.functional'; -import {mockServer} from '../__helper/mock'; -import {addUser} from '../__helper/api'; +import { HEADERS, API_ERROR, HTTP_STATUS, HEADER_TYPE, DIST_TAGS} from '../../../../src/lib/constants'; +import {DOMAIN_SERVERS} from '../../../functional/config.functional'; +import {mockServer} from '../../__helper/mock'; +import {addUser} from '../../__helper/api'; -require('../../../src/lib/logger').setup([]); +require('../../../../src/lib/logger').setup([]); const credentials = { name: 'user-web', password: 'secretPass' }; describe('endpoint web unit test', () => { @@ -20,16 +20,16 @@ describe('endpoint web unit test', () => { let mockRegistry; beforeAll(function(done) { - const store = path.join(__dirname, '../store/test-storage-web'); + const store = path.join(__dirname, '../../partials/store/web-api-storage'); const mockServerPort = 55544; rimraf(store, async () => { const configForTest = configDefault({ auth: { htpasswd: { - file: './test-storage-web/.htpasswd' + file: './web-api-storage/.htpasswd-web-api' } }, - storage: path.join(__dirname, '../store/test-storage-web'), + storage: store, uplinks: { npmjs: { url: `http://${DOMAIN_SERVERS}:${mockServerPort}` diff --git a/test/unit/partials/config/plugin.js b/test/unit/partials/config/plugin.js deleted file mode 100644 index c383294b0..000000000 --- a/test/unit/partials/config/plugin.js +++ /dev/null @@ -1,10 +0,0 @@ - -import path from 'path'; -import config from './index'; - -module.exports = { - ...config(), - auth: { - [`${path.join(__dirname, '../plugin/authenticate')}`]: { } - } -};