0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00

test: add unit test for login web ui

This commit is contained in:
Juan Picado @jotadeveloper 2018-03-18 13:41:36 +01:00
parent f0d2e8592f
commit d9e6e87702
No known key found for this signature in database
GPG key ID: 18AC54485952D158
2 changed files with 44 additions and 10 deletions

View file

@ -4,7 +4,7 @@ import HTTPError from 'http-errors';
import type {Config} from '@verdaccio/types';
import type {Router} from 'express';
import type {IAuth, $ResponseExtend, $RequestExtend, $NextFunctionVer} from '../../../../types';
import {combineBaseUrl, getWebProtocol} from '../../../lib/utils';
// import {combineBaseUrl, getWebProtocol} from '../../../lib/utils';
function addUserAuthApi(route: Router, auth: IAuth, config: Config) {
route.post('/login', function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
@ -22,12 +22,13 @@ function addUserAuthApi(route: Router, auth: IAuth, config: Config) {
});
});
route.post('/-/logout', function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
const base = combineBaseUrl(getWebProtocol(req), req.get('host'), config.url_prefix);
// FIXME: this will be re-implemented
// route.post('/-/logout', function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
// const base = combineBaseUrl(getWebProtocol(req), req.get('host'), config.url_prefix);
res.cookies.set('token', '');
res.redirect(base);
});
// res.cookies.set('token', '');
// res.redirect(base);
// });
}
export default addUserAuthApi;

View file

@ -12,6 +12,7 @@ import Auth from '../../src/lib/auth';
import indexAPI from '../../src/api/index';
require('../../src/lib/logger').setup([]);
const credentials = { name: 'Jota', password: 'secretPass' };
describe('endpoint unit test', () => {
let config;
@ -84,11 +85,7 @@ describe('endpoint unit test', () => {
});
describe('should test user api', () => {
const credentials = { name: 'Jota', password: 'secretPass' };
test('should test add a new user', (done) => {
request(app)
.put('/-/user/org.couchdb.user:jota')
.send(credentials)
@ -597,5 +594,41 @@ describe('endpoint unit test', () => {
});
});
});
describe('User', () => {
describe('login webui', () => {
test('should log a user jota', (done) => {
request(app)
.post('/-/verdaccio/login')
.send({
username: credentials.name,
password: credentials.password
})
.expect(200)
.end(function(err, res) {
expect(res.body.error).toBeUndefined();
expect(res.body.token).toBeDefined();
expect(res.body.token).toBeTruthy();
expect(res.body.username).toMatch(credentials.name);
done();
});
});
test('should fails on log unvalid user', (done) => {
request(app)
.post('/-/verdaccio/login')
.send(JSON.stringify({
username: 'fake',
password: 'fake'
}))
//FIXME: there should be 401
.expect(200)
.end(function(err, res) {
expect(res.body.error).toMatch(/bad username\/password, access denied/);
done();
});
});
});
});
});
});