1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-10-27 02:33:19 +00:00

feat: add keepass

This commit is contained in:
Adrien Waksberg 2017-11-19 21:25:42 +01:00
parent 6a2d5da9fb
commit a11777cade
3 changed files with 109 additions and 18 deletions

50
lib/mpw/import/keepass.rb Normal file
View file

@ -0,0 +1,50 @@
# MPW is a software to crypt and manage your passwords
# Copyright (C) 2017 Adrien Waksberg <mpw@yae.im>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'csv'
module MPW
module Import
# Import an keepass2 export csv file
# @param file [String] the file path to import
def self.keepass(file)
data = {}
CSV.foreach(file, headers: true) do |row|
id = "#{row['Group']} #{row['Title']}"
comment =
if row['Title'] && row['Notes']
"#{row['Title']} #{row['Notes']}"
elsif row['Title']
row['Title']
elsif row['Notes']
row['Notes']
end
data[id] = {
'comment' => comment,
'group' => row['Group'],
'password' => row['Password'],
'url' => row['URL'],
'user' => row['Username']
}
end
data
end
end
end

View file

@ -0,0 +1,3 @@
"Group","Title","Username","Password","URL","Notes"
"Racine","Bank","123456","ywcExJW8qmBVTSyi","http://bank.com/login","My little bank"
"Racine/Cloud","GAFAM","wesh","superpassword","localhost.local",""

View file

@ -14,11 +14,9 @@ class TestImport < Test::Unit::TestCase
@password = 'password'
end
def test_00_import
Dir['./test/files/import-*.txt'].each do |file|
format = File.basename(file, '.txt').partition('-').last
puts format
def test_00_import_mpw_old
file = './test/files/import-mpw_old.txt'
format = 'mpw_old'
output = %x(
mpw import \
@ -37,5 +35,45 @@ class TestImport < Test::Unit::TestCase
output = %x(echo #{@password} | mpw list --wallet #{format})
assert_match(/server\.com.*My little server/, output)
end
def test_01_import_gorilla
file = './test/files/import-gorilla.txt'
format = 'gorilla'
output = %x(
mpw import \
--file #{file} \
--format #{format} \
--wallet #{format}
)
assert_match(I18n.t('form.import.valid'), output)
output = %x(echo #{@password} | mpw list --group Bank --wallet #{format})
assert_match(%r{http://.*fric\.com.*12345.*Fric money money}, output)
output = %x(echo #{@password} | mpw list --group Cloud --wallet #{format})
assert_match(%r{ssh://.*fric\.com.*:4333.*username.*bastion}, output)
output = %x(echo #{@password} | mpw list --wallet #{format})
assert_match(/server\.com.*My little server/, output)
end
def test_02_import_keepass
file = './test/files/import-keepass.txt'
format = 'keepass'
output = %x(
mpw import \
--file #{file} \
--format #{format} \
--wallet #{format}
)
assert_match(I18n.t('form.import.valid'), output)
output = %x(echo #{@password} | mpw list --group 'Racine/Cloud' --wallet #{format})
assert_match(/localhost\.local.*wesh.*GAFAM/, output)
output = %x(echo #{@password} | mpw list --wallet #{format})
assert_match(%r{http://.*bank\.com.*123456.*Bank My little bank}, output)
end
end