1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-03-20 21:34:35 +00:00

test: update fixture

This commit is contained in:
Adrien Waksberg 2017-05-13 12:28:42 +02:00
parent f41a9e68d3
commit ca2e0d9e47
4 changed files with 114 additions and 124 deletions

View file

@ -1,28 +1,28 @@
add_new: add:
group: 'test_group' group: 'Bank'
host: 'test_host' host: 'example.com'
protocol: 'test_protocol' protocol: 'https'
user: 'test_user' user: 'admin'
password: 'test_password' password: 'VmfnCN6pPIqgRIbc'
port: '42' port: '8080'
comment: 'test_comment' comment: 'the website'
add_existing: import:
id: 'TEST-ID-XXXXX' id: 'TEST-ID-XXXXX'
group: 'test_group_existing' group: 'Cloud'
host: 'test_host_existing' host: 'gogole.com'
protocol: 'test_protocol_existing' protocol: 'https'
user: 'test_user_existing' user: 'gg-2304'
password: 'test_password_existing' password: 'TITl0kV9CDDa9sVK'
port: '44' port: '8081'
comment: 'test_comment_existing' comment: 'My little servers'
created: 1386752948 created: 1386752948
update: update:
group: 'test_group_update' group: 'Assurance'
host: 'test_host_update' host: 'example2.com'
protocol: 'test_protocol_update' protocol: 'ssh'
user: 'test_user_update' user: 'root'
password: 'test_password_update' password: 'kbSrbv4WlMaVxaZ7'
port: '43' port: '2222'
comment: 'test_comment_update' comment: 'i love ssh'

View file

