Browse Source

add phantomjs to fix error on travis

pull/342/head
Guillaume Vincent 8 years ago
parent
commit
ce916e68b8
8 changed files with 5870 additions and 255 deletions
  1. +26
    -25
      index.js
  2. +5814
    -212
      lib/lesspass.js
  3. +3
    -0
      package.json
  4. +8
    -8
      tests/api.tests.js
  5. +3
    -3
      tests/deriveEncryptedLogin.tests.js
  6. +7
    -2
      tests/karma.config.js
  7. +6
    -2
      tests/karma.webcrypto.config.js
  8. +3
    -3
      tests/node.js

+ 26
- 25
index.js View File

@@ -1,23 +1,24 @@
var pbkdf2 = require('pbkdf2');
var createHmac = require('create-hmac');
var Promise = require("bluebird");

module.exports = {
encryptLogin: _encryptLogin,
renderPassword: _renderPassword,
createFingerprint: createFingerprint,
_deriveEncryptedLogin,
_getPasswordTemplate,
_prettyPrint,
_string2charCodes,
_getCharType,
_getPasswordChar,
_createHmac
_deriveEncryptedLogin: _deriveEncryptedLogin,
_getPasswordTemplate: _getPasswordTemplate,
_prettyPrint: _prettyPrint,
_string2charCodes: _string2charCodes,
_getCharType: _getCharType,
_getPasswordChar: _getPasswordChar,
_createHmac: _createHmac
};

