http-auth testsNode.js package for HTTP basic and digest access authentication. | |
| tests/test-options.js |
Options module.
|
var opt = require('../lib/options');
|
Utils module.
|
var utils = require('../lib/utils');
|
Test for empty options.
|
exports['testEmptyOptions'] = function (test) {
test.throws(function () {
opt();
}, Error, "Must throw an error when options are empty!");
test.done();
};
|
Test for invalid authType.
|
exports['testInvalidAuthType'] = function (test) {
test.throws(function () {
opt({authType : 'some other type'});
}, Error, "Must throw an error when authType is invalid!");
test.done();
};
|
Test for default authType.
|
exports['testDefaultAuthType'] = function (test) {
var options = opt({
authRealm : "Private area with digest access authentication.",
authList : ['aa2sdas:s3sss', 'gi33ra:makaura']
});
test.equals(options.authType, 'digest', "Default authType must be digest!")
test.done();
};
|
Test for invalid algorithm.
|
exports['testInvalidAlgo'] = function (test) {
test.throws(function () {
opt({
authRealm : "Private area with digest access authentication.",
authList : ['asdasw:ssqss', 'gidra:maakura'],
algorithm : 'monkeyCrypt'
});
}, Error, "Must throw an error when algorithm is invalid!");
test.done();
};
|
Test for default algorithm.
|
exports['testDefaultAlgo'] = function (test) {
var options = opt({
authRealm : "Private area with digest access authentication.",
authList : ['aa2sdasa:s3s2ss', 'gi3q3ra:mwakaura']
});
test.equals(options.algorithm, 'MD5', "Default algorithm must be MD5!")
test.done();
};
|
Test for invalid realm.
|
exports['testInvalidRealm'] = function (test) {
test.throws(function () {
opt({
authRealm : "",
authList : ['asdasw:ssqss', 'gidra:maakura']
});
}, Error, "Must throw an error when authRealm is empty!");
test.done();
};
|
Test for empty authList.
|
exports['testInvalidAuthList'] = function (test) {
test.throws(function () {
opt({
authRealm : "Some realm",
authList : []
});
}, Error, "Must throw an error when authList is empty!");
test.done();
};
|
Test for valid authList - digest.
|
exports['testValidAuthListDigest'] = function (test) {
var options = opt({
authRealm : "Some realm",
authList : ['karo:seed', 'samvel:beed']
});
test.notEqual(options.authUsers, null, "authUsers must not be empty!");
test.equals(options.authUsers['karo'], 'karo:Some realm:seed', "User item is wrong!");
test.equals(options.authUsers['samvel'], 'samvel:Some realm:beed', "User item is wrong!");
test.done();
};
|
Test for valid authList - basic.
|
exports['testValidAuthListBasic'] = function (test) {
var options = opt({
authRealm : "Some realm",
authList : ['karo:seed', 'samvel:beed'],
authType : 'basic'
});
test.notEqual(options.authUsers, null, "authUsers must not be empty!");
test.equals(options.authUsers[0], utils.base64('karo:seed'), "User item is wrong!");
test.equals(options.authUsers[1], utils.base64('samvel:beed'), "User item is wrong!");
test.done();
};
|
Test for valid authFile.
|
exports['testValidAuthFile'] = function (test) {
var options = opt({
authRealm : "Some realm",
authList : ['karo:seed', 'samvel:beed'],
authFile : __dirname + '/../examples/users.htpasswd',
authType : 'basic'
});
test.notEqual(options.authUsers, null, "authUsers must not be empty!");
test.equals(options.authUsers[0], utils.base64('Sarah:testpass'), "User item is wrong!");
test.equals(options.authUsers[1], utils.base64('John:itismypass'), "User item is wrong!");
test.equals(options.authUsers[2], utils.base64('Shanon:noneof'), "User item is wrong!");
test.equals(options.authUsers[3], utils.base64('Mike:pass123'), "User item is wrong!");
test.done();
};
|
| tests/test-provider.js |
Provider module.
|
var provider = require('../lib/provider');
|
Test for valid basic access authentication.
|
exports['testValidBasicAuth'] = function (test) {
var basic = provider.newInstance({
authRealm : "Private area with basic access authentication.",
authList : ['Kuka:pi2', 'suma:kramoke'],
authType : 'basic'
});
test.notEqual(basic, null, "Basic access authentication instance is empty!");
test.notEqual(basic.apply, null, "Basic access authentication instance has no apply method!");
test.done();
};
|
Test for valid digest access authentication.
|
exports['testValidDigestAuth'] = function (test) {
var digest = provider.newInstance({
authRealm : "Private area with digest access authentication.",
authList : ['asdas:ssss', 'gira:makura'],
authType : 'digest'
});
test.notEqual(digest, null, "Digest access authentication instance is empty!");
test.notEqual(digest.apply, null, "Digest access authentication instance has no apply method!");
test.done();
};
|
Test for empty options.
|
exports['testInvalidAuthOptions'] = function (test) {
test.throws(function() {
provider.newInstance();
}, Error, "Must throw an error when no options are provided!");
test.done();
};
|
Test for invalid authType.
|
exports['testInvalidAuthType'] = function (test) {
test.throws(function () {
provider.newInstance({authType : 'some type'});
}, Error, "Must throw an error when authType is wrong!");
test.done();
};
|
| tests/test-utils.js |
Utility module.
|
var utils = require('../lib/utils');
|
Base64 test with ASCII.
|
exports['testBase64ASCII'] = function (test) {
test.equal(utils.base64("some text"), "c29tZSB0ZXh0", "ASCII string is not encoded correctly!");
test.done();
};
|
Base64 test with unicode.
|
exports['testBase64Unicode'] = function (test) {
test.equal(utils.base64("այսպես"), "aHVtdW91brVpdW9", "Unicode string is not encoded correctly!");
test.done();
};
|
MD5 test with ASCII.
|
exports['testMD5ASCII'] = function (test) {
test.equal(utils.base64("other text"), "b3RoZXIgdGV4dA==", "MD5 hash is not correct for ASCII string!");
test.done();
};
|
MD5 test with unicode.
|
exports['testMD5Unicode'] = function (test) {
test.equal(utils.base64("այնպես"), "aHVtdW21brVpdW9", "MD5 hash is not correct for unicode string!");
test.done();
};
|
| tests/test-http-auth.js |
HTTP authentication module.
|
var auth = require('../lib/http-auth');
|
Test for basic access authentication.
|
exports['testBasicAuth'] = function (test) {
var basic = auth({
authRealm : "Private area with basic access authentication.",
authList : ['Shi:many222', 'Lota:123456'],
authType : 'basic'
});
test.notEqual(basic, null, "Basic access authentication instance is empty!");
test.notEqual(basic.apply, null, "Basic access authentication instance has no apply method!");
test.done();
};
|
Test for digest access authentication.
|
exports['testDigestAuth'] = function (test) {
var digest = auth({
authRealm : "Private area with digest access authentication.",
authList : ['2Shi:ma22y222', '3Lota:1123456'],
authType : 'digest'
});
test.notEqual(digest, null, "Digest access authentication instance is empty!");
test.notEqual(digest.apply, null, "Digest access authentication instance has no apply method!");
test.done();
};
|