@ -15,6 +15,7 @@ class TestConfig < Test::Unit::TestCase
I18n.locale = :en I18n.locale = :en
@password = 'password' @password = 'password'
@fixtures = YAML.load_file(fixture_file)
end end
def test_00_init_config def test_00_init_config
@ -27,65 +28,54 @@ class TestConfig < Test::Unit::TestCase
end end
def test_01_add_item def test_01_add_item
host = 'example.com' data = @fixtures['add']
port = 1234
proto = 'http'
user = 'root'
comment = 'the super website'
group = 'Bank'
output = %x( output = %x(
echo #{@password} | mpw add \ echo #{@password} | mpw add \
--host #{host} \ --host #{data['host']} \
--port #{port} \ --port #{data['port']} \
--protocol #{proto} \ --protocol #{data['protocol']} \
--user #{user} \ --user #{data['user']} \
--comment '#{comment}' \ --comment '#{data['comment']}' \
--group #{group} \ --group #{data['group']} \
--random) --random)
puts output puts output
assert_match(I18n.t('form.add_item.valid'), output) assert_match(I18n.t('form.add_item.valid'), output)
output = %x(echo #{@password} | mpw list) output = %x(echo #{@password} | mpw list)
puts output puts output
assert_match(%r{#{proto}://.+#{host}.+:#{port}}, output) assert_match(%r{#{data['protocol']}://.+#{data['host']}.+:#{data['port']}}, output)
assert_match(user, output) assert_match(data['user'], output)
assert_match(comment, output) assert_match(data['comment'], output)
assert_match(group, output) assert_match(data['group'], output)
end end
def test_02_update_item def test_02_update_item
host_old = 'example.com' data = @fixtures['update']
host_new = 'example2.com'
port_new = 4321
proto_new = 'ssh'
user_new = 'tortue'
comment_new = 'my account'
group_new = 'Assurance'
output = %x( output = %x(
echo #{@password} | mpw update \ echo #{@password} | mpw update \
-p #{host_old} \ -p #{@fixtures['add']['host']} \
--host #{host_new} \ --host #{data['host']} \
--port #{port_new} \ --port #{data['port']} \
--protocol #{proto_new} \ --protocol #{data['protocol']} \
--user #{user_new} \ --user #{data['user']} \
--comment '#{comment_new}' \ --comment '#{data['comment']}' \
--new-group #{group_new} --new-group #{data['group']}
) )
puts output puts output
assert_match(I18n.t('form.update_item.valid'), output) assert_match(I18n.t('form.update_item.valid'), output)
output = %x(echo #{@password} | mpw list) output = %x(echo #{@password} | mpw list)
puts output puts output
assert_match(%r{#{proto_new}://.+#{host_new}.+:#{port_new}}, output) assert_match(%r{#{data['protocol']}://.+#{data['host']}.+:#{data['port']}}, output)
assert_match(user_new, output) assert_match(data['user'], output)
assert_match(comment_new, output) assert_match(data['comment'], output)
assert_match(group_new, output) assert_match(data['group'], output)
end end
def test_03_delete_item def test_03_delete_item
host = 'example2.com' host = @fixtures['update']['host']
output = %x(echo "#{@password}\ny" | mpw delete -p #{host}) output = %x(echo "#{@password}\ny" | mpw delete -p #{host})
puts output puts output

View file

@ -20,14 +20,14 @@ class TestItem < Test::Unit::TestCase
assert_raise(RuntimeError) { MPW::Item.new } assert_raise(RuntimeError) { MPW::Item.new }
end end
def test_01_add_new def test_01_add
data = { data = {
group: @fixtures['add_new']['group'], group: @fixtures['add']['group'],
host: @fixtures['add_new']['host'], host: @fixtures['add']['host'],
protocol: @fixtures['add_new']['protocol'], protocol: @fixtures['add']['protocol'],
user: @fixtures['add_new']['user'], user: @fixtures['add']['user'],
port: @fixtures['add_new']['port'], port: @fixtures['add']['port'],
comment: @fixtures['add_new']['comment'] comment: @fixtures['add']['comment']
} }
item = MPW::Item.new(data) item = MPW::Item.new(data)
@ -35,24 +35,24 @@ class TestItem < Test::Unit::TestCase
assert(!item.nil?) assert(!item.nil?)
assert(!item.empty?) assert(!item.empty?)
assert_equal(@fixtures['add_new']['group'], item.group) assert_equal(@fixtures['add']['group'], item.group)
assert_equal(@fixtures['add_new']['host'], item.host) assert_equal(@fixtures['add']['host'], item.host)
assert_equal(@fixtures['add_new']['protocol'], item.protocol) assert_equal(@fixtures['add']['protocol'], item.protocol)
assert_equal(@fixtures['add_new']['user'], item.user) assert_equal(@fixtures['add']['user'], item.user)
assert_equal(@fixtures['add_new']['port'].to_i, item.port) assert_equal(@fixtures['add']['port'].to_i, item.port)
assert_equal(@fixtures['add_new']['comment'], item.comment) assert_equal(@fixtures['add']['comment'], item.comment)
end end
def test_02_add_existing def test_02_import
data = { data = {
id: @fixtures['add_existing']['id'], id: @fixtures['import']['id'],
group: @fixtures['add_existing']['group'], group: @fixtures['import']['group'],
host: @fixtures['add_existing']['host'], host: @fixtures['import']['host'],
protocol: @fixtures['add_existing']['protocol'], protocol: @fixtures['import']['protocol'],
user: @fixtures['add_existing']['user'], user: @fixtures['import']['user'],
port: @fixtures['add_existing']['port'], port: @fixtures['import']['port'],
comment: @fixtures['add_existing']['comment'], comment: @fixtures['import']['comment'],
created: @fixtures['add_existing']['created'] created: @fixtures['import']['created']
} }
item = MPW::Item.new(data) item = MPW::Item.new(data)
@ -60,24 +60,24 @@ class TestItem < Test::Unit::TestCase
assert(!item.nil?) assert(!item.nil?)
assert(!item.empty?) assert(!item.empty?)
assert_equal(@fixtures['add_existing']['id'], item.id) assert_equal(@fixtures['import']['id'], item.id)
assert_equal(@fixtures['add_existing']['group'], item.group) assert_equal(@fixtures['import']['group'], item.group)
assert_equal(@fixtures['add_existing']['host'], item.host) assert_equal(@fixtures['import']['host'], item.host)
assert_equal(@fixtures['add_existing']['protocol'], item.protocol) assert_equal(@fixtures['import']['protocol'], item.protocol)
assert_equal(@fixtures['add_existing']['user'], item.user) assert_equal(@fixtures['import']['user'], item.user)
assert_equal(@fixtures['add_existing']['port'].to_i, item.port) assert_equal(@fixtures['import']['port'].to_i, item.port)
assert_equal(@fixtures['add_existing']['comment'], item.comment) assert_equal(@fixtures['import']['comment'], item.comment)
assert_equal(@fixtures['add_existing']['created'], item.created) assert_equal(@fixtures['import']['created'], item.created)
end end
def test_03_update def test_03_update
data = { data = {
group: @fixtures['add_new']['group'], group: @fixtures['add']['group'],
host: @fixtures['add_new']['host'], host: @fixtures['add']['host'],
protocol: @fixtures['add_new']['protocol'], protocol: @fixtures['add']['protocol'],
user: @fixtures['add_new']['user'], user: @fixtures['add']['user'],
port: @fixtures['add_new']['port'], port: @fixtures['add']['port'],
comment: @fixtures['add_new']['comment'] comment: @fixtures['add']['comment']
} }
item = MPW::Item.new(data) item = MPW::Item.new(data)
@ -115,12 +115,12 @@ class TestItem < Test::Unit::TestCase
def test_05_update_one_element def test_05_update_one_element
data = { data = {
group: @fixtures['add_new']['group'], group: @fixtures['add']['group'],
host: @fixtures['add_new']['host'], host: @fixtures['add']['host'],
protocol: @fixtures['add_new']['protocol'], protocol: @fixtures['add']['protocol'],
user: @fixtures['add_new']['user'], user: @fixtures['add']['user'],
port: @fixtures['add_new']['port'], port: @fixtures['add']['port'],
comment: @fixtures['add_new']['comment'] comment: @fixtures['add']['comment']
} }
item = MPW::Item.new(data) item = MPW::Item.new(data)
@ -133,24 +133,24 @@ class TestItem < Test::Unit::TestCase
sleep(1) sleep(1)
assert(item.update(comment: @fixtures['update']['comment'])) assert(item.update(comment: @fixtures['update']['comment']))
assert_equal(@fixtures['add_new']['group'], item.group) assert_equal(@fixtures['add']['group'], item.group)
assert_equal(@fixtures['add_new']['host'], item.host) assert_equal(@fixtures['add']['host'], item.host)
assert_equal(@fixtures['add_new']['protocol'], item.protocol) assert_equal(@fixtures['add']['protocol'], item.protocol)
assert_equal(@fixtures['add_new']['user'], item.user) assert_equal(@fixtures['add']['user'], item.user)
assert_equal(@fixtures['add_new']['port'].to_i, item.port) assert_equal(@fixtures['add']['port'].to_i, item.port)
assert_equal(@fixtures['update']['comment'], item.comment) assert_equal(@fixtures['update']['comment'], item.comment)
assert_not_equal(last_edit, item.last_edit) assert_not_equal(last_edit, item.last_edit)
end end
def test_05_delete def test_05_delete
data = { data = {
group: @fixtures['add_new']['group'], group: @fixtures['add']['group'],
host: @fixtures['add_new']['host'], host: @fixtures['add']['host'],
protocol: @fixtures['add_new']['protocol'], protocol: @fixtures['add']['protocol'],
user: @fixtures['add_new']['user'], user: @fixtures['add']['user'],
port: @fixtures['add_new']['port'], port: @fixtures['add']['port'],
comment: @fixtures['add_new']['comment'] comment: @fixtures['add']['comment']
} }
item = MPW::Item.new(data) item = MPW::Item.new(data)

View file

@ -32,12 +32,12 @@ class TestMPW < Test::Unit::TestCase
def test_02_add_item def test_02_add_item
data = { data = {
group: @fixtures['add_new']['group'], group: @fixtures['add']['group'],
host: @fixtures['add_new']['host'], host: @fixtures['add']['host'],
protocol: @fixtures['add_new']['protocol'], protocol: @fixtures['add']['protocol'],
user: @fixtures['add_new']['user'], user: @fixtures['add']['user'],
port: @fixtures['add_new']['port'], port: @fixtures['add']['port'],
comment: @fixtures['add_new']['comment'] comment: @fixtures['add']['comment']
} }
item = MPW::Item.new(data) item = MPW::Item.new(data)
@ -47,12 +47,12 @@ class TestMPW < Test::Unit::TestCase
@mpw.read_data @mpw.read_data
@mpw.add(item) @mpw.add(item)
@mpw.set_password(item.id, @fixtures['add_new']['password']) @mpw.set_password(item.id, @fixtures['add']['password'])
assert_equal(1, @mpw.list.length) assert_equal(1, @mpw.list.length)
item = @mpw.list[0] item = @mpw.list[0]
@fixtures['add_new'].each do |k, v| @fixtures['add'].each do |k, v|
if k == 'password' if k == 'password'
assert_equal(v, @mpw.get_password(item.id)) assert_equal(v, @mpw.get_password(item.id))
else else
@ -68,7 +68,7 @@ class TestMPW < Test::Unit::TestCase
assert_equal(1, @mpw.list.length) assert_equal(1, @mpw.list.length)
item = @mpw.list[0] item = @mpw.list[0]
@fixtures['add_new'].each do |k, v| @fixtures['add'].each do |k, v|
if k == 'password' if k == 'password'
assert_equal(v, @mpw.get_password(item.id)) assert_equal(v, @mpw.get_password(item.id))
else else
@ -110,9 +110,9 @@ class TestMPW < Test::Unit::TestCase
end end
assert_equal(3, @mpw.list.length) assert_equal(3, @mpw.list.length)
assert_equal(1, @mpw.list(group: @fixtures['add_new']['group']).length) assert_equal(1, @mpw.list(group: @fixtures['add']['group']).length)
assert_equal(1, @mpw.list(pattern: 'existing').length) assert_equal(1, @mpw.list(pattern: 'gogole').length)
assert_equal(2, @mpw.list(pattern: 'host_[eu]').length) assert_equal(2, @mpw.list(pattern: 'example[2\.]').length)
end end
def test_06_add_gpg_key def test_06_add_gpg_key