function _encryptLogin(login, masterPassword, options) {
const _options = options !== undefined ? options : {};
const iterations = _options.iterations || 8192;
const keylen = _options.keylen || 32;
var _options = options !== undefined ? options : {};
var iterations = _options.iterations || 8192;
var keylen = _options.keylen || 32;

return new Promise(function (resolve, reject) {
if (!login || !masterPassword) {
@@ -35,7 +36,7 @@ function _encryptLogin(login, masterPassword, options) {

function _renderPassword(encryptedLogin, site, passwordOptions) {
return _deriveEncryptedLogin(encryptedLogin, site, passwordOptions).then(function (derivedEncryptedLogin) {
const template = passwordOptions.template || _getPasswordTemplate(passwordOptions);
var template = passwordOptions.template || _getPasswordTemplate(passwordOptions);
return _prettyPrint(derivedEncryptedLogin, template);
});
}
@@ -51,41 +52,41 @@ function _deriveEncryptedLogin(encryptedLogin, site, options) {
var length = _options.length || 12;
var counter = _options.counter || 1;

const salt = site + counter.toString();
var salt = site + counter.toString();
return _createHmac(encryptedLogin, salt).then(function (derivedHash) {
return derivedHash.substring(0, length);
});
}

function _getPasswordTemplate(passwordTypes) {
const templates = {
var templates = {
lowercase: 'vc',
uppercase: 'VC',
numbers: 'n',
symbols: 's',
};
let template = '';
for (let templateKey in templates) {
if (passwordTypes.hasOwnProperty(templateKey) && passwordTypes[templateKey]) {
template += templates[templateKey]
var returnedTemplate = '';
Object.keys(templates).forEach(function (template) {
if (passwordTypes.hasOwnProperty(template) && passwordTypes[template]) {
returnedTemplate += templates[template]
}
}
return template;
});
return returnedTemplate;
}

function _prettyPrint(hash, template) {
let password = '';
var password = '';

_string2charCodes(hash).forEach(function (charCode, index) {
const charType = _getCharType(template, index);
var charType = _getCharType(template, index);
password += _getPasswordChar(charType, charCode);
});
return password;
}

function _string2charCodes(text) {
const charCodes = [];
for (let i = 0; i < text.length; i++) {
var charCodes = [];
for (var i = 0; i < text.length; i++) {
charCodes.push(text.charCodeAt(i));
}
return charCodes;
@@ -96,7 +97,7 @@ function _getCharType(template, index) {
}

function _getPasswordChar(charType, index) {
const passwordsChars = {
var passwordsChars = {
V: 'AEIOUY',
C: 'BCDFGHJKLMNPQRSTVWXZ',
v: 'aeiouy',
@@ -107,7 +108,7 @@ function _getPasswordChar(charType, index) {
s: '@&%?,=[]_:-+*$#!\'^~;()/.',
x: 'AEIOUYaeiouyBCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz0123456789@&%?,=[]_:-+*$#!\'^~;()/.'
};
const passwordChar = passwordsChars[charType];
var passwordChar = passwordsChars[charType];
return passwordChar[index % passwordChar.length];
}



+ 5814
- 212
lib/lesspass.js
File diff suppressed because it is too large
View File


+ 3
- 0
package.json View File

@@ -23,6 +23,7 @@
"test:browser": "npm run build && karma start tests/karma.config.js"
},
"dependencies": {
"bluebird": "^3.4.6",
"create-hmac": "^1.1.4",
"pbkdf2": "^3.0.9",
"unibabel": "^2.1.3"
@@ -38,7 +39,9 @@
"karma-chrome-launcher": "^2.0.0",
"karma-firefox-launcher": "^1.0.0",
"karma-mocha": "^1.3.0",
"karma-phantomjs-launcher": "^1.0.2",
"mocha": "^3.1.2",
"phantomjs": "^2.1.7",
"rimraf": "^2.5.4"
}
}

+ 8
- 8
tests/api.tests.js View File

@@ -100,12 +100,12 @@ describe('LessPass', function () {
}
];

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

return Promise.all(promises).then(values => {
for (let i = 0; i < values.length; i++) {
return Promise.all(promises).then(function (values) {
for (var i = 0; i < values.length; i++) {
assert.equal(passwords[i].encryptedLogin, values[i]);
}
});
@@ -312,7 +312,7 @@ describe('LessPass', function () {
}
];

for (var entry of passwords) {
passwords.forEach(function (entry) {
var passwordOption = {
counter: entry.counter,
length: entry.length,
@@ -322,10 +322,10 @@ describe('LessPass', function () {
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++) {
return Promise.all(promises).then(function(values) {
for (var i = 0; i < values.length; i++) {
assert.equal(passwords[i].generatedPassword, values[i]);
}
});


+ 3
- 3
tests/deriveEncryptedLogin.tests.js View File

@@ -23,7 +23,7 @@ describe('LessPass', function () {
};
var p1 = LessPass._deriveEncryptedLogin(encryptedLogin, site);
var p2 = LessPass._deriveEncryptedLogin(encryptedLogin, site, option);
Promise.all([p1, p2]).then(generatedPasswords => {
Promise.all([p1, p2]).then(function(generatedPasswords) {
assert.equal(generatedPasswords[0], generatedPasswords[1])
});
});
@@ -45,7 +45,7 @@ describe('LessPass', function () {
const site2 = 'facebook.com';
var p1 = LessPass._deriveEncryptedLogin(encryptedLogin, site);
var p2 = LessPass._deriveEncryptedLogin(encryptedLogin, site2);
Promise.all([p1, p2]).then(derivedEncryptedLogins => {
Promise.all([p1, p2]).then(function(derivedEncryptedLogins) {
assert.notEqual(derivedEncryptedLogins[0], derivedEncryptedLogins[1])
});
});
@@ -56,7 +56,7 @@ describe('LessPass', function () {
const option2 = {counter: 2};
var p1 = LessPass._deriveEncryptedLogin(encryptedLogin, site, option);
var p2 = LessPass._deriveEncryptedLogin(encryptedLogin, site, option2);
Promise.all([p1, p2]).then(derivedEncryptedLogins => {
Promise.all([p1, p2]).then(function(derivedEncryptedLogins) {
assert.notEqual(derivedEncryptedLogins[0], derivedEncryptedLogins[1])
});
});


+ 7
- 2
tests/karma.config.js View File

@@ -1,8 +1,9 @@
module.exports = function (config) {
config.set({
var configuration = {
basePath: '..',
frameworks: ['mocha', 'chai'],
files: [
'node_modules/bluebird/js/browser/bluebird.core.min.js',
'lib/lesspass.js',
'tests/**/*.js'
],
@@ -20,5 +21,9 @@ module.exports = function (config) {
browsers: ['Chrome', 'Firefox'],
singleRun: true,
concurrency: Infinity
})
};
if (process.env.TRAVIS) {
configuration.browsers = ['PhantomJS'];
}
config.set(configuration)
};

+ 6
- 2
tests/karma.webcrypto.config.js View File

@@ -1,5 +1,5 @@
module.exports = function (config) {
config.set({
var configuration = {
basePath: '..',
frameworks: ['mocha', 'chai'],
files: [
@@ -22,5 +22,9 @@ module.exports = function (config) {
browsers: ['Chrome', 'Firefox'],
singleRun: true,
concurrency: Infinity
})
};
if (process.env.TRAVIS) {
configuration.browsers = ['PhantomJS'];
}
config.set(configuration)
};

+ 3
- 3
tests/node.js View File

@@ -15,12 +15,12 @@ var options = {
};

LessPass.encryptLogin(login, masterPassword)
.then(encryptedLogin => {
LessPass.renderPassword(encryptedLogin, site, options).then(generatedPassword => {
.then(function(encryptedLogin) {
LessPass.renderPassword(encryptedLogin, site, options).then(function(generatedPassword) {
assert.equal(generatedPassword, 'azYS7,olOL2]');
console.log('generated password ok');
});
})
.catch(e => {
.catch(function(e) {
console.log(e);
});

Loading…
Cancel
Save