1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-03-19 12:59:30 +00:00

feat: add test for import

This commit is contained in:
Adrien Waksberg 2017-09-03 15:10:01 +02:00
parent 2a647afb10
commit 42629c61b3
4 changed files with 58 additions and 5 deletions

View file

@ -19,3 +19,4 @@ script:
- ruby ./test/test_translate.rb
- ruby ./test/init.rb
- ruby ./test/test_cli.rb
- ruby ./test/test_import.rb

View file

@ -0,0 +1,4 @@
uuid,group,title,url,user,password,notes
49627979-e393-48c4-49ca-1cf66603238e,Bank,Fric,http://fric.com,12345,secret,money money
49627979-e393-48c4-49ca-1cf66603238f,,My little server,server.com,secret2,
49627979-e393-48c4-49ca-1cf66603238g,Cloud,,ssh://fric.com:4333,username,secret,bastion

View file

@ -185,15 +185,16 @@ class TestConfig < Test::Unit::TestCase
end
def test_08_setup_config
gpg_key = 'user@example2.com'
gpg_key = 'test2@example.com'
gpg_exe = '/usr/bin/gpg2'
wallet_dir = '/tmp/mpw'
wallet_dir = '/tmp'
length = 24
wallet = 'work'
output = %x(
mpw config \
--gpg-exe #{gpg_exe} \
--key #{gpg_key} \
--enable-pinmode \
--disable-alpha \
--disable-special-chars \
@ -207,7 +208,7 @@ class TestConfig < Test::Unit::TestCase
output = %x(mpw config)
puts output
assert_match(/gpg_key.+\| #{@gpg_key}/, output)
assert_match(/gpg_key.+\| #{gpg_key}/, output)
assert_match(/gpg_exe.+\| #{gpg_exe}/, output)
assert_match(/pinmode.+\| true/, output)
assert_match(/default_wallet.+\| #{wallet}/, output)
@ -219,7 +220,8 @@ class TestConfig < Test::Unit::TestCase
output = %x(
mpw config \
--key #{gpg_key} \
--gpg-exe '' \
--key #{@gpg_key} \
--alpha \
--special-chars \
--numeric \
@ -230,7 +232,7 @@ class TestConfig < Test::Unit::TestCase
output = %x(mpw config)
puts output
assert_match(/gpg_key.+\| #{gpg_key}/, output)
assert_match(/gpg_key.+\| #{@gpg_key}/, output)
assert_match(/pinmode.+\| false/, output)
%w[numeric alpha special].each do |k|
assert_match(/password_#{k}.+\| true/, output)

46
test/test_import.rb Normal file
View file

@ -0,0 +1,46 @@
#!/usr/bin/ruby
require 'i18n'
require 'test/unit'
class TestImport < Test::Unit::TestCase
def setup
if defined?(I18n.enforce_available_locales)
I18n.enforce_available_locales = true
end
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
I18n.load_path = ["#{File.expand_path('../../i18n', __FILE__)}/en.yml"]
I18n.locale = :en
@password = 'password'
end
def test_00_import
Dir['./test/files/import-*.txt'].each do |file|
format = File.basename(file, '.txt').partition('-').last
puts format
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})
puts output
assert_match(%r{http://.*fric\.com.*12345.*Fric money money}, output)
output = %x(echo #{@password} | mpw list --group Cloud --wallet #{format})
puts output
assert_match(%r{ssh://.*fric\.com.*:4333.*username.*bastion}, output)
output = %x(echo #{@password} | mpw list --wallet #{format})
puts output
assert_match(/server\.com.*My little server/, output)
end
end
end