mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
test: relocate test
This commit is contained in:
parent
b4c42c1a78
commit
3929633f7e
9 changed files with 59 additions and 56 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,6 +6,7 @@ build/
|
||||||
### Test
|
### Test
|
||||||
|
|
||||||
test/unit/partials/store/test-*-storage/*
|
test/unit/partials/store/test-*-storage/*
|
||||||
|
test/unit/partials/store/*-storage/*
|
||||||
test/unit/partials/store/storage_default_storage/*
|
test/unit/partials/store/storage_default_storage/*
|
||||||
.verdaccio-db.json
|
.verdaccio-db.json
|
||||||
.sinopia-db.json
|
.sinopia-db.json
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
/**
|
/**
|
||||||
* @prettier
|
* @prettier
|
||||||
*/
|
*/
|
||||||
import { addVersion, uploadPackageTarball, removeTarball, unPublishPackage, publishPackage } from '../../../src/api/endpoint/api/publish';
|
import { addVersion, uploadPackageTarball, removeTarball, unPublishPackage, publishPackage } from '../../../../src/api/endpoint/api/publish';
|
||||||
import { HTTP_STATUS, API_ERROR } from '../../../src/lib/constants';
|
import { HTTP_STATUS, API_ERROR } from '../../../../src/lib/constants';
|
||||||
|
|
||||||
const REVISION_MOCK = '15-e53a77096b0ee33e';
|
const REVISION_MOCK = '15-e53a77096b0ee33e';
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import Auth from '../../../src/lib/auth';
|
import Auth from '../../../../src/lib/auth';
|
||||||
import {CHARACTER_ENCODING} from '../../../src/lib/constants';
|
import {CHARACTER_ENCODING, TOKEN_BEARER} from '../../../../src/lib/constants';
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
import configExample from '../partials/config/index';
|
import configExample from '../../partials/config';
|
||||||
import AppConfig from '../../../src/lib/config';
|
import AppConfig from '../../../../src/lib/config';
|
||||||
import {setup} from '../../../src/lib/logger';
|
import {setup} from '../../../../src/lib/logger';
|
||||||
|
|
||||||
import {convertPayloadToBase64, parseConfigFile} from '../../../src/lib/utils';
|
import {buildToken, convertPayloadToBase64, parseConfigFile} from '../../../../src/lib/utils';
|
||||||
import {
|
import {
|
||||||
buildUserBuffer,
|
buildUserBuffer,
|
||||||
getApiToken,
|
getApiToken,
|
||||||
getAuthenticatedMessage,
|
getAuthenticatedMessage,
|
||||||
getMiddlewareCredentials,
|
getMiddlewareCredentials,
|
||||||
getSecurity
|
getSecurity
|
||||||
} from '../../../src/lib/auth-utils';
|
} from '../../../../src/lib/auth-utils';
|
||||||
import {aesDecrypt, verifyPayload} from '../../../src/lib/crypto-utils';
|
import {aesDecrypt, verifyPayload} from '../../../../src/lib/crypto-utils';
|
||||||
import {parseConfigurationFile} from '../__helper';
|
import {parseConfigurationFile} from '../../__helper';
|
||||||
|
|
||||||
import type {IAuth, } from '../../../types/index';
|
import type {IAuth, } from '../../../../types';
|
||||||
import type {Config, Security, RemoteUser} from '@verdaccio/types';
|
import type {Config, Security, RemoteUser} from '@verdaccio/types';
|
||||||
|
|
||||||
setup([]);
|
setup([]);
|
||||||
|
@ -181,7 +181,7 @@ describe('Auth utilities', () => {
|
||||||
'test', 'test', secret, 'aesEncrypt', 'jwtEncrypt');
|
'test', 'test', secret, 'aesEncrypt', 'jwtEncrypt');
|
||||||
const config: Config = getConfig('security-legacy', secret);
|
const config: Config = getConfig('security-legacy', secret);
|
||||||
const security: Security = getSecurity(config);
|
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();
|
expect(credentials).not.toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ describe('Auth utilities', () => {
|
||||||
'test', 'test', secret, 'aesEncrypt', 'jwtEncrypt');
|
'test', 'test', secret, 'aesEncrypt', 'jwtEncrypt');
|
||||||
const config: Config = getConfig('security-legacy', secret);
|
const config: Config = getConfig('security-legacy', secret);
|
||||||
const security: Security = getSecurity(config);
|
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();
|
expect(credentials).not.toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ describe('Auth utilities', () => {
|
||||||
const auth: IAuth = new Auth(config);
|
const auth: IAuth = new Auth(config);
|
||||||
const token = auth.aesEncrypt(new Buffer(`corruptedBuffer`)).toString('base64');
|
const token = auth.aesEncrypt(new Buffer(`corruptedBuffer`)).toString('base64');
|
||||||
const security: Security = getSecurity(config);
|
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();
|
expect(credentials).not.toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -210,7 +210,7 @@ describe('Auth utilities', () => {
|
||||||
test('should return anonymous whether token is corrupted', () => {
|
test('should return anonymous whether token is corrupted', () => {
|
||||||
const config: Config = getConfig('security-jwt', '12345');
|
const config: Config = getConfig('security-jwt', '12345');
|
||||||
const security: Security = getSecurity(config);
|
const security: Security = getSecurity(config);
|
||||||
const credentials = getMiddlewareCredentials(security, '12345', 'Bearer fakeToken');
|
const credentials = getMiddlewareCredentials(security, '12345', buildToken(TOKEN_BEARER, 'fakeToken'));
|
||||||
|
|
||||||
expect(credentials).toBeDefined();
|
expect(credentials).toBeDefined();
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
|
@ -224,7 +224,7 @@ describe('Auth utilities', () => {
|
||||||
test('should return anonymous whether token and scheme are corrupted', () => {
|
test('should return anonymous whether token and scheme are corrupted', () => {
|
||||||
const config: Config = getConfig('security-jwt', '12345');
|
const config: Config = getConfig('security-jwt', '12345');
|
||||||
const security: Security = getSecurity(config);
|
const security: Security = getSecurity(config);
|
||||||
const credentials = getMiddlewareCredentials(security, '12345', 'FakeScheme fakeToken');
|
const credentials = getMiddlewareCredentials(security, '12345', buildToken('FakeScheme', 'fakeToken'));
|
||||||
|
|
||||||
expect(credentials).not.toBeDefined();
|
expect(credentials).not.toBeDefined();
|
||||||
});
|
});
|
||||||
|
@ -236,7 +236,7 @@ describe('Auth utilities', () => {
|
||||||
const token = await signCredentials('security-jwt',
|
const token = await signCredentials('security-jwt',
|
||||||
user, 'secretTest', secret, 'jwtEncrypt', 'aesEncrypt');
|
user, 'secretTest', secret, 'jwtEncrypt', 'aesEncrypt');
|
||||||
const security: Security = getSecurity(config);
|
const security: Security = getSecurity(config);
|
||||||
const credentials = getMiddlewareCredentials(security, secret, `Bearer ${token}`);
|
const credentials = getMiddlewareCredentials(security, secret, buildToken(TOKEN_BEARER, token));
|
||||||
expect(credentials).toBeDefined();
|
expect(credentials).toBeDefined();
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
expect(credentials.name).toEqual(user);
|
expect(credentials.name).toEqual(user);
|
|
@ -1,14 +1,14 @@
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
// @flow
|
// @flow
|
||||||
import Auth from '../../../src/lib/auth';
|
import Auth from '../../../../src/lib/auth';
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
import _configExample from '../partials/config/index';
|
import _configExample from '../../partials/config';
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
import _configPlugins from '../partials/config/plugin';
|
import _configPlugins from './helper/plugin';
|
||||||
import AppConfig from '../../../src/lib/config';
|
import AppConfig from '../../../../src/lib/config';
|
||||||
import {setup} from '../../../src/lib/logger';
|
import {setup} from '../../../../src/lib/logger';
|
||||||
|
|
||||||
import type {IAuth} from '../../../types/index';
|
import type {IAuth} from '../../../../types';
|
||||||
import type {Config} from '@verdaccio/types';
|
import type {Config} from '@verdaccio/types';
|
||||||
|
|
||||||
setup([]);
|
setup([]);
|
12
test/unit/modules/plugin/helper/plugin.js
Normal file
12
test/unit/modules/plugin/helper/plugin.js
Normal file
|
@ -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;
|
|
@ -4,20 +4,20 @@ import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import rimraf from 'rimraf';
|
import rimraf from 'rimraf';
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
import configExample from '../partials/config/index';
|
import configExample from '../../partials/config';
|
||||||
import AppConfig from '../../../src/lib/config';
|
import AppConfig from '../../../../src/lib/config';
|
||||||
import Storage from '../../../src/lib/storage';
|
import Storage from '../../../../src/lib/storage';
|
||||||
import {setup} from '../../../src/lib/logger';
|
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';
|
||||||
import {API_ERROR, HTTP_STATUS} from '../../../src/lib/constants';
|
import {API_ERROR, HTTP_STATUS} from '../../../../src/lib/constants';
|
||||||
import {mockServer} from '../__helper/mock';
|
import {mockServer} from '../../__helper/mock';
|
||||||
import {DOMAIN_SERVERS} from '../../functional/config.functional';
|
import {DOMAIN_SERVERS} from '../../../functional/config.functional';
|
||||||
|
|
||||||
setup([]);
|
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 mockServerPort: number = 55548;
|
||||||
const generateStorage = async function(port = mockServerPort) {
|
const generateStorage = async function(port = mockServerPort) {
|
||||||
const storageConfig = configExample({
|
const storageConfig = configExample({
|
||||||
|
@ -99,7 +99,7 @@ describe('StorageTest', () => {
|
||||||
|
|
||||||
test('should not touch if the package exists and has no uplinks', async (done) => {
|
test('should not touch if the package exists and has no uplinks', async (done) => {
|
||||||
const storage: IStorageHandler = await generateStorage();
|
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');
|
const metadataPath = path.join(storagePath, 'npm_test/package.json');
|
||||||
|
|
||||||
fs.mkdirSync(path.join(storagePath, 'npm_test'));
|
fs.mkdirSync(path.join(storagePath, 'npm_test'));
|
|
@ -2,17 +2,17 @@ import request from 'supertest';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import rimraf from 'rimraf';
|
import rimraf from 'rimraf';
|
||||||
|
|
||||||
import configDefault from '../partials/config/index';
|
import configDefault from '../../partials/config';
|
||||||
import publishMetadata from '../partials/publish-api';
|
import publishMetadata from '../../partials/publish-api';
|
||||||
import forbiddenPlace from '../partials/forbidden-place';
|
import forbiddenPlace from '../../partials/forbidden-place';
|
||||||
import endPointAPI from '../../../src/api/index';
|
import endPointAPI from '../../../../src/api';
|
||||||
|
|
||||||
import { HEADERS, API_ERROR, HTTP_STATUS, HEADER_TYPE, DIST_TAGS} from '../../../src/lib/constants';
|
import { HEADERS, API_ERROR, HTTP_STATUS, HEADER_TYPE, DIST_TAGS} from '../../../../src/lib/constants';
|
||||||
import {DOMAIN_SERVERS} from '../../functional/config.functional';
|
import {DOMAIN_SERVERS} from '../../../functional/config.functional';
|
||||||
import {mockServer} from '../__helper/mock';
|
import {mockServer} from '../../__helper/mock';
|
||||||
import {addUser} from '../__helper/api';
|
import {addUser} from '../../__helper/api';
|
||||||
|
|
||||||
require('../../../src/lib/logger').setup([]);
|
require('../../../../src/lib/logger').setup([]);
|
||||||
|
|
||||||
const credentials = { name: 'user-web', password: 'secretPass' };
|
const credentials = { name: 'user-web', password: 'secretPass' };
|
||||||
describe('endpoint web unit test', () => {
|
describe('endpoint web unit test', () => {
|
||||||
|
@ -20,16 +20,16 @@ describe('endpoint web unit test', () => {
|
||||||
let mockRegistry;
|
let mockRegistry;
|
||||||
|
|
||||||
beforeAll(function(done) {
|
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;
|
const mockServerPort = 55544;
|
||||||
rimraf(store, async () => {
|
rimraf(store, async () => {
|
||||||
const configForTest = configDefault({
|
const configForTest = configDefault({
|
||||||
auth: {
|
auth: {
|
||||||
htpasswd: {
|
htpasswd: {
|
||||||
file: './test-storage-web/.htpasswd'
|
file: './web-api-storage/.htpasswd-web-api'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
storage: path.join(__dirname, '../store/test-storage-web'),
|
storage: store,
|
||||||
uplinks: {
|
uplinks: {
|
||||||
npmjs: {
|
npmjs: {
|
||||||
url: `http://${DOMAIN_SERVERS}:${mockServerPort}`
|
url: `http://${DOMAIN_SERVERS}:${mockServerPort}`
|
|
@ -1,10 +0,0 @@
|
||||||
|
|
||||||
import path from 'path';
|
|
||||||
import config from './index';
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
...config(),
|
|
||||||
auth: {
|
|
||||||
[`${path.join(__dirname, '../plugin/authenticate')}`]: { }
|
|
||||||
}
|
|
||||||
};
|
|
Loading…
Reference in a new issue