1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-23 05:47:53 +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,28 +14,66 @@ class TestImport < Test::Unit::TestCase
@password = 'password' @password = 'password'
end end
def test_00_import def test_00_import_mpw_old
Dir['./test/files/import-*.txt'].each do |file| file = './test/files/import-mpw_old.txt'
format = File.basename(file, '.txt').partition('-').last format = 'mpw_old'
puts format output = %x(
mpw import \
--file #{file} \
--format #{format} \
--wallet #{format}
)
assert_match(I18n.t('form.import.valid'), output)
output = %x( output = %x(echo #{@password} | mpw list --group Bank --wallet #{format})
mpw import \ assert_match(%r{http://.*fric\.com.*12345.*Fric money money}, output)
--file #{file} \
--format #{format} \
--wallet #{format}
)
assert_match(I18n.t('form.import.valid'), output)
output = %x(echo #{@password} | mpw list --group Bank --wallet #{format}) output = %x(echo #{@password} | mpw list --group Cloud --wallet #{format})
assert_match(%r{http://.*fric\.com.*12345.*Fric money money}, output) assert_match(%r{ssh://.*fric\.com.*:4333.*username.*bastion}, output)
output = %x(echo #{@password} | mpw list --group Cloud --wallet #{format}) output = %x(echo #{@password} | mpw list --wallet #{format})
assert_match(%r{ssh://.*fric\.com.*:4333.*username.*bastion}, output) assert_match(/server\.com.*My little server/, output)
end
output = %x(echo #{@password} | mpw list --wallet #{format}) def test_01_import_gorilla
assert_match(/server\.com.*My little server/, output) file = './test/files/import-gorilla.txt'
end 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
end end