From 734733924e44600b9b5460937996a48f963962c0 Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Sat, 20 May 2017 08:40:16 +0200 Subject: [PATCH] add transformProfilesFromV1ToV2 and first tests --- migration.js | 26 ++++++++++++++++++++++++++ package.json | 22 ++++++++++++++++++++++ test.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 migration.js create mode 100644 package.json create mode 100644 test.js diff --git a/migration.js b/migration.js new file mode 100644 index 0000000..eec00da --- /dev/null +++ b/migration.js @@ -0,0 +1,26 @@ +module.exports = { + transformProfilesFromV1ToV2: function(profiles) { + const newProfiles = []; + profiles.forEach(profile => { + const newProfile = { + "site": profile.site, + "login": profile.login, + "lowercase": profile.lowercase, + "uppercase": profile.uppercase, + "number": profile.number, + "symbol": profile.symbol, + "counter": profile.counter, + "length": profile.length, + "version": profile.version, + }; + if (profile.version === 1) { + newProfile.version = 2; + if (profile.length === 12) { + newProfile.length = 16; + } + } + newProfiles.push(newProfile) + }); + return newProfiles + } +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..6058b9c --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "lesspass-move", + "version": "0.1.0", + "description": "A tool to change your LessPass passwords", + "main": "index.js", + "scripts": { + "test": "ava" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/lesspass/move.git" + }, + "author": "Guillaume Vincent ", + "license": "GPL-3.0", + "bugs": { + "url": "https://github.com/lesspass/move/issues" + }, + "homepage": "https://github.com/lesspass/move#readme", + "devDependencies": { + "ava": "^0.19.1" + } +} diff --git a/test.js b/test.js new file mode 100644 index 0000000..d8d96aa --- /dev/null +++ b/test.js @@ -0,0 +1,54 @@ +import test from 'ava'; +import migration from './migration' + +test('transformProfilesFromV1ToV2', t => { + var profiles = [ + { + "site": "example.org", + "login": "test@example.org", + "lowercase": true, + "uppercase": true, + "number": true, + "symbol": true, + "counter": 1, + "length": 12, + "version": 1 + }, + { + "site": "bank.example.org", + "login": "test@example.org", + "lowercase": false, + "uppercase": false, + "number": true, + "symbol": false, + "counter": 2, + "length": 6, + "version": 1 + } + ]; + var expectedProfiles = [ + { + "site": "example.org", + "login": "test@example.org", + "lowercase": true, + "uppercase": true, + "number": true, + "symbol": true, + "counter": 1, + "length": 16, + "version": 2 + }, + { + "site": "bank.example.org", + "login": "test@example.org", + "lowercase": false, + "uppercase": false, + "number": true, + "symbol": false, + "counter": 2, + "length": 6, + "version": 2 + } + ]; + t.deepEqual(migration.transformProfilesFromV1ToV2(profiles), expectedProfiles); +});