2020-03-03 17:59:19 -05:00
|
|
|
import path from 'path';
|
2020-08-11 00:21:51 -05:00
|
|
|
import request from 'supertest';
|
2020-03-03 17:59:19 -05:00
|
|
|
|
2020-08-13 16:27:00 -05:00
|
|
|
import { setup, logger } from '@verdaccio/logger';
|
2020-03-03 17:59:19 -05:00
|
|
|
|
|
|
|
setup([]);
|
|
|
|
|
2020-11-15 05:14:09 -05:00
|
|
|
import { HEADERS, HTTP_STATUS } from '@verdaccio/commons-api';
|
2020-08-13 16:27:00 -05:00
|
|
|
import { generateRamdonStorage, mockServer, configExample, DOMAIN_SERVERS } from '@verdaccio/mock';
|
2020-08-11 00:21:51 -05:00
|
|
|
import endPointAPI from '../../src';
|
2020-03-03 17:59:19 -05:00
|
|
|
|
|
|
|
describe('api with no limited access configuration', () => {
|
|
|
|
let app;
|
|
|
|
let mockRegistry;
|
|
|
|
const store = generateRamdonStorage();
|
|
|
|
jest.setTimeout(10000);
|
|
|
|
|
|
|
|
beforeAll(async (done) => {
|
|
|
|
const mockServerPort = 55530;
|
2020-08-13 16:27:00 -05:00
|
|
|
const configForTest = configExample(
|
|
|
|
{
|
2020-11-08 09:20:02 -05:00
|
|
|
config_path: store,
|
2020-08-13 16:27:00 -05:00
|
|
|
uplinks: {
|
|
|
|
remote: {
|
|
|
|
url: `http://${DOMAIN_SERVERS}:${mockServerPort}`,
|
|
|
|
},
|
|
|
|
},
|
2020-03-03 17:59:19 -05:00
|
|
|
},
|
2020-08-13 16:27:00 -05:00
|
|
|
'pkg.access.yaml',
|
|
|
|
__dirname
|
|
|
|
);
|
2020-03-03 17:59:19 -05:00
|
|
|
|
|
|
|
app = await endPointAPI(configForTest);
|
|
|
|
const binPath = require.resolve('verdaccio/bin/verdaccio');
|
|
|
|
const storePath = path.join(__dirname, '/mock/store');
|
|
|
|
mockRegistry = await mockServer(mockServerPort, { storePath, silence: true }).init(binPath);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2020-08-13 16:27:00 -05:00
|
|
|
afterAll(function (done) {
|
2020-03-03 17:59:19 -05:00
|
|
|
const [registry, pid] = mockRegistry;
|
|
|
|
registry.stop();
|
|
|
|
logger.info(`registry ${pid} has been stopped`);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('test proxy packages partially restricted', () => {
|
|
|
|
test('should test fails on fetch endpoint /-/not-found', (done) => {
|
|
|
|
request(app)
|
2020-08-13 16:27:00 -05:00
|
|
|
// @ts-ignore
|
2020-03-03 17:59:19 -05:00
|
|
|
.get('/not-found-for-sure')
|
|
|
|
.set(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
|
|
.expect(HEADERS.CONTENT_TYPE, /json/)
|
|
|
|
.expect(HTTP_STATUS.NOT_FOUND)
|
2020-08-13 16:27:00 -05:00
|
|
|
.end(function (err) {
|
2020-03-03 17:59:19 -05:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should test fetch endpoint /-/jquery', (done) => {
|
|
|
|
request(app)
|
|
|
|
// @ts-ignore
|
|
|
|
.get('/jquery')
|
|
|
|
.set(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
|
|
.expect(HEADERS.CONTENT_TYPE, /json/)
|
|
|
|
.expect(HTTP_STATUS.OK)
|
2020-08-13 16:27:00 -05:00
|
|
|
.end(function (err) {
|
2020-03-03 17:59:19 -05:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should success on fetch endpoint /-/vue', (done) => {
|
|
|
|
request(app)
|
|
|
|
// @ts-ignore
|
|
|
|
.get('/vue')
|
|
|
|
.set(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
|
|
.expect(HEADERS.CONTENT_TYPE, /json/)
|
|
|
|
.expect(HTTP_STATUS.OK)
|
2020-08-13 16:27:00 -05:00
|
|
|
.end(function (err) {
|
2020-03-03 17:59:19 -05:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|