mirror of https://gitee.com/bigwinds/arangodb
54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
/*jslint indent: 2, nomen: true, maxlen: 120, es5: true */
|
|
/*global require, module, describe, it, beforeEach */
|
|
(function () {
|
|
'use strict';
|
|
var sinon = require('sinon'),
|
|
expect = require('expect.js'),
|
|
mockuire;
|
|
|
|
mockuire = require('mockuire')(module, {
|
|
'js': {compile: function (src) {
|
|
return 'var applicationContext = require("applicationContext");\n' + src;
|
|
}}
|
|
});
|
|
|
|
describe('hashPassword', function () {
|
|
var cfg = {}, crypto = {}, hashPassword;
|
|
|
|
hashPassword = mockuire('../auth', {
|
|
applicationContext: {configuration: cfg},
|
|
'org/arangodb/crypto': crypto
|
|
}).hashPassword;
|
|
|
|
beforeEach(function () {
|
|
cfg.hashMethod = 'bogohash';
|
|
crypto.bogohash = sinon.stub();
|
|
crypto.genRandomAlphaNumbers = sinon.stub();
|
|
});
|
|
|
|
it('uses the hash method defined by the configuration', function () {
|
|
var result = hashPassword('secret');
|
|
expect(result.method).to.equal(cfg.hashMethod);
|
|
});
|
|
|
|
it('uses the salt length defined by the configuration', function () {
|
|
cfg.saltLength = 42;
|
|
var result = hashPassword('secret');
|
|
expect(crypto.genRandomAlphaNumbers.callCount).to.equal(1);
|
|
expect(crypto.genRandomAlphaNumbers.args[0]).to.eql([42]);
|
|
});
|
|
|
|
it('prefixes the password with the salt', function () {
|
|
crypto.genRandomAlphaNumbers.returns('keyboardcat');
|
|
var result = hashPassword('secret');
|
|
expect(crypto.bogohash.callCount).to.equal(1);
|
|
expect(crypto.bogohash.args[0]).to.eql(['keyboardcatsecret']);
|
|
});
|
|
|
|
it('retuns the hashed password', function () {
|
|
crypto.bogohash.returns('somekindofhash');
|
|
var result = hashPassword();
|
|
expect(result.hash).to.equal('somekindofhash');
|
|
});
|
|
});
|
|
}()); |