Преглед на файлове

remove ava to use same test suite with webcrypto

pull/342/head
Guillaume Vincent преди 8 години
родител
ревизия
4dd321fdcb
променени са 6 файла, в които са добавени 419 реда и са изтрити 397 реда
  1. +4
    -9
      package.json
  2. +251
    -237
      tests/api.tests.js
  3. +68
    -64
      tests/deriveEncryptedLogin.tests.js
  4. +60
    -52
      tests/getPasswordTemplate.tests.js
  5. +3
    -0
      tests/helper.js
  6. +33
    -35
      tests/prettyPrint.js

+ 4
- 9
package.json Целия файл

@@ -8,9 +8,9 @@
"repository": "lesspass/core",
"scripts": {
"test:node": "npm run build && cd tests && babel-node --presets es2015 node.js && cd ..",
"test": "ava --require babel-core/register",
"test": "mocha --compilers js:babel-register --require ./tests/helper.js tests",
"build": "rimraf lib && babel index.js -d lib",
"prepublish": "npm test && npm run build"
"prepublish": "npm test && npm run build && npm run test:node"
},
"files": [
"lib/",
@@ -23,21 +23,16 @@
],
"license": "MIT",
"devDependencies": {
"ava": "^0.16.0",
"babel-cli": "^6.16.0",
"babel-core": "^6.17.0",
"babel-preset-es2015": "^6.16.0",
"chai": "^3.5.0",
"mocha": "^3.1.2",
"rimraf": "^2.5.4"
},
"babel": {
"presets": [
"es2015"
]
},
"ava": {
"files": [
"tests/*.js",
"!tests/node.js"
]
}
}

+ 251
- 237
tests/api.tests.js Целия файл

@@ -1,251 +1,265 @@
import test from 'ava';
import lesspass from '../index';
var assert = chai.assert;

test('should use pbkdf2 with 8192 iterations and sha256', t=> {
lesspass.encryptLogin('test@example.org', 'password').then(function (encryptedLogin) {
t.is('d8af5f918db6b65b1db3d3984e5a400e39e1dbb19462220e4431de283809f472', encryptedLogin);
});
});
describe('LessPass', function () {
describe('encryptLogin', function () {
it('should use pbkdf2 with 8192 iterations and sha256', function (done) {
LessPass.encryptLogin('test@example.org', 'password').then(function (encryptedLogin) {
assert.equal('d8af5f918db6b65b1db3d3984e5a400e39e1dbb19462220e4431de283809f472', encryptedLogin);
done();
});
});

test('should allow utf8 parameter', t=> {
lesspass.encryptLogin('test@example.org', '♥ LessPass ♥').then(function (encryptedLogin) {
t.is('997fe81d3d0db236e039c75efdb487f17a902fdf94f9dacaa9884329c85d9651', encryptedLogin);
});
});
test('auto generated encrypt login tests', t => {
var promises = [];
var passwords = [
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'lesspass',
masterPassword: 'password',
encryptedLogin: '7d05ee25597dcc3ac16d082aa910e7707f75be620ed8db5bef7245e2a8579116',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password2',
encryptedLogin: 'ce853092fc54fe88c281e38df97bd5826d64e6bee315dc94939cbba8930df0e4',
}
];
it('should allow utf8 parameter', function (done) {
LessPass.encryptLogin('test@example.org', '♥ LessPass ♥').then(function (encryptedLogin) {
assert.equal('997fe81d3d0db236e039c75efdb487f17a902fdf94f9dacaa9884329c85d9651', encryptedLogin);
done();
});
});
it('auto generated encrypt login tests', function () {
var promises = [];
var passwords = [
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password',
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
},
{
login: 'lesspass',
masterPassword: 'password',
encryptedLogin: '7d05ee25597dcc3ac16d082aa910e7707f75be620ed8db5bef7245e2a8579116',
},
{
login: 'contact@lesspass.com',
masterPassword: 'password2',
encryptedLogin: 'ce853092fc54fe88c281e38df97bd5826d64e6bee315dc94939cbba8930df0e4',
}
];

for (var entry of passwords) {
promises.push(lesspass.encryptLogin(entry.login, entry.masterPassword));
}
for (var entry of passwords) {
promises.push(LessPass.encryptLogin(entry.login, entry.masterPassword));
}

return Promise.all(promises).then(values => {
for (let i = 0; i < values.length; i++) {
t.is(passwords[i].encryptedLogin, values[i]);
}
return Promise.all(promises).then(values => {
for (let i = 0; i < values.length; i++) {
assert.equal(passwords[i].encryptedLogin, values[i]);
}
});
});
});
});
test('render password', t => {
var site = 'lesspass.com';
var encryptedLogin = '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0';
var passwordOptions = {
counter: 1,
length: 12,
lowercase: true,
uppercase: true,
numbers: true,
symbols: true
};
lesspass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
t.is('azYS7,olOL2]', generatedPassword);
})
});
test('auto generated render password tests', t => {
var promises = [];
var passwords = [
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: true,
uppercase: true,
numbers: true,
symbols: true,
generatedPassword: 'azYS7,olOL2]'
},
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 1,
length: 14,
lowercase: true,
uppercase: true,
numbers: true,
symbols: true,
generatedPassword: 'azYS7,olOL2]iz'
},
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: true,
uppercase: false,
numbers: false,
symbols: false,
generatedPassword: 'azyseqololat'
},
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: false,
uppercase: true,
numbers: true,
symbols: true,
generatedPassword: 'AZ3[EQ7@OL2]'
},
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: false,
uppercase: false,
numbers: true,
symbols: true,
generatedPassword: '4?3[7,7@7@2]'
},
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: false,
uppercase: false,
numbers: false,
symbols: true,
generatedPassword: '[?=[&,:@:@[]'
},
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: true,
uppercase: true,
numbers: true,
symbols: false,
generatedPassword: 'azYS7uwAW8at'
},
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: true,
uppercase: true,
numbers: false,
symbols: false,
generatedPassword: 'azYSeqOLolAT'
},
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 2,
length: 12,
lowercase: true,
uppercase: true,
numbers: true,
symbols: true,
generatedPassword: 'obYT2=olOV9='
},
{
encryptedLogin: '7d05ee25597dcc3ac16d082aa910e7707f75be620ed8db5bef7245e2a8579116',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: true,
uppercase: true,
numbers: true,
symbols: true,
generatedPassword: 'erOC1%imIW3,'
},
{
encryptedLogin: 'ce853092fc54fe88c281e38df97bd5826d64e6bee315dc94939cbba8930df0e4',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: true,
uppercase: true,
numbers: true,
symbols: true,
generatedPassword: 'uvUM5_ucUP5='
}
];

