feat: add test for import
This commit is contained in:
parent
2a647afb10
commit
42629c61b3
4 changed files with 58 additions and 5 deletions
|
@ -19,3 +19,4 @@ script:
|
||||||
- ruby ./test/test_translate.rb
|
- ruby ./test/test_translate.rb
|
||||||
- ruby ./test/init.rb
|
- ruby ./test/init.rb
|
||||||
- ruby ./test/test_cli.rb
|
- ruby ./test/test_cli.rb
|
||||||
|
- ruby ./test/test_import.rb
|
||||||
|
|
4
test/files/import-gorilla.txt
Normal file
4
test/files/import-gorilla.txt
Normal 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
|
|
@ -185,15 +185,16 @@ class TestConfig < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_08_setup_config
|
def test_08_setup_config
|
||||||
gpg_key = 'user@example2.com'
|
gpg_key = 'test2@example.com'
|
||||||
gpg_exe = '/usr/bin/gpg2'
|
gpg_exe = '/usr/bin/gpg2'
|
||||||
wallet_dir = '/tmp/mpw'
|
wallet_dir = '/tmp'
|
||||||
length = 24
|
length = 24
|
||||||
wallet = 'work'
|
wallet = 'work'
|
||||||
|
|
||||||
output = %x(
|
output = %x(
|
||||||
mpw config \
|
mpw config \
|
||||||
--gpg-exe #{gpg_exe} \
|
--gpg-exe #{gpg_exe} \
|
||||||
|
--key #{gpg_key} \
|
||||||
--enable-pinmode \
|
--enable-pinmode \
|
||||||
--disable-alpha \
|
--disable-alpha \
|
||||||
--disable-special-chars \
|
--disable-special-chars \
|
||||||
|
@ -207,7 +208,7 @@ class TestConfig < Test::Unit::TestCase
|
||||||
|
|
||||||
output = %x(mpw config)
|
output = %x(mpw config)
|
||||||
puts output
|
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(/gpg_exe.+\| #{gpg_exe}/, output)
|
||||||
assert_match(/pinmode.+\| true/, output)
|
assert_match(/pinmode.+\| true/, output)
|
||||||
assert_match(/default_wallet.+\| #{wallet}/, output)
|
assert_match(/default_wallet.+\| #{wallet}/, output)
|
||||||
|
@ -219,7 +220,8 @@ class TestConfig < Test::Unit::TestCase
|
||||||
|
|
||||||
output = %x(
|
output = %x(
|
||||||
mpw config \
|
mpw config \
|
||||||
--key #{gpg_key} \
|
--gpg-exe '' \
|
||||||
|
--key #{@gpg_key} \
|
||||||
--alpha \
|
--alpha \
|
||||||
--special-chars \
|
--special-chars \
|
||||||
--numeric \
|
--numeric \
|
||||||
|
@ -230,7 +232,7 @@ class TestConfig < Test::Unit::TestCase
|
||||||
|
|
||||||
output = %x(mpw config)
|
output = %x(mpw config)
|
||||||
puts output
|
puts output
|
||||||
assert_match(/gpg_key.+\| #{gpg_key}/, output)
|
assert_match(/gpg_key.+\| #{@gpg_key}/, output)
|
||||||
assert_match(/pinmode.+\| false/, output)
|
assert_match(/pinmode.+\| false/, output)
|
||||||
%w[numeric alpha special].each do |k|
|
%w[numeric alpha special].each do |k|
|
||||||
assert_match(/password_#{k}.+\| true/, output)
|
assert_match(/password_#{k}.+\| true/, output)
|
||||||
|
|
46
test/test_import.rb
Normal file
46
test/test_import.rb
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue