2023-01-29 09:08:50 -05:00
|
|
|
import request from 'supertest';
|
|
|
|
|
|
|
|
import { HTTP_STATUS } from '@verdaccio/core';
|
2023-02-05 15:00:32 -05:00
|
|
|
import { logger, setup } from '@verdaccio/logger';
|
2023-01-29 09:08:50 -05:00
|
|
|
|
|
|
|
import { allow } from '../src';
|
|
|
|
import { getApp } from './helper';
|
|
|
|
|
|
|
|
setup({});
|
|
|
|
|
|
|
|
test('should allow request', async () => {
|
2023-02-05 15:00:32 -05:00
|
|
|
const can = allow(
|
|
|
|
{
|
|
|
|
allow_publish: (params, remove, cb) => {
|
|
|
|
return cb(null, true);
|
|
|
|
},
|
2023-01-29 09:08:50 -05:00
|
|
|
},
|
2023-02-05 15:00:32 -05:00
|
|
|
logger
|
|
|
|
);
|
2023-01-29 09:08:50 -05:00
|
|
|
const app = getApp([]);
|
|
|
|
// @ts-ignore
|
|
|
|
app.get('/:package', can('publish'), (req, res) => {
|
|
|
|
res.status(HTTP_STATUS.OK).json({});
|
|
|
|
});
|
|
|
|
|
|
|
|
return request(app).get('/react').expect(HTTP_STATUS.OK);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should allow scope request', async () => {
|
2023-02-05 15:00:32 -05:00
|
|
|
const can = allow(
|
|
|
|
{
|
|
|
|
allow_publish: (params, remove, cb) => {
|
|
|
|
return cb(null, true);
|
|
|
|
},
|
2023-01-29 09:08:50 -05:00
|
|
|
},
|
2023-02-05 15:00:32 -05:00
|
|
|
logger
|
|
|
|
);
|
2023-01-29 09:08:50 -05:00
|
|
|
const app = getApp([]);
|
|
|
|
// @ts-ignore
|
|
|
|
app.get('/:package/:scope', can('publish'), (req, res) => {
|
|
|
|
res.status(HTTP_STATUS.OK).json({});
|
|
|
|
});
|
|
|
|
|
|
|
|
return request(app).get('/@verdaccio/core').expect(HTTP_STATUS.OK);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should allow filename request', async () => {
|
2023-02-05 15:00:32 -05:00
|
|
|
const can = allow(
|
|
|
|
{
|
|
|
|
allow_publish: (params, remove, cb) => {
|
|
|
|
return cb(null, true);
|
|
|
|
},
|
2023-01-29 09:08:50 -05:00
|
|
|
},
|
2023-02-05 15:00:32 -05:00
|
|
|
logger
|
|
|
|
);
|
2023-01-29 09:08:50 -05:00
|
|
|
const app = getApp([]);
|
|
|
|
// @ts-ignore
|
|
|
|
app.get('/:filename', can('publish'), (req, res) => {
|
|
|
|
res.status(HTTP_STATUS.OK).json({});
|
|
|
|
});
|
|
|
|
|
|
|
|
return request(app).get('/aaa-0.0.1.tgz').expect(HTTP_STATUS.OK);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should not allow request', async () => {
|
2023-02-05 15:00:32 -05:00
|
|
|
const can = allow(
|
|
|
|
{
|
|
|
|
allow_publish: (params, remove, cb) => {
|
|
|
|
return cb(null, false);
|
|
|
|
},
|
2023-01-29 09:08:50 -05:00
|
|
|
},
|
2023-02-05 15:00:32 -05:00
|
|
|
logger
|
|
|
|
);
|
2023-01-29 09:08:50 -05:00
|
|
|
const app = getApp([]);
|
|
|
|
// @ts-ignore
|
|
|
|
app.get('/sec', can('publish'), (req, res) => {
|
|
|
|
res.status(HTTP_STATUS.OK).json({});
|
|
|
|
});
|
|
|
|
|
|
|
|
return request(app).get('/sec').expect(HTTP_STATUS.INTERNAL_ERROR);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should handle error request', async () => {
|
2023-02-05 15:00:32 -05:00
|
|
|
const can = allow(
|
|
|
|
{
|
|
|
|
allow_publish: (params, remove, cb) => {
|
|
|
|
return cb(Error('foo error'));
|
|
|
|
},
|
2023-01-29 09:08:50 -05:00
|
|
|
},
|
2023-02-05 15:00:32 -05:00
|
|
|
logger
|
|
|
|
);
|
2023-01-29 09:08:50 -05:00
|
|
|
const app = getApp([]);
|
|
|
|
// @ts-ignore
|
|
|
|
app.get('/err', can('publish'));
|
|
|
|
|
|
|
|
return request(app).get('/err').expect(HTTP_STATUS.INTERNAL_ERROR);
|
|
|
|
});
|