2018-03-11 12:55:19 -05:00
|
|
|
import request from 'supertest';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import path from 'path';
|
|
|
|
import rimraf from 'rimraf';
|
|
|
|
|
2018-04-30 08:41:04 -05:00
|
|
|
import {HEADERS} from '../../src/lib/constants';
|
2018-03-11 12:55:19 -05:00
|
|
|
import configDefault from './partials/config/access';
|
|
|
|
import Config from '../../src/lib/config';
|
2018-04-21 11:36:06 -05:00
|
|
|
import endPointAPI from '../../src/api/index';
|
2018-03-11 12:55:19 -05:00
|
|
|
|
|
|
|
require('../../src/lib/logger').setup([]);
|
|
|
|
|
|
|
|
describe('api with no limited access configuration', () => {
|
|
|
|
let config;
|
|
|
|
let app;
|
|
|
|
|
|
|
|
beforeAll(function(done) {
|
2018-03-11 13:25:13 -05:00
|
|
|
const store = path.join(__dirname, './partials/store/access-storage');
|
2018-04-21 11:36:06 -05:00
|
|
|
rimraf(store, async () => {
|
2018-03-11 12:55:19 -05:00
|
|
|
const configForTest = _.clone(configDefault);
|
|
|
|
configForTest.auth = {
|
|
|
|
htpasswd: {
|
|
|
|
file: './access-storage/htpasswd-access-test'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
configForTest.self_path = store;
|
|
|
|
config = new Config(configForTest);
|
2018-04-21 11:36:06 -05:00
|
|
|
app = await endPointAPI(config);
|
2018-03-11 12:55:19 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-11 13:25:13 -05:00
|
|
|
afterAll(function(done) {
|
|
|
|
const store = path.join(__dirname, './partials/store/access-storage');
|
|
|
|
rimraf(store, (err) => {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-11 12:55:19 -05:00
|
|
|
describe('test proxy packages partially restricted', () => {
|
|
|
|
|
|
|
|
test('should test fails on fetch endpoint /-/jquery', (done) => {
|
|
|
|
request(app)
|
|
|
|
.get('/jquery')
|
2018-04-30 08:41:04 -05:00
|
|
|
.set('content-type', HEADERS.JSON_CHARSET)
|
2018-03-11 12:55:19 -05:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(404)
|
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-11 13:25:13 -05:00
|
|
|
test('should success on fetch endpoint /-/vue', (done) => {
|
2018-03-11 12:55:19 -05:00
|
|
|
request(app)
|
2018-03-11 13:25:13 -05:00
|
|
|
.get('/vue')
|
2018-04-30 08:41:04 -05:00
|
|
|
.set('content-type', HEADERS.JSON_CHARSET)
|
2018-03-11 12:55:19 -05:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200)
|
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|