2018-03-11 12:55:19 -05:00
|
|
|
import path from 'path';
|
2021-05-13 16:13:57 -05:00
|
|
|
import request from 'supertest';
|
2018-03-11 12:55:19 -05:00
|
|
|
import rimraf from 'rimraf';
|
|
|
|
|
2019-07-16 01:40:01 -05:00
|
|
|
import { setup } from '../../../../src/lib/logger';
|
|
|
|
|
|
|
|
setup([]);
|
|
|
|
|
2019-05-19 15:23:12 -05:00
|
|
|
import { HEADERS, HTTP_STATUS } from '../../../../src/lib/constants';
|
2019-09-07 17:46:50 -05:00
|
|
|
import configDefault from '../../partials/config';
|
2019-05-19 15:23:12 -05:00
|
|
|
import endPointAPI from '../../../../src/api';
|
2021-03-14 02:42:46 -05:00
|
|
|
import { mockServer } from '../../__helper/mock';
|
|
|
|
import { DOMAIN_SERVERS } from '../../../functional/config.functional';
|
2018-03-11 12:55:19 -05:00
|
|
|
|
2019-05-19 15:23:12 -05:00
|
|
|
require('../../../../src/lib/logger').setup([]);
|
2018-03-11 12:55:19 -05:00
|
|
|
|
|
|
|
describe('api with no limited access configuration', () => {
|
|
|
|
let app;
|
2018-06-30 11:10:05 -05:00
|
|
|
let mockRegistry;
|
2019-07-16 01:40:01 -05:00
|
|
|
const store = path.join(__dirname, '../../partials/store/access-storage');
|
|
|
|
jest.setTimeout(10000);
|
2018-03-11 12:55:19 -05:00
|
|
|
|
2021-03-14 02:42:46 -05:00
|
|
|
beforeAll(function (done) {
|
2018-06-30 11:10:05 -05:00
|
|
|
const mockServerPort = 55530;
|
2019-05-19 15:23:12 -05:00
|
|
|
|
2018-04-21 11:36:06 -05:00
|
|
|
rimraf(store, async () => {
|
2021-03-14 02:42:46 -05:00
|
|
|
const configForTest = configDefault(
|
|
|
|
{
|
|
|
|
auth: {
|
|
|
|
htpasswd: {
|
|
|
|
file: './access-storage/htpasswd-pkg-access'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
self_path: store,
|
|
|
|
uplinks: {
|
|
|
|
remote: {
|
|
|
|
url: `http://${DOMAIN_SERVERS}:${mockServerPort}`
|
|
|
|
}
|
|
|
|
},
|
|
|
|
logs: [{ type: 'stdout', format: 'pretty', level: 'warn' }]
|
2019-09-07 17:46:50 -05:00
|
|
|
},
|
2021-03-14 02:42:46 -05:00
|
|
|
'pkg.access.spec.yaml'
|
|
|
|
);
|
2019-07-16 01:40:01 -05:00
|
|
|
|
2019-02-24 17:20:25 -05:00
|
|
|
app = await endPointAPI(configForTest);
|
2018-06-30 11:10:05 -05:00
|
|
|
mockRegistry = await mockServer(mockServerPort).init();
|
2018-03-11 12:55:19 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-14 02:42:46 -05:00
|
|
|
afterAll(function (done) {
|
2018-03-11 13:25:13 -05:00
|
|
|
rimraf(store, (err) => {
|
|
|
|
if (err) {
|
2018-06-30 11:10:05 -05:00
|
|
|
mockRegistry[0].stop();
|
2018-03-11 13:25:13 -05:00
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
2018-06-30 11:10:05 -05:00
|
|
|
mockRegistry[0].stop();
|
2018-03-11 13:25:13 -05:00
|
|
|
return done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-11 12:55:19 -05:00
|
|
|
describe('test proxy packages partially restricted', () => {
|
2019-09-07 17:46:50 -05:00
|
|
|
test('should test fails on fetch endpoint /-/not-found', (done) => {
|
|
|
|
request(app)
|
2021-03-14 02:42:46 -05:00
|
|
|
// @ts-ignore
|
2019-09-07 17:46:50 -05:00
|
|
|
.get('/not-found-for-sure')
|
|
|
|
.set(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
|
|
.expect(HEADERS.CONTENT_TYPE, /json/)
|
|
|
|
.expect(HTTP_STATUS.NOT_FOUND)
|
2021-03-14 02:42:46 -05:00
|
|
|
.end(function (err) {
|
2019-09-07 17:46:50 -05:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should test fetch endpoint /-/jquery', (done) => {
|
2018-03-11 12:55:19 -05:00
|
|
|
request(app)
|
2019-07-16 01:40:01 -05:00
|
|
|
// @ts-ignore
|
2018-03-11 12:55:19 -05:00
|
|
|
.get('/jquery')
|
2019-07-16 01:40:01 -05:00
|
|
|
.set(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
|
|
.expect(HEADERS.CONTENT_TYPE, /json/)
|
2019-09-07 17:46:50 -05:00
|
|
|
.expect(HTTP_STATUS.OK)
|
2021-03-14 02:42:46 -05:00
|
|
|
.end(function (err) {
|
2018-03-11 12:55:19 -05:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-07-16 01:40:01 -05:00
|
|
|
|
2018-03-11 12:55:19 -05:00
|
|
|
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)
|
2019-07-16 01:40:01 -05:00
|
|
|
// @ts-ignore
|
2018-03-11 13:25:13 -05:00
|
|
|
.get('/vue')
|
2019-07-16 01:40:01 -05:00
|
|
|
.set(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
|
|
.expect(HEADERS.CONTENT_TYPE, /json/)
|
|
|
|
.expect(HTTP_STATUS.OK)
|
2021-03-14 02:42:46 -05:00
|
|
|
.end(function (err) {
|
2018-03-11 12:55:19 -05:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2019-07-16 01:40:01 -05:00
|
|
|
|
2018-03-11 12:55:19 -05:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|