for (var entry of passwords) {
var passwordOption = {
counter: entry.counter,
length: entry.length,
lowercase: entry.lowercase,
uppercase: entry.uppercase,
numbers: entry.numbers,
symbols: entry.symbols,
};
promises.push(lesspass.renderPassword(entry.encryptedLogin, entry.site, passwordOption));
}
describe('LessPass', function () {
describe('renderPassword', function () {
it('render password', function () {
var site = 'lesspass.com';
var encryptedLogin = '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0';
var passwordOptions = {
counter: 1,
length: 12,
lowercase: true,
uppercase: true,
numbers: true,
symbols: true
};
LessPass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
assert.equal('azYS7,olOL2]', generatedPassword);
})
});
it('auto generated render password tests', function () {
var promises = [];
var passwords = [
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: true,
uppercase: true,
numbers: true,
symbols: true,
generatedPassword: 'azYS7,olOL2]'
},
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 1,
length: 14,
lowercase: true,
uppercase: true,
numbers: true,
symbols: true,
generatedPassword: 'azYS7,olOL2]iz'
},
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: true,
uppercase: false,
numbers: false,
symbols: false,
generatedPassword: 'azyseqololat'
},
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: false,
uppercase: true,
numbers: true,
symbols: true,
generatedPassword: 'AZ3[EQ7@OL2]'
},
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: false,
uppercase: false,
numbers: true,
symbols: true,
generatedPassword: '4?3[7,7@7@2]'
},
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: false,
uppercase: false,
numbers: false,
symbols: true,
generatedPassword: '[?=[&,:@:@[]'
},
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: true,
uppercase: true,
numbers: true,
symbols: false,
generatedPassword: 'azYS7uwAW8at'
},
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: true,
uppercase: true,
numbers: false,
symbols: false,
generatedPassword: 'azYSeqOLolAT'
},
{
encryptedLogin: '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0',
site: 'lesspass.com',
counter: 2,
length: 12,
lowercase: true,
uppercase: true,
numbers: true,
symbols: true,
generatedPassword: 'obYT2=olOV9='
},
{
encryptedLogin: '7d05ee25597dcc3ac16d082aa910e7707f75be620ed8db5bef7245e2a8579116',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: true,
uppercase: true,
numbers: true,
symbols: true,
generatedPassword: 'erOC1%imIW3,'
},
{
encryptedLogin: 'ce853092fc54fe88c281e38df97bd5826d64e6bee315dc94939cbba8930df0e4',
site: 'lesspass.com',
counter: 1,
length: 12,
lowercase: true,
uppercase: true,
numbers: true,
symbols: true,
generatedPassword: 'uvUM5_ucUP5='
}
];

