2018-01-25 21:36:26 +01:00
|
|
|
import request from 'supertest';
|
2018-01-25 23:14:03 +01:00
|
|
|
import _ from 'lodash';
|
|
|
|
import path from 'path';
|
2018-06-24 22:39:09 +02:00
|
|
|
|
2020-03-03 23:59:19 +01:00
|
|
|
import endPointAPI from '@verdaccio/server';
|
2019-08-10 13:38:06 +02:00
|
|
|
import {
|
|
|
|
HEADERS,
|
|
|
|
HTTP_STATUS,
|
|
|
|
HEADER_TYPE,
|
|
|
|
API_MESSAGE,
|
2020-03-03 23:59:19 +01:00
|
|
|
TOKEN_BEARER,
|
|
|
|
} from '@verdaccio/dev-commons';
|
|
|
|
import {buildToken, encodeScopedUri} from '@verdaccio/utils';
|
|
|
|
import {setup, logger} from '@verdaccio/logger';
|
|
|
|
|
|
|
|
import {mockServer} from '@verdaccio/mock';
|
|
|
|
|
2019-08-10 13:38:06 +02:00
|
|
|
import {
|
2020-03-03 23:59:19 +01:00
|
|
|
configExample, DOMAIN_SERVERS,
|
2019-08-10 13:38:06 +02:00
|
|
|
getNewToken,
|
2020-06-19 22:54:03 +02:00
|
|
|
getPackage,
|
2019-08-10 13:38:06 +02:00
|
|
|
putPackage,
|
2020-03-03 23:59:19 +01:00
|
|
|
generateRamdonStorage,
|
2021-03-14 08:42:46 +01:00
|
|
|
verifyPackageVersionDoesExist,
|
2020-03-03 23:59:19 +01:00
|
|
|
generateUnPublishURI,
|
2020-06-19 22:54:03 +02:00
|
|
|
generateDeprecateMetadata,
|
2020-03-03 23:59:19 +01:00
|
|
|
generateVersion,
|
|
|
|
} from '@verdaccio/mock';
|
2018-01-25 21:36:26 +01:00
|
|
|
|
2020-03-03 23:59:19 +01:00
|
|
|
import publishMetadata from './helpers/publish-api';
|
|
|
|
import {generatePackageMetadata, generatePackageUnpublish, generateStarMedatada} from './helpers/utils';
|
2020-10-11 15:58:57 +02:00
|
|
|
|
2020-03-03 23:59:19 +01:00
|
|
|
setup([]);
|
2019-08-10 13:38:06 +02:00
|
|
|
|
2018-11-18 18:41:05 +01:00
|
|
|
const credentials = { name: 'jota', password: 'secretPass' };
|
2018-01-25 21:36:26 +01:00
|
|
|
|
2019-07-27 23:47:04 +02:00
|
|
|
const putVersion = (app, name, publishMetadata) => {
|
2019-02-25 08:33:01 +01:00
|
|
|
return request(app)
|
|
|
|
.put(name)
|
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
|
|
|
.send(JSON.stringify(publishMetadata))
|
|
|
|
.expect(HTTP_STATUS.CREATED)
|
|
|
|
.set('accept', 'gzip')
|
|
|
|
.set('accept-encoding', HEADERS.JSON)
|
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON);
|
2019-07-27 23:47:04 +02:00
|
|
|
};
|
2019-02-25 08:33:01 +01:00
|
|
|
|
2018-01-25 21:36:26 +01:00
|
|
|
describe('endpoint unit test', () => {
|
|
|
|
let app;
|
2018-06-24 22:39:09 +02:00
|
|
|
let mockRegistry;
|
2018-01-25 21:36:26 +01:00
|
|
|
|
2020-03-03 23:59:19 +01:00
|
|
|
beforeAll(async function(done) {
|
|
|
|
const store = generateRamdonStorage();
|
|
|
|
const mockServerPort = 55549;
|
|
|
|
const configForTest = configExample({
|
|
|
|
filters: {
|
|
|
|
[path.join(__dirname, './plugin/filter')]: {
|
|
|
|
pkg: 'npm_test',
|
|
|
|
version: '2.0.0'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
storage: store,
|
|
|
|
self_path: store,
|
|
|
|
uplinks: {
|
|
|
|
npmjs: {
|
|
|
|
url: `http://${DOMAIN_SERVERS}:${mockServerPort}`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 'api.spec.yaml', __dirname);
|
2018-01-25 21:36:26 +01:00
|
|
|
|
2020-03-03 23:59:19 +01: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);
|
2018-06-24 22:39:09 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2020-03-03 23:59:19 +01:00
|
|
|
afterAll(function(done) {
|
|
|
|
const [registry, pid] = mockRegistry;
|
|
|
|
registry.stop();
|
|
|
|
logger.info(`registry ${pid} has been stopped`);
|
|
|
|
|
|
|
|
done();
|
2021-03-14 08:42:46 +01:00
|
|
|
});
|
2020-10-11 15:58:57 +02:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
describe('Registry API Endpoints', () => {
|
|
|
|
describe('should test user api', () => {
|
2018-04-29 21:50:10 +02:00
|
|
|
describe('should test authorization headers with tokens only errors', () => {
|
|
|
|
test('should fails on protected endpoint /-/auth-package bad format', (done) => {
|
|
|
|
request(app)
|
|
|
|
.get('/auth-package')
|
2019-05-19 21:37:43 +02:00
|
|
|
.set(HEADERS.AUTHORIZATION, 'FakeHader')
|
2018-06-25 07:59:35 +02:00
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
2018-06-24 22:39:09 +02:00
|
|
|
.expect(HTTP_STATUS.FORBIDDEN)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2018-04-29 21:50:10 +02:00
|
|
|
expect(res.body.error).toBeDefined();
|
2020-03-03 23:59:19 +01:00
|
|
|
expect(res.body.error).toMatch(/authorization required to access package auth-package/);
|
2018-04-29 21:50:10 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should fails on protected endpoint /-/auth-package bad JWT Bearer format', (done) => {
|
|
|
|
request(app)
|
|
|
|
.get('/auth-package')
|
2019-05-19 21:37:43 +02:00
|
|
|
.set(HEADERS.AUTHORIZATION, TOKEN_BEARER)
|
2018-06-25 07:59:35 +02:00
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
2018-06-24 22:39:09 +02:00
|
|
|
.expect(HTTP_STATUS.FORBIDDEN)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2018-04-29 21:50:10 +02:00
|
|
|
expect(res.body.error).toBeDefined();
|
2020-03-03 23:59:19 +01:00
|
|
|
expect(res.body.error).toMatch(/authorization required to access package auth-package/);
|
2018-04-29 21:50:10 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should fails on protected endpoint /-/auth-package well JWT Bearer', (done) => {
|
|
|
|
request(app)
|
|
|
|
.get('/auth-package')
|
2019-05-19 21:37:43 +02:00
|
|
|
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, '12345'))
|
2018-06-25 07:59:35 +02:00
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
2018-06-24 22:39:09 +02:00
|
|
|
.expect(HTTP_STATUS.FORBIDDEN)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2018-04-29 21:50:10 +02:00
|
|
|
expect(res.body.error).toBeDefined();
|
2020-03-03 23:59:19 +01:00
|
|
|
expect(res.body.error).toMatch(/authorization required to access package auth-package/);
|
2018-04-29 21:50:10 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
test('should test add a new user', (done) => {
|
|
|
|
request(app)
|
2018-11-18 18:41:05 +01:00
|
|
|
.put(`/-/user/org.couchdb.user:${credentials.name}`)
|
2018-03-18 08:46:02 +01:00
|
|
|
.send(credentials)
|
2018-06-25 07:59:35 +02:00
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
2018-06-24 22:39:09 +02:00
|
|
|
.expect(HTTP_STATUS.CREATED)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
expect(res.body.ok).toBeDefined();
|
2018-04-29 21:50:10 +02:00
|
|
|
expect(res.body.token).toBeDefined();
|
|
|
|
const token = res.body.token;
|
|
|
|
expect(typeof token).toBe('string');
|
2018-03-18 08:46:02 +01:00
|
|
|
expect(res.body.ok).toMatch(`user '${credentials.name}' created`);
|
2018-04-29 21:50:10 +02:00
|
|
|
|
|
|
|
// testing JWT auth headers with token
|
|
|
|
// we need it here, because token is required
|
|
|
|
request(app)
|
|
|
|
.get('/vue')
|
2019-05-19 21:37:43 +02:00
|
|
|
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
2018-06-25 07:59:35 +02:00
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
2018-06-24 22:39:09 +02:00
|
|
|
.expect(HTTP_STATUS.OK)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2018-04-29 21:50:10 +02:00
|
|
|
expect(err).toBeNull();
|
|
|
|
expect(res.body).toBeDefined();
|
|
|
|
expect(res.body.name).toMatch(/vue/);
|
|
|
|
done();
|
|
|
|
});
|
2018-03-18 08:46:02 +01:00
|
|
|
});
|
|
|
|
});
|
2018-01-26 07:35:41 +01:00
|
|
|
});
|
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
describe('should test package api', () => {
|
2019-07-27 07:17:08 +02:00
|
|
|
// The current behaviour depends of what's defined in the following configuration file.
|
|
|
|
// test/unit/partials/config/yaml/api.spec.yaml
|
|
|
|
// 'jquery':
|
|
|
|
// access: $all
|
|
|
|
// publish: $all
|
|
|
|
// proxy: npmjs
|
2018-03-18 08:46:02 +01:00
|
|
|
|
|
|
|
test('should fetch jquery package from remote uplink', (done) => {
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
request(app)
|
|
|
|
.get('/jquery')
|
2018-06-24 22:39:09 +02:00
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
2018-06-25 07:59:35 +02:00
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
2018-06-24 22:39:09 +02:00
|
|
|
.expect(HTTP_STATUS.OK)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(res.body).toBeDefined();
|
|
|
|
expect(res.body.name).toMatch(/jquery/);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should fetch jquery specific version package from remote uplink', (done) => {
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
request(app)
|
|
|
|
.get('/jquery/1.5.1')
|
2018-06-24 22:39:09 +02:00
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
2018-06-25 07:59:35 +02:00
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
2018-06-24 22:39:09 +02:00
|
|
|
.expect(HTTP_STATUS.OK)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(res.body).toBeDefined();
|
|
|
|
expect(res.body.name).toMatch(/jquery/);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should fetch jquery specific tag package from remote uplink', (done) => {
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
request(app)
|
|
|
|
.get('/jquery/latest')
|
2018-06-24 22:39:09 +02:00
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
2018-06-25 07:59:35 +02:00
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
2018-06-24 22:39:09 +02:00
|
|
|
.expect(HTTP_STATUS.OK)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(res.body).toBeDefined();
|
|
|
|
expect(res.body.name).toMatch(/jquery/);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should fails on fetch jquery specific tag package from remote uplink', (done) => {
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
request(app)
|
|
|
|
.get('/jquery/never-will-exist-this-tag')
|
2018-06-24 22:39:09 +02:00
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
2018-06-25 07:59:35 +02:00
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
2018-06-24 22:39:09 +02:00
|
|
|
.expect(HTTP_STATUS.NOT_FOUND)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should not found a unexisting remote package under scope', (done) => {
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
request(app)
|
|
|
|
.get('/@verdaccio/not-found')
|
2018-06-24 22:39:09 +02:00
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
2018-06-25 07:59:35 +02:00
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
2018-06-24 22:39:09 +02:00
|
|
|
.expect(HTTP_STATUS.NOT_FOUND)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-27 07:17:08 +02:00
|
|
|
describe('testing filters', () => {
|
|
|
|
test('be able to filter packages', (done) => {
|
|
|
|
request(app)
|
|
|
|
.get('/npm_test')
|
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
|
|
.expect(HTTP_STATUS.OK)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2019-07-27 07:17:08 +02:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
// Filter out 2.0.0
|
|
|
|
expect(Object.keys(res.body.versions)).toEqual(['1.0.0']);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2019-04-16 18:39:52 +02:00
|
|
|
|
2019-07-27 07:17:08 +02:00
|
|
|
test('should not found when a filter fails', (done) => {
|
|
|
|
request(app)
|
2020-03-03 23:59:19 +01:00
|
|
|
// Filter errors look like other uplink errors
|
2019-07-27 07:17:08 +02:00
|
|
|
.get('/trigger-filter-failure')
|
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
|
|
|
.expect(HTTP_STATUS.NOT_FOUND)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err) {
|
2019-07-27 07:17:08 +02:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2019-04-16 18:39:52 +02:00
|
|
|
});
|
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
test('should forbid access to remote package', (done) => {
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
request(app)
|
|
|
|
.get('/forbidden-place')
|
2018-06-24 22:39:09 +02:00
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
2018-06-25 07:59:35 +02:00
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
2018-11-15 20:14:56 +01:00
|
|
|
.expect(HTTP_STATUS.UNAUTHORIZED)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should fetch a tarball from remote uplink', (done) => {
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
request(app)
|
|
|
|
.get('/jquery/-/jquery-1.5.1.tgz')
|
2018-06-25 07:59:35 +02:00
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.OCTET_STREAM)
|
2018-06-24 22:39:09 +02:00
|
|
|
.expect(HTTP_STATUS.OK)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(res.body).toBeDefined();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-04-28 09:34:59 +02:00
|
|
|
test('should fetch a scoped tarball from remote uplink', (done) => {
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2019-04-28 09:34:59 +02:00
|
|
|
request(app)
|
|
|
|
.get('/@jquery/jquery/-/@jquery/jquery-1.5.1.tgz')
|
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.OCTET_STREAM)
|
|
|
|
.expect(HTTP_STATUS.OK)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2019-04-28 09:34:59 +02:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(res.body).toBeDefined();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
test('should fails fetch a tarball from remote uplink', (done) => {
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
request(app)
|
2019-04-28 09:34:59 +02:00
|
|
|
.get('/jquery/-/jquery-not-found-tarball-0.0.1.tgz')
|
2018-06-25 07:59:35 +02:00
|
|
|
.expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.OCTET_STREAM)
|
2018-06-24 22:39:09 +02:00
|
|
|
.expect(HTTP_STATUS.NOT_FOUND)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
2018-06-25 07:59:35 +02:00
|
|
|
expect(err).not.toBeNull();
|
2018-03-18 08:46:02 +01:00
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2018-01-28 11:53:49 +01:00
|
|
|
});
|
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
describe('should test dist-tag api', () => {
|
|
|
|
const jqueryVersion = '2.1.2';
|
|
|
|
const jqueryUpdatedVersion = {
|
2020-03-03 23:59:19 +01:00
|
|
|
'beta': '3.0.0',
|
|
|
|
'jota': '1.6.3'
|
2018-03-18 08:46:02 +01:00
|
|
|
};
|
2018-01-28 11:38:22 +01:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
test('should set a new tag on jquery', (done) => {
|
2019-07-27 23:47:04 +02:00
|
|
|
putVersion(app, '/jquery/verdaccio-tag', jqueryVersion)
|
2018-06-24 22:39:09 +02:00
|
|
|
.expect(HTTP_STATUS.CREATED)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
2019-07-16 08:40:01 +02:00
|
|
|
expect(err).toBeNull();
|
2018-03-18 08:46:02 +01:00
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(res.body.ok).toBeDefined();
|
|
|
|
expect(res.body.ok).toMatch(/package tagged/);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should fetch all tag for jquery', (done) => {
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
request(app)
|
|
|
|
.get('/-/package/jquery/dist-tags')
|
2018-04-30 15:41:04 +02:00
|
|
|
.set('accept-encoding', HEADERS.JSON)
|
2018-06-24 22:39:09 +02:00
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
|
|
|
.expect(HTTP_STATUS.OK)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
2019-07-16 08:40:01 +02:00
|
|
|
expect(err).toBeNull();
|
2018-03-18 08:46:02 +01:00
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(res.body).toBeDefined();
|
|
|
|
expect(res.body['verdaccio-tag']).toMatch(jqueryVersion);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should update a new tag on jquery', (done) => {
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
request(app)
|
|
|
|
.post('/-/package/jquery/dist-tags')
|
|
|
|
.send(JSON.stringify(jqueryUpdatedVersion))
|
2018-06-24 22:39:09 +02:00
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
|
|
|
.expect(HTTP_STATUS.CREATED)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
2019-07-16 08:40:01 +02:00
|
|
|
expect(err).toBeNull();
|
2018-03-18 08:46:02 +01:00
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(res.body.ok).toBeDefined();
|
2018-06-25 07:59:35 +02:00
|
|
|
expect(res.body.ok).toMatch(API_MESSAGE.TAG_UPDATED);
|
2018-03-18 08:46:02 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should fetch all tags for jquery and ccheck previous update', (done) => {
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
request(app)
|
|
|
|
.get('/-/package/jquery/dist-tags')
|
2018-04-30 15:41:04 +02:00
|
|
|
.set('accept-encoding', HEADERS.JSON)
|
2018-06-24 22:39:09 +02:00
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
|
|
|
.expect(HTTP_STATUS.OK)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
2019-07-16 08:40:01 +02:00
|
|
|
expect(err).toBeNull();
|
2018-03-18 08:46:02 +01:00
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(res.body).toBeDefined();
|
|
|
|
expect(res.body['beta']).toMatch(jqueryUpdatedVersion['beta']);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should set a remove a tag on jquery', (done) => {
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
request(app)
|
|
|
|
.del('/-/package/jquery/dist-tags/verdaccio-tag')
|
2018-04-30 15:41:04 +02:00
|
|
|
.set('accept-encoding', HEADERS.JSON)
|
2018-06-24 22:39:09 +02:00
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
2019-12-23 09:29:27 +01:00
|
|
|
// .expect(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
2018-06-24 22:39:09 +02:00
|
|
|
.expect(HTTP_STATUS.CREATED)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
2019-07-16 08:40:01 +02:00
|
|
|
expect(err).toBeNull();
|
2018-03-18 08:46:02 +01:00
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(res.body.ok).toBeDefined();
|
2018-06-25 07:59:35 +02:00
|
|
|
expect(res.body.ok).toMatch(API_MESSAGE.TAG_REMOVED);
|
2018-03-18 08:46:02 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2018-01-28 14:40:38 +01:00
|
|
|
});
|
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
describe('should test search api', () => {
|
|
|
|
test('should perform a search', (done) => {
|
2019-07-27 23:47:04 +02:00
|
|
|
const now = Date.now();
|
2018-03-18 08:46:02 +01:00
|
|
|
const cacheTime = now - 6000000;
|
|
|
|
request(app)
|
|
|
|
.get('/-/all/since?stale=update_after&startkey=' + cacheTime)
|
2018-04-30 15:41:04 +02:00
|
|
|
// .set('accept-encoding', HEADERS.JSON)
|
2018-06-24 22:39:09 +02:00
|
|
|
// .set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
2020-03-03 21:16:53 +01:00
|
|
|
.expect(HEADERS.CONTENT_TYPE, HEADERS.JSON_CHARSET)
|
2018-06-24 22:39:09 +02:00
|
|
|
.expect(HTTP_STATUS.OK)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
2019-07-16 08:40:01 +02:00
|
|
|
expect(err).toBeNull();
|
2018-03-18 08:46:02 +01:00
|
|
|
return done(err);
|
|
|
|
}
|
2019-12-23 09:29:27 +01:00
|
|
|
// TODO: we have to catch the stream check whether it returns something
|
2018-03-18 08:46:02 +01:00
|
|
|
// we should not spend much time on this api since is deprecated somehow.
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2020-03-03 23:59:19 +01:00
|
|
|
|
2018-01-28 14:40:38 +01:00
|
|
|
});
|
|
|
|
|
2019-02-25 08:33:01 +01:00
|
|
|
describe('should test publish/unpublish api', () => {
|
2019-08-10 13:38:06 +02:00
|
|
|
/**
|
|
|
|
* It publish 2 versions and unpublish the latest one, then verifies
|
|
|
|
* the version do not exist anymore in the body of the metadata.
|
|
|
|
*/
|
|
|
|
const runPublishUnPublishFlow = async (pkgName: string, done, token?: string) => {
|
|
|
|
const version = '2.0.0';
|
|
|
|
const pkg = generatePackageMetadata(pkgName, version);
|
|
|
|
|
|
|
|
const [err] = await putPackage(request(app), `/${encodeScopedUri(pkgName)}`, pkg, token);
|
|
|
|
if (err) {
|
|
|
|
expect(err).toBeNull();
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const newVersion = '2.0.1';
|
2020-03-03 23:59:19 +01:00
|
|
|
const [newErr] = await putPackage(request(app), `/${encodeScopedUri(pkgName)}`,
|
|
|
|
generatePackageMetadata(pkgName, newVersion), token);
|
2019-08-10 13:38:06 +02:00
|
|
|
if (newErr) {
|
|
|
|
expect(newErr).toBeNull();
|
|
|
|
return done(newErr);
|
|
|
|
}
|
|
|
|
|
2020-03-03 23:59:19 +01:00
|
|
|
const deletePayload = generatePackageUnpublish(pkgName, ['2.0.0']);
|
|
|
|
const [err2, res2] = await putPackage(request(app), generateUnPublishURI(pkgName), deletePayload, token);
|
2019-08-10 13:38:06 +02:00
|
|
|
|
|
|
|
expect(err2).toBeNull();
|
|
|
|
expect(res2.body.ok).toMatch(API_MESSAGE.PKG_CHANGED);
|
|
|
|
|
|
|
|
const existVersion = await verifyPackageVersionDoesExist(app, pkgName, newVersion, token);
|
|
|
|
expect(existVersion).toBeTruthy();
|
|
|
|
|
|
|
|
return done();
|
|
|
|
};
|
2019-07-27 23:47:04 +02:00
|
|
|
|
2019-08-10 13:38:06 +02:00
|
|
|
describe('un/publish scenarios with credentials', () => {
|
|
|
|
test('should flow with no credentials', async (done) => {
|
|
|
|
const pkgName = '@public-anyone-can-publish/pk1-test';
|
|
|
|
runPublishUnPublishFlow(pkgName, done, undefined);
|
|
|
|
});
|
2018-03-18 08:46:02 +01:00
|
|
|
|
2019-08-10 13:38:06 +02:00
|
|
|
test('should flow with credentials', async (done) => {
|
|
|
|
const credentials = { name: 'jota_unpublish', password: 'secretPass' };
|
|
|
|
const token = await getNewToken(request(app), credentials);
|
|
|
|
const pkgName = '@only-one-can-publish/pk1-test';
|
2019-02-25 08:33:01 +01:00
|
|
|
|
2019-08-10 13:38:06 +02:00
|
|
|
runPublishUnPublishFlow(pkgName, done, token);
|
|
|
|
});
|
2018-03-18 08:46:02 +01:00
|
|
|
});
|
2019-02-25 08:33:01 +01:00
|
|
|
|
2019-08-10 13:38:06 +02:00
|
|
|
describe('test error handling', () => {
|
|
|
|
test('should fail if user is not allowed to unpublish', async (done) => {
|
|
|
|
/**
|
|
|
|
* Context:
|
|
|
|
*
|
|
|
|
* 'non-unpublish':
|
|
|
|
access: $authenticated
|
|
|
|
publish: jota_unpublish_fail
|
|
|
|
# There is some conditions to keep on mind here
|
|
|
|
# - If unpublish is empty, fallback with the publish value
|
|
|
|
# - If the user has permissions to publish and this empty it will be allowed to unpublish
|
|
|
|
# - If we want to forbid anyone to unpublish, just write here any unexisting user
|
|
|
|
unpublish: none
|
|
|
|
|
|
|
|
The result of this test should fail and even if jota_unpublish_fail is allowed to publish.
|
|
|
|
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
const credentials = { name: 'jota_unpublish_fail', password: 'secretPass' };
|
|
|
|
const pkgName = 'non-unpublish';
|
|
|
|
const newVersion = '1.0.0';
|
|
|
|
const token = await getNewToken(request(app), credentials);
|
|
|
|
|
2020-03-03 23:59:19 +01:00
|
|
|
const [newErr] = await putPackage(request(app), `/${encodeScopedUri(pkgName)}`,
|
|
|
|
generatePackageMetadata(pkgName, newVersion), token);
|
2019-08-10 13:38:06 +02:00
|
|
|
if (newErr) {
|
|
|
|
expect(newErr).toBeNull();
|
|
|
|
return done(newErr);
|
|
|
|
}
|
|
|
|
|
2020-03-03 23:59:19 +01:00
|
|
|
const deletePayload = generatePackageUnpublish(pkgName, ['2.0.0']);
|
|
|
|
const [err2, res2] = await putPackage(request(app), generateUnPublishURI(pkgName), deletePayload, token);
|
2019-08-10 13:38:06 +02:00
|
|
|
|
|
|
|
expect(err2).not.toBeNull();
|
2020-03-03 23:59:19 +01:00
|
|
|
expect(res2.body.error).toMatch(/user jota_unpublish_fail is not allowed to unpublish package non-unpublish/);
|
2019-08-10 13:38:06 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should fail if publish prop is not defined', async (done) => {
|
|
|
|
/**
|
|
|
|
* Context:
|
|
|
|
*
|
|
|
|
* 'non-unpublish':
|
|
|
|
access: $authenticated
|
|
|
|
publish: jota_unpublish_fail
|
|
|
|
# There is some conditions to keep on mind here
|
|
|
|
# - If unpublish is empty, fallback with the publish value
|
|
|
|
# - If the user has permissions to publish and this empty it will be allowed to unpublish
|
|
|
|
# - If we want to forbid anyone to unpublish, just write here any unexisting user
|
|
|
|
unpublish: none
|
|
|
|
|
|
|
|
The result of this test should fail and even if jota_unpublish_fail is allowed to publish.
|
|
|
|
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
const credentials = { name: 'jota_only_unpublish_fail', password: 'secretPass' };
|
|
|
|
const pkgName = 'only-unpublish';
|
|
|
|
const newVersion = '1.0.0';
|
|
|
|
const token = await getNewToken(request(app), credentials);
|
|
|
|
|
2020-03-03 23:59:19 +01:00
|
|
|
const [newErr, resp] = await putPackage(request(app), `/${encodeScopedUri(pkgName)}`,
|
|
|
|
generatePackageMetadata(pkgName, newVersion), token);
|
2019-08-10 13:38:06 +02:00
|
|
|
|
|
|
|
expect(newErr).not.toBeNull();
|
2020-03-03 23:59:19 +01:00
|
|
|
expect(resp.body.error).toMatch(/user jota_only_unpublish_fail is not allowed to publish package only-unpublish/);
|
2019-08-10 13:38:06 +02:00
|
|
|
done();
|
|
|
|
});
|
2019-02-25 08:33:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should be able to publish/unpublish by only super_admin user', async (done) => {
|
|
|
|
const credentials = { name: 'super_admin', password: 'secretPass' };
|
|
|
|
const token = await getNewToken(request(app), credentials);
|
|
|
|
request(app)
|
|
|
|
.put('/super-admin-can-unpublish')
|
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
2019-05-19 21:37:43 +02:00
|
|
|
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
2020-03-03 23:59:19 +01:00
|
|
|
.send(JSON.stringify(_.assign({}, publishMetadata, {
|
|
|
|
name: 'super-admin-can-unpublish'
|
|
|
|
})))
|
2019-02-25 08:33:01 +01:00
|
|
|
.expect(HTTP_STATUS.CREATED)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2019-02-25 08:33:01 +01:00
|
|
|
if (err) {
|
2019-07-16 08:40:01 +02:00
|
|
|
expect(err).toBeNull();
|
2019-02-25 08:33:01 +01:00
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
expect(res.body.ok).toBeDefined();
|
|
|
|
expect(res.body.success).toBeDefined();
|
|
|
|
expect(res.body.success).toBeTruthy();
|
|
|
|
expect(res.body.ok).toMatch(API_MESSAGE.PKG_CREATED);
|
|
|
|
request(app)
|
|
|
|
.del('/super-admin-can-unpublish/-rev/4-6abcdb4efd41a576')
|
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
2019-05-19 21:37:43 +02:00
|
|
|
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
2019-02-25 08:33:01 +01:00
|
|
|
.expect(HTTP_STATUS.CREATED)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2019-02-25 08:33:01 +01:00
|
|
|
expect(err).toBeNull();
|
|
|
|
expect(res.body.ok).toBeDefined();
|
|
|
|
expect(res.body.ok).toMatch(API_MESSAGE.PKG_REMOVED);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should be able to publish/unpublish by any user', async (done) => {
|
|
|
|
const credentials = { name: 'any_user', password: 'secretPass' };
|
|
|
|
const token = await getNewToken(request(app), credentials);
|
|
|
|
request(app)
|
|
|
|
.put('/all-can-unpublish')
|
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
2019-05-19 21:37:43 +02:00
|
|
|
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
2020-03-03 23:59:19 +01:00
|
|
|
.send(JSON.stringify(_.assign({}, publishMetadata, {
|
|
|
|
name: 'all-can-unpublish'
|
|
|
|
})))
|
2019-02-25 08:33:01 +01:00
|
|
|
.expect(HTTP_STATUS.CREATED)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2019-02-25 08:33:01 +01:00
|
|
|
if (err) {
|
2019-07-16 08:40:01 +02:00
|
|
|
expect(err).toBeNull();
|
2019-02-25 08:33:01 +01:00
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
expect(res.body.ok).toBeDefined();
|
|
|
|
expect(res.body.success).toBeDefined();
|
|
|
|
expect(res.body.success).toBeTruthy();
|
|
|
|
expect(res.body.ok).toMatch(API_MESSAGE.PKG_CREATED);
|
|
|
|
request(app)
|
|
|
|
.del('/all-can-unpublish/-rev/4-6abcdb4efd41a576')
|
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
2019-05-19 21:37:43 +02:00
|
|
|
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
2019-02-25 08:33:01 +01:00
|
|
|
.expect(HTTP_STATUS.CREATED)
|
2020-03-03 23:59:19 +01:00
|
|
|
.end(function(err, res) {
|
2019-02-25 08:33:01 +01:00
|
|
|
expect(err).toBeNull();
|
|
|
|
expect(res.body.ok).toBeDefined();
|
|
|
|
expect(res.body.ok).toMatch(API_MESSAGE.PKG_REMOVED);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-01-28 14:40:38 +01:00
|
|
|
});
|
2019-07-27 23:47:04 +02:00
|
|
|
|
|
|
|
describe('should test star and stars api', () => {
|
2020-03-03 23:59:19 +01:00
|
|
|
const pkgName = '@scope/starPackage';
|
|
|
|
const credentials = { name: 'jota_star', password: 'secretPass' };
|
|
|
|
let token = '';
|
|
|
|
beforeAll(async (done) =>{
|
|
|
|
token = await getNewToken(request(app), credentials);
|
|
|
|
await putPackage(request(app), `/${pkgName}`, generatePackageMetadata(pkgName), token);
|
2021-03-14 08:42:46 +01:00
|
|
|
done();
|
2020-03-03 23:59:19 +01:00
|
|
|
});
|
2019-07-27 23:47:04 +02:00
|
|
|
|
2020-03-03 23:59:19 +01:00
|
|
|
test('should star a package', (done) => {
|
|
|
|
request(app)
|
|
|
|
.put(`/${pkgName}`)
|
|
|
|
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
|
|
|
.send(JSON.stringify(generateStarMedatada(pkgName, {
|
|
|
|
[credentials.name]: true
|
|
|
|
})))
|
|
|
|
.expect(HTTP_STATUS.OK)
|
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
expect(err).toBeNull();
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
expect(res.body.success).toBeDefined();
|
|
|
|
expect(res.body.success).toBeTruthy();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2019-07-27 23:47:04 +02:00
|
|
|
|
2020-03-03 23:59:19 +01:00
|
|
|
test('should unstar a package', (done) => {
|
2019-07-27 23:47:04 +02:00
|
|
|
request(app)
|
2020-03-03 23:59:19 +01:00
|
|
|
.put(`/${pkgName}`)
|
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
|
|
|
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
|
|
|
.send(JSON.stringify(generateStarMedatada(pkgName, {})))
|
|
|
|
.expect(HTTP_STATUS.OK)
|
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
expect(err).toBeNull();
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
expect(res.body.success).toBeDefined();
|
|
|
|
expect(res.body.success).toBeTruthy();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should retrieve stars list with credentials', async (done) => {
|
|
|
|
request(app)
|
|
|
|
.put(`/${pkgName}`)
|
|
|
|
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
|
|
|
.send(generateStarMedatada(pkgName, {[credentials.name]: true}))
|
|
|
|
.expect(HTTP_STATUS.OK).end(function(err) {
|
2019-07-27 23:47:04 +02:00
|
|
|
if (err) {
|
2020-03-03 23:59:19 +01:00
|
|
|
expect(err).toBeNull();
|
|
|
|
return done(err);
|
2019-07-27 23:47:04 +02:00
|
|
|
}
|
2020-03-03 23:59:19 +01:00
|
|
|
request(app)
|
|
|
|
.get('/-/_view/starredByUser')
|
|
|
|
.set(HEADERS.AUTHORIZATION, buildToken(TOKEN_BEARER, token))
|
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
|
|
|
.send(JSON.stringify({
|
|
|
|
key: [credentials.name]
|
|
|
|
}))
|
|
|
|
.expect(HTTP_STATUS.OK)
|
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
expect(err).toBeNull();
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
expect(res.body.rows).toBeDefined();
|
|
|
|
expect(res.body.rows).toHaveLength(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-07-27 23:47:04 +02:00
|
|
|
});
|
2020-06-19 22:54:03 +02:00
|
|
|
|
|
|
|
describe('should test (un)deprecate api', () => {
|
|
|
|
const pkgName = '@scope/deprecate';
|
|
|
|
const credentials = { name: 'jota_deprecate', password: 'secretPass' };
|
2020-03-03 23:59:19 +01:00
|
|
|
const version = '1.0.0'
|
2020-06-19 22:54:03 +02:00
|
|
|
let token = '';
|
2020-03-03 23:59:19 +01:00
|
|
|
beforeAll(async (done) =>{
|
2020-06-19 22:54:03 +02:00
|
|
|
token = await getNewToken(request(app), credentials);
|
2020-03-03 23:59:19 +01:00
|
|
|
await putPackage(request(app), `/${pkgName}`, generatePackageMetadata(pkgName, version), token);
|
2020-06-19 22:54:03 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should deprecate a package', async (done) => {
|
|
|
|
const pkg = generateDeprecateMetadata(pkgName, version, 'get deprecated');
|
|
|
|
const [err] = await putPackage(request(app), `/${encodeScopedUri(pkgName)}`, pkg, token);
|
|
|
|
if (err) {
|
|
|
|
expect(err).toBeNull();
|
|
|
|
return done(err);
|
|
|
|
}
|
2020-03-03 23:59:19 +01:00
|
|
|
const [,res] = await getPackage(request(app), '', pkgName);
|
2020-06-19 22:54:03 +02:00
|
|
|
expect(res.body.versions[version].deprecated).toEqual('get deprecated');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should undeprecate a package', async (done) => {
|
|
|
|
let pkg = generateDeprecateMetadata(pkgName, version, 'get deprecated');
|
|
|
|
await putPackage(request(app), `/${encodeScopedUri(pkgName)}`, pkg, token);
|
|
|
|
pkg = generateDeprecateMetadata(pkgName, version, '');
|
|
|
|
const [err] = await putPackage(request(app), `/${encodeScopedUri(pkgName)}`, pkg, token);
|
|
|
|
if (err) {
|
|
|
|
expect(err).toBeNull();
|
|
|
|
return done(err);
|
|
|
|
}
|
2020-03-03 23:59:19 +01:00
|
|
|
const [,res] = await getPackage(request(app), '', pkgName);
|
2020-06-19 22:54:03 +02:00
|
|
|
expect(res.body.versions[version].deprecated).not.toBeDefined();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should require both publish and unpublish access to (un)deprecate a package', async () => {
|
|
|
|
let credentials = { name: 'only_publish', password: 'secretPass' };
|
|
|
|
let token = await getNewToken(request(app), credentials);
|
|
|
|
const pkg = generateDeprecateMetadata(pkgName, version, 'get deprecated');
|
2020-03-03 23:59:19 +01:00
|
|
|
const [err, res] = await putPackage(request(app), `/${encodeScopedUri(pkgName)}`, pkg, token);
|
2020-06-19 22:54:03 +02:00
|
|
|
expect(err).not.toBeNull();
|
|
|
|
expect(res.body.error).toBeDefined();
|
2020-03-03 23:59:19 +01:00
|
|
|
expect(res.body.error).toMatch(/user only_publish is not allowed to unpublish package @scope\/deprecate/);
|
2020-06-19 22:54:03 +02:00
|
|
|
credentials = { name: 'only_unpublish', password: 'secretPass' };
|
|
|
|
token = await getNewToken(request(app), credentials);
|
2020-03-03 23:59:19 +01:00
|
|
|
const [err2, res2] = await putPackage(request(app), `/${encodeScopedUri(pkgName)}`, pkg, token);
|
2020-06-19 22:54:03 +02:00
|
|
|
expect(err2).not.toBeNull();
|
|
|
|
expect(res2.body.error).toBeDefined();
|
2020-03-03 23:59:19 +01:00
|
|
|
expect(res2.body.error).toMatch(/user only_unpublish is not allowed to publish package @scope\/deprecate/);
|
|
|
|
})
|
2020-06-19 22:54:03 +02:00
|
|
|
|
|
|
|
test('should deprecate multiple packages', async (done) => {
|
2020-03-03 23:59:19 +01:00
|
|
|
await putPackage(request(app), `/${pkgName}`, generatePackageMetadata(pkgName, '1.0.1'), token);
|
2020-06-19 22:54:03 +02:00
|
|
|
const pkg = generateDeprecateMetadata(pkgName, version, 'get deprecated');
|
|
|
|
pkg.versions['1.0.1'] = {
|
|
|
|
...generateVersion(pkgName, '1.0.1'),
|
2020-03-03 23:59:19 +01:00
|
|
|
deprecated: 'get deprecated',
|
2020-06-19 22:54:03 +02:00
|
|
|
};
|
|
|
|
await putPackage(request(app), `/${encodeScopedUri(pkgName)}`, pkg, token);
|
2020-03-03 23:59:19 +01:00
|
|
|
const [,res] = await getPackage(request(app), '', pkgName);
|
2020-06-19 22:54:03 +02:00
|
|
|
expect(res.body.versions[version].deprecated).toEqual('get deprecated');
|
|
|
|
expect(res.body.versions['1.0.1'].deprecated).toEqual('get deprecated');
|
2020-03-03 23:59:19 +01:00
|
|
|
done()
|
|
|
|
})
|
2020-06-19 22:54:03 +02:00
|
|
|
});
|
2018-01-28 14:40:38 +01:00
|
|
|
});
|
2018-01-25 21:36:26 +01:00
|
|
|
});
|