2018-03-11 18:55:19 +01:00
|
|
|
import request from 'supertest';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import path from 'path';
|
|
|
|
import rimraf from 'rimraf';
|
|
|
|
|
2018-10-05 08:20:43 +02:00
|
|
|
import { HEADERS, HTTP_STATUS } from '../../../src/lib/constants';
|
2018-06-30 18:10:05 +02:00
|
|
|
import configDefault from '../partials/config/config_access';
|
2018-06-17 13:34:59 +02:00
|
|
|
import endPointAPI from '../../../src/api/index';
|
2018-06-30 18:10:05 +02:00
|
|
|
import {mockServer} from './mock';
|
|
|
|
import {DOMAIN_SERVERS} from '../../functional/config.functional';
|
2018-03-11 18:55:19 +01:00
|
|
|
|
2018-06-17 13:34:59 +02:00
|
|
|
require('../../../src/lib/logger').setup([]);
|
2018-03-11 18:55:19 +01:00
|
|
|
|
|
|
|
describe('api with no limited access configuration', () => {
|
|
|
|
let app;
|
2018-06-30 18:10:05 +02:00
|
|
|
let mockRegistry;
|
2018-03-11 18:55:19 +01:00
|
|
|
|
|
|
|
beforeAll(function(done) {
|
2018-06-30 18:10:05 +02:00
|
|
|
const mockServerPort = 55530;
|
2018-03-11 19:25:13 +01:00
|
|
|
const store = path.join(__dirname, './partials/store/access-storage');
|
2018-04-21 18:36:06 +02:00
|
|
|
rimraf(store, async () => {
|
2019-02-24 23:20:25 +01:00
|
|
|
const configForTest = _.assign({}, _.cloneDeep(configDefault), {
|
|
|
|
auth: {
|
|
|
|
htpasswd: {
|
|
|
|
file: './access-storage/htpasswd-access-test'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
self_path: store,
|
|
|
|
uplinks: {
|
|
|
|
npmjs: {
|
|
|
|
url: `http://${DOMAIN_SERVERS}:${mockServerPort}`
|
|
|
|
}
|
2018-03-11 18:55:19 +01:00
|
|
|
}
|
2019-02-24 23:20:25 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
app = await endPointAPI(configForTest);
|
2018-06-30 18:10:05 +02:00
|
|
|
mockRegistry = await mockServer(mockServerPort).init();
|
2018-03-11 18:55:19 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-11 19:25:13 +01:00
|
|
|
afterAll(function(done) {
|
|
|
|
const store = path.join(__dirname, './partials/store/access-storage');
|
|
|
|
rimraf(store, (err) => {
|
|
|
|
if (err) {
|
2018-06-30 18:10:05 +02:00
|
|
|
mockRegistry[0].stop();
|
2018-03-11 19:25:13 +01:00
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2018-06-30 18:10:05 +02:00
|
|
|
mockRegistry[0].stop();
|
2018-03-11 19:25:13 +01:00
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-11 18:55:19 +01:00
|
|
|
describe('test proxy packages partially restricted', () => {
|
|
|
|
|
|
|
|
test('should test fails on fetch endpoint /-/jquery', (done) => {
|
|
|
|
request(app)
|
|
|
|
.get('/jquery')
|
2018-04-30 15:41:04 +02:00
|
|
|
.set('content-type', HEADERS.JSON_CHARSET)
|
2018-03-11 18:55:19 +01:00
|
|
|
.expect('Content-Type', /json/)
|
2018-10-05 08:20:43 +02:00
|
|
|
.expect(HTTP_STATUS.NOT_FOUND)
|
2018-03-11 18:55:19 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-11 19:25:13 +01:00
|
|
|
test('should success on fetch endpoint /-/vue', (done) => {
|
2018-03-11 18:55:19 +01:00
|
|
|
request(app)
|
2018-03-11 19:25:13 +01:00
|
|
|
.get('/vue')
|
2018-04-30 15:41:04 +02:00
|
|
|
.set('content-type', HEADERS.JSON_CHARSET)
|
2018-03-11 18:55:19 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|