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

test(unit): add test for add_user and login

This commit is contained in:
Juan Picado @jotadeveloper 2018-01-26 07:35:41 +01:00
parent 67c63892d3
commit aa3101ef9a
No known key found for this signature in database
GPG key ID: 18AC54485952D158
2 changed files with 68 additions and 3 deletions

View file

@ -5,7 +5,6 @@ import {loadPlugin} from '../lib/plugin-loader';
const Crypto = require('crypto');
const Error = require('http-errors');
const Logger = require('./logger');
const pkgJson = require('../../package.json');
const jwt = require('jsonwebtoken');
/**
* Handles the authentification, load auth plugins.

View file

@ -82,7 +82,7 @@ describe('endpoint unit test', () => {
describe('should test user api', () => {
const credentials = { name: 'Jota', password: 'secretPass' };
test('test add a new user', (done) => {
test('should test add a new user', (done) => {
request(app)
@ -101,7 +101,49 @@ describe('endpoint unit test', () => {
});
});
test('test fails add a new user', (done) => {
test('should test fails add a new user with missing name', (done) => {
const credentialsShort = _.clone(credentials);
delete credentialsShort.name;
request(app)
.put('/-/user/org.couchdb.user:jota')
.send(credentialsShort)
.expect('Content-Type', /json/)
.expect(409)
.end(function(err, res) {
if (err) {
return done(err);
}
expect(res.body.error).toBeDefined();
expect(res.body.error).toMatch(/username should not contain non-uri-safe characters/);
done();
});
});
test('should test fails add a new user with missing password', (done) => {
const credentialsShort = _.clone(credentials);
delete credentialsShort.password;
request(app)
.put('/-/user/org.couchdb.user:jota')
.send(credentialsShort)
.expect('Content-Type', /json/)
.expect(409)
.end(function(err, res) {
if (err) {
return done(err);
}
expect(res.body.error).toBeDefined();
expect(res.body.error).toMatch(/this user already exists/);
done();
});
});
test('should test fails add a new user', (done) => {
request(app)
.put('/-/user/org.couchdb.user:jota')
@ -119,6 +161,30 @@ describe('endpoint unit test', () => {
});
});
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)
.expect('Content-Type', /json/)
//TODO: this should return 401 and will fail when issue
// https://github.com/verdaccio/verdaccio-htpasswd/issues/5
// is being fixed
.expect(409)
.end(function(err, res) {
if (err) {
return done(err);
}
expect(res.body.error).toBeDefined();
expect(res.body.error).toMatch(/this user already exists/);
done();
});
});
});
});