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';
|
|
|
|
import rimraf from 'rimraf';
|
|
|
|
|
2018-06-17 13:34:59 +02:00
|
|
|
import configDefault from '../partials/config/index';
|
|
|
|
import publishMetadata from '../partials/publish-api';
|
|
|
|
import Config from '../../../src/lib/config';
|
|
|
|
import endPointAPI from '../../../src/api/index';
|
2018-06-24 22:39:09 +02:00
|
|
|
|
2018-11-18 18:41:05 +01:00
|
|
|
import { HEADERS, API_ERROR, HTTP_STATUS, HEADER_TYPE, API_MESSAGE} from '../../../src/lib/constants';
|
2018-06-24 22:39:09 +02:00
|
|
|
import {mockServer} from './mock';
|
|
|
|
import {DOMAIN_SERVERS} from '../../functional/config.functional';
|
2018-01-25 21:36:26 +01:00
|
|
|
|
2018-06-17 13:34:59 +02:00
|
|
|
require('../../../src/lib/logger').setup([]);
|
2018-11-18 18:41:05 +01:00
|
|
|
const credentials = { name: 'jota', password: 'secretPass' };
|
2018-01-25 21:36:26 +01:00
|
|
|
|
|
|
|
describe('endpoint unit test', () => {
|
|
|
|
let config;
|
|
|
|
let app;
|
2018-06-24 22:39:09 +02:00
|
|
|
let mockRegistry;
|
2018-01-25 21:36:26 +01:00
|
|
|
|
2018-01-25 23:14:03 +01:00
|
|
|
beforeAll(function(done) {
|
2018-06-17 13:34:59 +02:00
|
|
|
const store = path.join(__dirname, '../partials/store/test-storage');
|
2018-06-24 22:39:09 +02:00
|
|
|
const mockServerPort = 55549;
|
2018-04-21 18:36:06 +02:00
|
|
|
rimraf(store, async () => {
|
2018-01-25 23:14:03 +01:00
|
|
|
const configForTest = _.clone(configDefault);
|
|
|
|
configForTest.auth = {
|
|
|
|
htpasswd: {
|
2018-06-30 17:13:53 +02:00
|
|
|
file: './test-storage/.htpasswd'
|
2018-01-25 23:14:03 +01:00
|
|
|
}
|
|
|
|
};
|
2018-06-24 22:39:09 +02:00
|
|
|
configForTest.uplinks = {
|
|
|
|
npmjs: {
|
|
|
|
url: `http://${DOMAIN_SERVERS}:${mockServerPort}`
|
|
|
|
}
|
|
|
|
};
|
2018-01-25 23:14:03 +01:00
|
|
|
configForTest.self_path = store;
|
|
|
|
config = new Config(configForTest);
|
2018-04-21 18:36:06 +02:00
|
|
|
app = await endPointAPI(config);
|
2018-06-24 22:39:09 +02:00
|
|
|
mockRegistry = await mockServer(mockServerPort).init();
|
2018-01-25 23:14:03 +01:00
|
|
|
done();
|
|
|
|
});
|
2018-01-25 21:36:26 +01:00
|
|
|
});
|
|
|
|
|
2018-06-24 22:39:09 +02:00
|
|
|
afterAll(function(done) {
|
|
|
|
mockRegistry[0].stop();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
describe('Registry API Endpoints', () => {
|
|
|
|
|
|
|
|
describe('should test ping api', () => {
|
2018-04-29 21:50:10 +02:00
|
|
|
test('should test endpoint /-/ping', (done) => {
|
2018-03-18 08:46:02 +01:00
|
|
|
request(app)
|
|
|
|
.get('/-/ping')
|
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)
|
2018-06-25 07:59:35 +02:00
|
|
|
.end(function(err) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-01-25 21:36:26 +01:00
|
|
|
});
|
2018-01-25 23:14:03 +01:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
describe('should test whoami api', () => {
|
|
|
|
test('should test /-/whoami endpoint', (done) => {
|
|
|
|
request(app)
|
|
|
|
.get('/-/whoami')
|
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)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should test /whoami endpoint', (done) => {
|
|
|
|
request(app)
|
|
|
|
.get('/-/whoami')
|
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)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-01-25 21:36:26 +01:00
|
|
|
});
|
2018-01-25 23:14:03 +01:00
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
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')
|
|
|
|
.set('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)
|
2018-04-29 21:50:10 +02:00
|
|
|
.end(function(err, res) {
|
|
|
|
expect(res.body.error).toBeDefined();
|
2018-11-15 20:14:56 +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')
|
|
|
|
.set('authorization', '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)
|
2018-04-29 21:50:10 +02:00
|
|
|
.end(function(err, res) {
|
|
|
|
expect(res.body.error).toBeDefined();
|
2018-11-15 20:14:56 +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')
|
|
|
|
.set('authorization', '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)
|
2018-04-29 21:50:10 +02:00
|
|
|
.end(function(err, res) {
|
|
|
|
expect(res.body.error).toBeDefined();
|
2018-11-15 20:14:56 +01:00
|
|
|
expect(res.body.error).toMatch(/authorization required to access package auth-package/);
|
2018-04-29 21:50:10 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
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)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
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')
|
|
|
|
.set('authorization', `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)
|
2018-04-29 21:50:10 +02:00
|
|
|
.end(function(err, res) {
|
|
|
|
expect(err).toBeNull();
|
|
|
|
expect(res.body).toBeDefined();
|
|
|
|
expect(res.body.name).toMatch(/vue/);
|
|
|
|
done();
|
|
|
|
});
|
2018-03-18 08:46:02 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should test fails add a new user with missing name', (done) => {
|
|
|
|
|
|
|
|
const credentialsShort = _.clone(credentials);
|
|
|
|
delete credentialsShort.name;
|
|
|
|
|
|
|
|
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(credentialsShort)
|
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.BAD_REQUEST)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(res.body.error).toBeDefined();
|
2018-11-18 18:41:05 +01:00
|
|
|
expect(res.body.error).toMatch(API_ERROR.USERNAME_PASSWORD_REQUIRED);
|
2018-03-18 08:46:02 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should test fails add a new user with missing password', (done) => {
|
|
|
|
|
|
|
|
const credentialsShort = _.clone(credentials);
|
|
|
|
delete credentialsShort.password;
|
|
|
|
|
|
|
|
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(credentialsShort)
|
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.BAD_REQUEST)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(res.body.error).toBeDefined();
|
|
|
|
//FIXME: message is not 100% accurate
|
2018-10-12 11:07:55 +02:00
|
|
|
expect(res.body.error).toMatch(API_ERROR.PASSWORD_SHORT());
|
2018-03-18 08:46:02 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should test add a new user with login', (done) => {
|
2018-04-03 07:08:44 +02:00
|
|
|
const newCredentials = _.clone(credentials);
|
|
|
|
newCredentials.name = 'jotaNew';
|
2018-03-18 08:46:02 +01:00
|
|
|
|
|
|
|
request(app)
|
2018-04-03 07:08:44 +02:00
|
|
|
.put('/-/user/org.couchdb.user:jotaNew')
|
|
|
|
.send(newCredentials)
|
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)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
expect(res.body).toBeTruthy();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-03 07:08:44 +02:00
|
|
|
test('should test fails on add a existing user with login', (done) => {
|
|
|
|
request(app)
|
|
|
|
.put('/-/user/org.couchdb.user:jotaNew')
|
|
|
|
.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.CONFLICT)
|
2018-04-03 07:08:44 +02:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
expect(res.body.error).toBeDefined();
|
2018-11-18 18:41:05 +01:00
|
|
|
expect(res.body.error).toMatch(API_ERROR.USERNAME_ALREADY_REGISTERED);
|
2018-04-03 07:08:44 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
test('should test fails add a new user with wrong password', (done) => {
|
|
|
|
|
|
|
|
const credentialsShort = _.clone(credentials);
|
|
|
|
credentialsShort.password = 'failPassword';
|
|
|
|
|
|
|
|
request(app)
|
|
|
|
.put('/-/user/org.couchdb.user:jota')
|
|
|
|
.send(credentialsShort)
|
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.UNAUTHORIZED)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(res.body.error).toBeDefined();
|
|
|
|
expect(res.body.error).toMatch(/unauthorized/);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-01-26 07:35:41 +01:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
describe('should test package api', () => {
|
|
|
|
|
|
|
|
test('should fetch jquery package from remote uplink', (done) => {
|
|
|
|
|
|
|
|
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)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
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) => {
|
|
|
|
|
|
|
|
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)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
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) => {
|
|
|
|
|
|
|
|
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)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
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) => {
|
|
|
|
|
|
|
|
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)
|
2018-06-25 07:59:35 +02: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) => {
|
|
|
|
|
|
|
|
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)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should forbid access to remote package', (done) => {
|
|
|
|
|
|
|
|
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)
|
2018-06-25 07:59:35 +02: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) => {
|
|
|
|
|
|
|
|
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)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(res.body).toBeDefined();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should fails fetch a tarball from remote uplink', (done) => {
|
|
|
|
|
|
|
|
request(app)
|
|
|
|
.get('/jquery/-/jquery-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)
|
2018-06-25 07:59:35 +02: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();
|
|
|
|
});
|
|
|
|
});
|
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 = {
|
|
|
|
'beta': '3.0.0',
|
|
|
|
'jota': '1.6.3'
|
|
|
|
};
|
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) => {
|
|
|
|
|
|
|
|
request(app)
|
|
|
|
.put('/jquery/verdaccio-tag')
|
|
|
|
.send(JSON.stringify(jqueryVersion))
|
|
|
|
.set('accept', 'gzip')
|
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.CREATED)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
2018-06-25 07:59:35 +02:00
|
|
|
expect.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) => {
|
|
|
|
|
|
|
|
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)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
2018-06-25 07:59:35 +02:00
|
|
|
expect.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) => {
|
|
|
|
|
|
|
|
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)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
2018-06-25 07:59:35 +02:00
|
|
|
expect.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) => {
|
|
|
|
|
|
|
|
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)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
2018-06-25 07:59:35 +02:00
|
|
|
expect.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) => {
|
|
|
|
|
|
|
|
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)
|
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)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
2018-06-25 07:59:35 +02:00
|
|
|
expect.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();
|
|
|
|
});
|
|
|
|
});
|
2018-01-28 11:38:22 +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) => {
|
|
|
|
const now = Date.now()
|
|
|
|
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)
|
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)
|
2018-06-25 07:59:35 +02:00
|
|
|
.end(function(err) {
|
2018-03-18 08:46:02 +01:00
|
|
|
if (err) {
|
2018-06-25 07:59:35 +02:00
|
|
|
expect.toBeNull();
|
2018-03-18 08:46:02 +01:00
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
//TODO: we have to catch the stream check whether it returns something
|
|
|
|
// we should not spend much time on this api since is deprecated somehow.
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-01-28 14:40:38 +01:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-03-18 08:46:02 +01:00
|
|
|
describe('should test publish api', () => {
|
|
|
|
test('should publish a new package', (done) => {
|
|
|
|
request(app)
|
|
|
|
.put('/@scope%2fpk1-test')
|
2018-06-24 22:39:09 +02:00
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
2018-03-18 08:46:02 +01:00
|
|
|
.send(JSON.stringify(publishMetadata))
|
2018-06-24 22:39:09 +02:00
|
|
|
.expect(HTTP_STATUS.CREATED)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
2018-06-25 07:59:35 +02:00
|
|
|
expect.toBeNull();
|
2018-03-18 08:46:02 +01:00
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
expect(res.body.ok).toBeDefined();
|
|
|
|
expect(res.body.success).toBeDefined();
|
|
|
|
expect(res.body.success).toBeTruthy();
|
2018-06-25 07:59:35 +02:00
|
|
|
expect(res.body.ok).toMatch(API_MESSAGE.PKG_CREATED);
|
2018-03-18 08:46:02 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should unpublish a new package', (done) => {
|
|
|
|
//FUTURE: for some reason it does not remove the scope folder
|
|
|
|
request(app)
|
|
|
|
.del('/@scope%2fpk1-test/-rev/4-6abcdb4efd41a576')
|
2018-06-24 22:39:09 +02:00
|
|
|
.set(HEADER_TYPE.CONTENT_TYPE, HEADERS.JSON)
|
|
|
|
.expect(HTTP_STATUS.CREATED)
|
2018-03-18 08:46:02 +01:00
|
|
|
.end(function(err, res) {
|
|
|
|
if (err) {
|
2018-06-25 07:59:35 +02:00
|
|
|
expect.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.PKG_REMOVED);
|
2018-03-18 08:46:02 +01:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-01-28 14:40:38 +01:00
|
|
|
});
|
|
|
|
});
|
2018-01-25 21:36:26 +01:00
|
|
|
});
|