1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/node_modules/sinopia-htpasswd/tests/acceptance.js
2014-09-14 18:28:17 +04:00

95 lines
2.2 KiB
JavaScript

var plugin = require('../')
var assert = require('assert')
var stuff = {config:{self_path:__dirname+'/config'},logger:{}}
describe('acc', function() {
before(function(cb) {
require('fs').unlink(__dirname + '/test-htpasswd', function() {
cb()
})
})
it('should have plugin interface', function() {
assert.equal(typeof plugin, 'function')
var p = plugin({file: './test-htpasswd'}, stuff)
assert.equal(typeof p.authenticate, 'function')
})
it('should not authenticate random user', function(cb) {
var p = plugin({file: './test-htpasswd'}, stuff)
p.authenticate('blah', 'blah', function(err, groups) {
assert(!err)
assert(!groups)
cb()
})
})
it('should add user', function(cb) {
var p = plugin({file: './test-htpasswd'}, stuff)
p.adduser('foo1', 'bar1', function(err, ok) {
assert(!err)
assert(ok)
cb()
})
})
describe('user', function() {
var p = plugin({file: './test-htpasswd'}, stuff)
before(function(cb) {
p.adduser('foo', 'bar', function(err, ok) {
assert(!err)
assert(ok)
cb()
})
})
it('should authenticate user', function(cb) {
p.authenticate('foo', 'bar', function(err, groups) {
assert(!err)
assert.deepEqual(groups, ['foo'])
cb()
})
})
it('should fail different pass', function(cb) {
p.authenticate('foo', 'bar111', function(err, groups) {
assert(!err)
assert(!groups)
cb()
})
})
it('should fail adding it again', function(cb) {
p.adduser('foo', 'bar111', function(err, ok) {
assert(err)
cb()
})
})
it('still should not authenticate random user', function(cb) {
p.authenticate('blah', 'wow', function(err, groups) {
assert(!err)
assert(!groups)
cb()
})
})
})
describe('max_users', function() {
var p = plugin({file: './test-htpasswd', max_users: 1}, stuff)
before(function(cb) {
p.adduser('foo', 'bar', function(err, ok) {
cb()
})
})
it('should not add more users', function(cb) {
p.adduser('foozzz', 'bar', function(err) {
assert(err)
cb()
})
})
})
})