for (var entry of passwords) {
var passwordOption = {
counter: entry.counter,
length: entry.length,
lowercase: entry.lowercase,
uppercase: entry.uppercase,
numbers: entry.numbers,
symbols: entry.symbols,
};
promises.push(LessPass.renderPassword(entry.encryptedLogin, entry.site, passwordOption));
}

return Promise.all(promises).then(values => {
for (let i = 0; i < values.length; i++) {
t.is(passwords[i].generatedPassword, values[i]);
}
return Promise.all(promises).then(values => {
for (let i = 0; i < values.length; i++) {
assert.equal(passwords[i].generatedPassword, values[i]);
}
});
});
});
});


test('createFingerprint', t => {
return lesspass.createFingerprint('password').then(fingerprint => {
t.is('e56a207acd1e6714735487c199c6f095844b7cc8e5971d86c003a7b6f36ef51e', fingerprint);
describe('LessPass', function () {
describe('fingerprint', function () {
it('createFingerprint', function (done) {
LessPass.createFingerprint('password').then(function (fingerprint) {
assert.equal('e56a207acd1e6714735487c199c6f095844b7cc8e5971d86c003a7b6f36ef51e', fingerprint);
done();
})
});
});
});


+ 68
- 64
tests/deriveEncryptedLogin.tests.js Целия файл

@@ -1,68 +1,72 @@
import test from 'ava';
import lesspass from '../index';
var assert = chai.assert;

test('should createHmac', t => {
var encryptedLogin = '9f505f3a95fe0485da3242cb81c9fe25c2f400d8399737655a8dad2b52778d88';
var salt = 'lesspass.com1';
return lesspass._createHmac(encryptedLogin, salt).then(hmac => {
t.is('be00f942fc8aa67d8e76fc2456862b9d66d166ebfdd3dc2f0116e278209532ed', hmac);
});
});
test('should derive encrypted login with default options', t => {
const encryptedLogin = '90cff82b8847525370a8f29a59ecf45db62c719a535788ad0df58d32304e925d';
const site = 'lesspass.com';
const option = {
counter: 1,
length: 12,
lowercase: true,
uppercase: true,
numbers: true,
symbols: true,
};
var p1 = lesspass._deriveEncryptedLogin(encryptedLogin, site);
var p2 = lesspass._deriveEncryptedLogin(encryptedLogin, site, option);
Promise.all([p1, p2]).then(generatedPasswords => {
t.is(generatedPasswords[0], generatedPasswords[1])
});
});
test('should derive encrypted login with defined length', t => {
var encryptedLogin = 'd79d8482f708122288af7b259393a58fe05840f4555cc935cdd3f062b9aa75ed';
var site = 'lesspass.com';
var option = {
counter: 1,
length: 10,
};
return lesspass._deriveEncryptedLogin(encryptedLogin, site, option).then(function (generatedPassword) {
t.is(10, generatedPassword.length);
})
});
test('should return two different passwords if site different', t => {
const encryptedLogin = 'f4fd3885fb70085f2285c3382e2d9adb4c2553285fc45dd896791aa5e79070a9';
const site = 'google.com';
const site2 = 'facebook.com';
var p1 = lesspass._deriveEncryptedLogin(encryptedLogin, site);
var p2 = lesspass._deriveEncryptedLogin(encryptedLogin, site2);
Promise.all([p1, p2]).then(derivedEncryptedLogins => {
t.not(derivedEncryptedLogins[0], derivedEncryptedLogins[1])
describe('LessPass', function () {
describe('deriveEncryptedLogin', function () {
it('should createHmac', function (done) {
var encryptedLogin = '9f505f3a95fe0485da3242cb81c9fe25c2f400d8399737655a8dad2b52778d88';
var salt = 'lesspass.com1';
LessPass._createHmac(encryptedLogin, salt).then(function (hmac) {
assert.equal('be00f942fc8aa67d8e76fc2456862b9d66d166ebfdd3dc2f0116e278209532ed', hmac);
done();
});
});
it('should derive encrypted login with default options', function () {
const encryptedLogin = '90cff82b8847525370a8f29a59ecf45db62c719a535788ad0df58d32304e925d';
const site = 'lesspass.com';
const option = {
counter: 1,
length: 12,
lowercase: true,
uppercase: true,
numbers: true,
symbols: true,
};
var p1 = LessPass._deriveEncryptedLogin(encryptedLogin, site);
var p2 = LessPass._deriveEncryptedLogin(encryptedLogin, site, option);
Promise.all([p1, p2]).then(generatedPasswords => {
assert.equal(generatedPasswords[0], generatedPasswords[1])
});
});
it('should derive encrypted login with defined length', function (done) {
var encryptedLogin = 'd79d8482f708122288af7b259393a58fe05840f4555cc935cdd3f062b9aa75ed';
var site = 'lesspass.com';
var option = {
counter: 1,
length: 10,
};
LessPass._deriveEncryptedLogin(encryptedLogin, site, option).then(function (generatedPassword) {
assert.equal(10, generatedPassword.length);
done();
})
});
it('should return two different passwords if site different', function () {
const encryptedLogin = 'f4fd3885fb70085f2285c3382e2d9adb4c2553285fc45dd896791aa5e79070a9';
const site = 'google.com';
const site2 = 'facebook.com';
var p1 = LessPass._deriveEncryptedLogin(encryptedLogin, site);
var p2 = LessPass._deriveEncryptedLogin(encryptedLogin, site2);
Promise.all([p1, p2]).then(derivedEncryptedLogins => {
assert.notEqual(derivedEncryptedLogins[0], derivedEncryptedLogins[1])
});
});
it('should return two different passwords if counter different', function () {
const encryptedLogin = 'dfba06278c9aa24d992bc2d390a53efef482788859455875f72015335d085fcd';
const site = 'lesspass.com';
const option = {counter: 1};
const option2 = {counter: 2};
var p1 = LessPass._deriveEncryptedLogin(encryptedLogin, site, option);
var p2 = LessPass._deriveEncryptedLogin(encryptedLogin, site, option2);
Promise.all([p1, p2]).then(derivedEncryptedLogins => {
assert.notEqual(derivedEncryptedLogins[0], derivedEncryptedLogins[1])
});
});
it('should derive encrypted login with sha 256', function () {
const encryptedLogin = '9f505f3a95fe0485da3242cb81c9fe25c2f400d8399737655a8dad2b52778d88';
const site = 'lesspass.com';
LessPass._deriveEncryptedLogin(encryptedLogin, site).then(function (encryptedLogin) {
assert.equal('be00f942fc8a', encryptedLogin);
});
});
});
});

test('should return two different passwords if counter different', t => {
const encryptedLogin = 'dfba06278c9aa24d992bc2d390a53efef482788859455875f72015335d085fcd';
const site = 'lesspass.com';
const option = {counter: 1};
const option2 = {counter: 2};
var p1 = lesspass._deriveEncryptedLogin(encryptedLogin, site, option);
var p2 = lesspass._deriveEncryptedLogin(encryptedLogin, site, option2);
Promise.all([p1, p2]).then(derivedEncryptedLogins => {
t.not(derivedEncryptedLogins[0], derivedEncryptedLogins[1])
});
});

test('should derive encrypted login with sha 256', t => {
const encryptedLogin = '9f505f3a95fe0485da3242cb81c9fe25c2f400d8399737655a8dad2b52778d88';
const site = 'lesspass.com';
return lesspass._deriveEncryptedLogin(encryptedLogin, site).then(function (encryptedLogin) {
t.is('be00f942fc8a', encryptedLogin);
});
});

+ 60
- 52
tests/getPasswordTemplate.tests.js Целия файл

@@ -1,55 +1,63 @@
import test from 'ava';
import lesspass from '../index';
var assert = chai.assert;

test('should get default template', t => {
t.is('vcVCns', lesspass._getPasswordTemplate({
counter: 1,
length: 12,
lowercase: true,
uppercase: true,
numbers: true,
symbols: true
}));
describe('LessPass', function () {
describe('getPasswordTemplate', function () {
it('should get default template', function () {
assert.equal('vcVCns', LessPass._getPasswordTemplate({
counter: 1,
length: 12,
lowercase: true,
uppercase: true,
numbers: true,
symbols: true
}));
});
it('should get lowercase template', function () {
assert.equal('vc', LessPass._getPasswordTemplate({
lowercase: true,
uppercase: false,
numbers: false,
symbols: false
}));
});
it('should get uppercase template', function () {
assert.equal('VC', LessPass._getPasswordTemplate({
lowercase: false,
uppercase: true,
numbers: false,
symbols: false
}));
});
it('should get numbers template', function () {
assert.equal('n', LessPass._getPasswordTemplate({
lowercase: false,
uppercase: false,
numbers: true,
symbols: false
}));
});
it('should get symbols template', function () {
assert.equal('s', LessPass._getPasswordTemplate({
lowercase: false,
uppercase: false,
numbers: false,
symbols: true
}));
});
it('should concatenate template if two password settings', function () {
assert.equal('vcVC', LessPass._getPasswordTemplate({
lowercase: true,
uppercase: true,
numbers: false,
symbols: false
}));
assert.equal('vcns', LessPass._getPasswordTemplate({
lowercase: true,
uppercase: false,
numbers: true,
symbols: true
}));
});
});
});

test('should get template from password setting', t => {
t.is('vc', lesspass._getPasswordTemplate({
lowercase: true,
uppercase: false,
numbers: false,
symbols: false
}));
t.is('VC', lesspass._getPasswordTemplate({
lowercase: false,
uppercase: true,
numbers: false,
symbols: false
}));
t.is('n', lesspass._getPasswordTemplate({
lowercase: false,
uppercase: false,
numbers: true,
symbols: false
}));
t.is('s', lesspass._getPasswordTemplate({
lowercase: false,
uppercase: false,
numbers: false,
symbols: true
}));
});

test('should concatenate template if two password settings', t => {
t.is('vcVC', lesspass._getPasswordTemplate({
lowercase: true,
uppercase: true,
numbers: false,
symbols: false
}));
t.is('vcns', lesspass._getPasswordTemplate({
lowercase: true,
uppercase: false,
numbers: true,
symbols: true
}));
});

+ 3
- 0
tests/helper.js Целия файл

@@ -0,0 +1,3 @@
// globals
global.chai = require('chai');
global.LessPass = require('../index');

+ 33
- 35
tests/prettyPrint.js Целия файл

@@ -1,37 +1,35 @@
import test from 'ava';
import lesspass from '../index';
var assert = chai.assert;

test('should print different password if templates different', t => {
const encryptedLogin = '78ae5892055ab59fdd54489ae30928d322841a27590b65cf875fcfdd083f7c32';
t.not(lesspass._prettyPrint(encryptedLogin, 'cv'), lesspass._prettyPrint(encryptedLogin, 'vc'));
});

test('must return a string of the same length as the input', t => {
const hash = 'f5785e569ab5d38b02e2248c798ac17df90f57a85f34a9d5382408c2f0d9532d';
t.is(hash.length, lesspass._prettyPrint(hash, 'cv').length);
});

test('should return char inside a string based on modulo of the index', t => {
const template = 'cv';
t.is('c', lesspass._getCharType(template, 0));
t.is('v', lesspass._getCharType(template, 1));
t.is('c', lesspass._getCharType(template, 10));
});

test('should convert a string into an array of char code', t => {
const charCodes = lesspass._string2charCodes('ab40f6ee71');
t.is(97, charCodes[0]);
t.is(98, charCodes[1]);
t.is(10, charCodes.length);
});

test('should get password char based on its type and index', t => {
const typeVowel = 'V';
t.is('A', lesspass._getPasswordChar(typeVowel, 0));
});

test('should modulo if overflow', t => {
const typeVowel = 'V';
t.is('E', lesspass._getPasswordChar(typeVowel, 1));
t.is('E', lesspass._getPasswordChar(typeVowel, 7));
describe('LessPass', function () {
describe('prettyPrint', function () {
it('should print different password if templates different', function () {
var encryptedLogin = '78ae5892055ab59fdd54489ae30928d322841a27590b65cf875fcfdd083f7c32';
assert.notEqual(LessPass._prettyPrint(encryptedLogin, 'cv'), LessPass._prettyPrint(encryptedLogin, 'vc'));
});
it('must return a string of the same length as the input', function () {
var hash = 'f5785e569ab5d38b02e2248c798ac17df90f57a85f34a9d5382408c2f0d9532d';
assert.equal(hash.length, LessPass._prettyPrint(hash, 'cv').length);
});
it('should return char inside a string based on modulo of the index', function () {
var template = 'cv';
assert.equal('c', LessPass._getCharType(template, 0));
assert.equal('v', LessPass._getCharType(template, 1));
assert.equal('c', LessPass._getCharType(template, 10));
});
it('should convert a string into an array of char code', function () {
var charCodes = LessPass._string2charCodes('ab40f6ee71');
assert.equal(97, charCodes[0]);
assert.equal(98, charCodes[1]);
assert.equal(10, charCodes.length);
});
it('should get password char based on its type and index', function () {
var typeVowel = 'V';
assert.equal('A', LessPass._getPasswordChar(typeVowel, 0));
});
it('should modulo if overflow', function () {
var typeVowel = 'V';
assert.equal('E', LessPass._getPasswordChar(typeVowel, 1));
assert.equal('E', LessPass._getPasswordChar(typeVowel, 7));
});
});
});

Зареждане…
Отказ
Запис