mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-20 01:50:04 +00:00
test: update fixture
This commit is contained in:
parent
f41a9e68d3
commit
ca2e0d9e47
4 changed files with 114 additions and 124 deletions
|
@ -1,28 +1,28 @@
|
|||
add_new:
|
||||
group: 'test_group'
|
||||
host: 'test_host'
|
||||
protocol: 'test_protocol'
|
||||
user: 'test_user'
|
||||
password: 'test_password'
|
||||
port: '42'
|
||||
comment: 'test_comment'
|
||||
add:
|
||||
group: 'Bank'
|
||||
host: 'example.com'
|
||||
protocol: 'https'
|
||||
user: 'admin'
|
||||
password: 'VmfnCN6pPIqgRIbc'
|
||||
port: '8080'
|
||||
comment: 'the website'
|
||||
|
||||
add_existing:
|
||||
import:
|
||||
id: 'TEST-ID-XXXXX'
|
||||
group: 'test_group_existing'
|
||||
host: 'test_host_existing'
|
||||
protocol: 'test_protocol_existing'
|
||||
user: 'test_user_existing'
|
||||
password: 'test_password_existing'
|
||||
port: '44'
|
||||
comment: 'test_comment_existing'
|
||||
group: 'Cloud'
|
||||
host: 'gogole.com'
|
||||
protocol: 'https'
|
||||
user: 'gg-2304'
|
||||
password: 'TITl0kV9CDDa9sVK'
|
||||
port: '8081'
|
||||
comment: 'My little servers'
|
||||
created: 1386752948
|
||||
|
||||
update:
|
||||
group: 'test_group_update'
|
||||
host: 'test_host_update'
|
||||
protocol: 'test_protocol_update'
|
||||
user: 'test_user_update'
|
||||
password: 'test_password_update'
|
||||
port: '43'
|
||||
comment: 'test_comment_update'
|
||||
group: 'Assurance'
|
||||
host: 'example2.com'
|
||||
protocol: 'ssh'
|
||||
user: 'root'
|
||||
password: 'kbSrbv4WlMaVxaZ7'
|
||||
port: '2222'
|
||||
comment: 'i love ssh'
|
||||
|
|
|
@ -15,6 +15,7 @@ class TestConfig < Test::Unit::TestCase
|
|||
I18n.locale = :en
|
||||
|
||||
@password = 'password'
|
||||
@fixtures = YAML.load_file(fixture_file)
|
||||
end
|
||||
|
||||
def test_00_init_config
|
||||
|
@ -27,65 +28,54 @@ class TestConfig < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_01_add_item
|
||||
host = 'example.com'
|
||||
port = 1234
|
||||
proto = 'http'
|
||||
user = 'root'
|
||||
comment = 'the super website'
|
||||
group = 'Bank'
|
||||
data = @fixtures['add']
|
||||
|
||||
output = %x(
|
||||
echo #{@password} | mpw add \
|
||||
--host #{host} \
|
||||
--port #{port} \
|
||||
--protocol #{proto} \
|
||||
--user #{user} \
|
||||
--comment '#{comment}' \
|
||||
--group #{group} \
|
||||
--host #{data['host']} \
|
||||
--port #{data['port']} \
|
||||
--protocol #{data['protocol']} \
|
||||
--user #{data['user']} \
|
||||
--comment '#{data['comment']}' \
|
||||
--group #{data['group']} \
|
||||
--random)
|
||||
puts output
|
||||
assert_match(I18n.t('form.add_item.valid'), output)
|
||||
|
||||
output = %x(echo #{@password} | mpw list)
|
||||
puts output
|
||||
assert_match(%r{#{proto}://.+#{host}.+:#{port}}, output)
|
||||
assert_match(user, output)
|
||||
assert_match(comment, output)
|
||||
assert_match(group, output)
|
||||
assert_match(%r{#{data['protocol']}://.+#{data['host']}.+:#{data['port']}}, output)
|
||||
assert_match(data['user'], output)
|
||||
assert_match(data['comment'], output)
|
||||
assert_match(data['group'], output)
|
||||
end
|
||||
|
||||
def test_02_update_item
|
||||
host_old = 'example.com'
|
||||
host_new = 'example2.com'
|
||||
port_new = 4321
|
||||
proto_new = 'ssh'
|
||||
user_new = 'tortue'
|
||||
comment_new = 'my account'
|
||||
group_new = 'Assurance'
|
||||
data = @fixtures['update']
|
||||
|
||||
output = %x(
|
||||
echo #{@password} | mpw update \
|
||||
-p #{host_old} \
|
||||
--host #{host_new} \
|
||||
--port #{port_new} \
|
||||
--protocol #{proto_new} \
|
||||
--user #{user_new} \
|
||||
--comment '#{comment_new}' \
|
||||
--new-group #{group_new}
|
||||
-p #{@fixtures['add']['host']} \
|
||||
--host #{data['host']} \
|
||||
--port #{data['port']} \
|
||||
--protocol #{data['protocol']} \
|
||||
--user #{data['user']} \
|
||||
--comment '#{data['comment']}' \
|
||||
--new-group #{data['group']}
|
||||
)
|
||||
puts output
|
||||
assert_match(I18n.t('form.update_item.valid'), output)
|
||||
|
||||
output = %x(echo #{@password} | mpw list)
|
||||
puts output
|
||||
assert_match(%r{#{proto_new}://.+#{host_new}.+:#{port_new}}, output)
|
||||
assert_match(user_new, output)
|
||||
assert_match(comment_new, output)
|
||||
assert_match(group_new, output)
|
||||
assert_match(%r{#{data['protocol']}://.+#{data['host']}.+:#{data['port']}}, output)
|
||||
assert_match(data['user'], output)
|
||||
assert_match(data['comment'], output)
|
||||
assert_match(data['group'], output)
|
||||
end
|
||||
|
||||
def test_03_delete_item
|
||||
host = 'example2.com'
|
||||
host = @fixtures['update']['host']
|
||||
|
||||
output = %x(echo "#{@password}\ny" | mpw delete -p #{host})
|
||||
puts output
|
||||
|
|
|
@ -20,14 +20,14 @@ class TestItem < Test::Unit::TestCase
|
|||
assert_raise(RuntimeError) { MPW::Item.new }
|
||||
end
|
||||
|
||||
def test_01_add_new
|
||||
def test_01_add
|
||||
data = {
|
||||
group: @fixtures['add_new']['group'],
|
||||
host: @fixtures['add_new']['host'],
|
||||
protocol: @fixtures['add_new']['protocol'],
|
||||
user: @fixtures['add_new']['user'],
|
||||
port: @fixtures['add_new']['port'],
|
||||
comment: @fixtures['add_new']['comment']
|
||||
group: @fixtures['add']['group'],
|
||||
host: @fixtures['add']['host'],
|
||||
protocol: @fixtures['add']['protocol'],
|
||||
user: @fixtures['add']['user'],
|
||||
port: @fixtures['add']['port'],
|
||||
comment: @fixtures['add']['comment']
|
||||
}
|
||||
|
||||
item = MPW::Item.new(data)
|
||||
|
@ -35,24 +35,24 @@ class TestItem < Test::Unit::TestCase
|
|||
assert(!item.nil?)
|
||||
assert(!item.empty?)
|
||||
|
||||
assert_equal(@fixtures['add_new']['group'], item.group)
|
||||
assert_equal(@fixtures['add_new']['host'], item.host)
|
||||
assert_equal(@fixtures['add_new']['protocol'], item.protocol)
|
||||
assert_equal(@fixtures['add_new']['user'], item.user)
|
||||
assert_equal(@fixtures['add_new']['port'].to_i, item.port)
|
||||
assert_equal(@fixtures['add_new']['comment'], item.comment)
|
||||
assert_equal(@fixtures['add']['group'], item.group)
|
||||
assert_equal(@fixtures['add']['host'], item.host)
|
||||
assert_equal(@fixtures['add']['protocol'], item.protocol)
|
||||
assert_equal(@fixtures['add']['user'], item.user)
|
||||
assert_equal(@fixtures['add']['port'].to_i, item.port)
|
||||
assert_equal(@fixtures['add']['comment'], item.comment)
|
||||
end
|
||||
|
||||
def test_02_add_existing
|
||||
def test_02_import
|
||||
data = {
|
||||
id: @fixtures['add_existing']['id'],
|
||||
group: @fixtures['add_existing']['group'],
|
||||
host: @fixtures['add_existing']['host'],
|
||||
protocol: @fixtures['add_existing']['protocol'],
|
||||
user: @fixtures['add_existing']['user'],
|
||||
port: @fixtures['add_existing']['port'],
|
||||
comment: @fixtures['add_existing']['comment'],
|
||||
created: @fixtures['add_existing']['created']
|
||||
id: @fixtures['import']['id'],
|
||||
group: @fixtures['import']['group'],
|
||||
host: @fixtures['import']['host'],
|
||||
protocol: @fixtures['import']['protocol'],
|
||||
user: @fixtures['import']['user'],
|
||||
port: @fixtures['import']['port'],
|
||||
comment: @fixtures['import']['comment'],
|
||||
created: @fixtures['import']['created']
|
||||
}
|
||||
|
||||
item = MPW::Item.new(data)
|
||||
|
@ -60,24 +60,24 @@ class TestItem < Test::Unit::TestCase
|
|||
assert(!item.nil?)
|
||||
assert(!item.empty?)
|
||||
|
||||
assert_equal(@fixtures['add_existing']['id'], item.id)
|
||||
assert_equal(@fixtures['add_existing']['group'], item.group)
|
||||
assert_equal(@fixtures['add_existing']['host'], item.host)
|
||||
assert_equal(@fixtures['add_existing']['protocol'], item.protocol)
|
||||
assert_equal(@fixtures['add_existing']['user'], item.user)
|
||||
assert_equal(@fixtures['add_existing']['port'].to_i, item.port)
|
||||
assert_equal(@fixtures['add_existing']['comment'], item.comment)
|
||||
assert_equal(@fixtures['add_existing']['created'], item.created)
|
||||
assert_equal(@fixtures['import']['id'], item.id)
|
||||
assert_equal(@fixtures['import']['group'], item.group)
|
||||
assert_equal(@fixtures['import']['host'], item.host)
|
||||
assert_equal(@fixtures['import']['protocol'], item.protocol)
|
||||
assert_equal(@fixtures['import']['user'], item.user)
|
||||
assert_equal(@fixtures['import']['port'].to_i, item.port)
|
||||
assert_equal(@fixtures['import']['comment'], item.comment)
|
||||
assert_equal(@fixtures['import']['created'], item.created)
|
||||
end
|
||||
|
||||
def test_03_update
|
||||
data = {
|
||||
group: @fixtures['add_new']['group'],
|
||||
host: @fixtures['add_new']['host'],
|
||||
protocol: @fixtures['add_new']['protocol'],
|
||||
user: @fixtures['add_new']['user'],
|
||||
port: @fixtures['add_new']['port'],
|
||||
comment: @fixtures['add_new']['comment']
|
||||
group: @fixtures['add']['group'],
|
||||
host: @fixtures['add']['host'],
|
||||
protocol: @fixtures['add']['protocol'],
|
||||
user: @fixtures['add']['user'],
|
||||
port: @fixtures['add']['port'],
|
||||
comment: @fixtures['add']['comment']
|
||||
}
|
||||
|
||||
item = MPW::Item.new(data)
|
||||
|
@ -115,12 +115,12 @@ class TestItem < Test::Unit::TestCase
|
|||
|
||||
def test_05_update_one_element
|
||||
data = {
|
||||
group: @fixtures['add_new']['group'],
|
||||
host: @fixtures['add_new']['host'],
|
||||
protocol: @fixtures['add_new']['protocol'],
|
||||
user: @fixtures['add_new']['user'],
|
||||
port: @fixtures['add_new']['port'],
|
||||
comment: @fixtures['add_new']['comment']
|
||||
group: @fixtures['add']['group'],
|
||||
host: @fixtures['add']['host'],
|
||||
protocol: @fixtures['add']['protocol'],
|
||||
user: @fixtures['add']['user'],
|
||||
port: @fixtures['add']['port'],
|
||||
comment: @fixtures['add']['comment']
|
||||
}
|
||||
|
||||
item = MPW::Item.new(data)
|
||||
|
@ -133,24 +133,24 @@ class TestItem < Test::Unit::TestCase
|
|||
sleep(1)
|
||||
assert(item.update(comment: @fixtures['update']['comment']))
|
||||
|
||||
assert_equal(@fixtures['add_new']['group'], item.group)
|
||||
assert_equal(@fixtures['add_new']['host'], item.host)
|
||||
assert_equal(@fixtures['add_new']['protocol'], item.protocol)
|
||||
assert_equal(@fixtures['add_new']['user'], item.user)
|
||||
assert_equal(@fixtures['add_new']['port'].to_i, item.port)
|
||||
assert_equal(@fixtures['update']['comment'], item.comment)
|
||||
assert_equal(@fixtures['add']['group'], item.group)
|
||||
assert_equal(@fixtures['add']['host'], item.host)
|
||||
assert_equal(@fixtures['add']['protocol'], item.protocol)
|
||||
assert_equal(@fixtures['add']['user'], item.user)
|
||||
assert_equal(@fixtures['add']['port'].to_i, item.port)
|
||||
assert_equal(@fixtures['update']['comment'], item.comment)
|
||||
|
||||
assert_not_equal(last_edit, item.last_edit)
|
||||
end
|
||||
|
||||
def test_05_delete
|
||||
data = {
|
||||
group: @fixtures['add_new']['group'],
|
||||
host: @fixtures['add_new']['host'],
|
||||
protocol: @fixtures['add_new']['protocol'],
|
||||
user: @fixtures['add_new']['user'],
|
||||
port: @fixtures['add_new']['port'],
|
||||
comment: @fixtures['add_new']['comment']
|
||||
group: @fixtures['add']['group'],
|
||||
host: @fixtures['add']['host'],
|
||||
protocol: @fixtures['add']['protocol'],
|
||||
user: @fixtures['add']['user'],
|
||||
port: @fixtures['add']['port'],
|
||||
comment: @fixtures['add']['comment']
|
||||
}
|
||||
|
||||
item = MPW::Item.new(data)
|
||||
|
|
|
@ -32,12 +32,12 @@ class TestMPW < Test::Unit::TestCase
|
|||
|
||||
def test_02_add_item
|
||||
data = {
|
||||
group: @fixtures['add_new']['group'],
|
||||
host: @fixtures['add_new']['host'],
|
||||
protocol: @fixtures['add_new']['protocol'],
|
||||
user: @fixtures['add_new']['user'],
|
||||
port: @fixtures['add_new']['port'],
|
||||
comment: @fixtures['add_new']['comment']
|
||||
group: @fixtures['add']['group'],
|
||||
host: @fixtures['add']['host'],
|
||||
protocol: @fixtures['add']['protocol'],
|
||||
user: @fixtures['add']['user'],
|
||||
port: @fixtures['add']['port'],
|
||||
comment: @fixtures['add']['comment']
|
||||
}
|
||||
|
||||
item = MPW::Item.new(data)
|
||||
|
@ -47,12 +47,12 @@ class TestMPW < Test::Unit::TestCase
|
|||
|
||||
@mpw.read_data
|
||||
@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)
|
||||
|
||||
item = @mpw.list[0]
|
||||
@fixtures['add_new'].each do |k, v|
|
||||
@fixtures['add'].each do |k, v|
|
||||
if k == 'password'
|
||||
assert_equal(v, @mpw.get_password(item.id))
|
||||
else
|
||||
|
@ -68,7 +68,7 @@ class TestMPW < Test::Unit::TestCase
|
|||
assert_equal(1, @mpw.list.length)
|
||||
|
||||
item = @mpw.list[0]
|
||||
@fixtures['add_new'].each do |k, v|
|
||||
@fixtures['add'].each do |k, v|
|
||||
if k == 'password'
|
||||
assert_equal(v, @mpw.get_password(item.id))
|
||||
else
|
||||
|
@ -110,9 +110,9 @@ class TestMPW < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
assert_equal(3, @mpw.list.length)
|
||||
assert_equal(1, @mpw.list(group: @fixtures['add_new']['group']).length)
|
||||
assert_equal(1, @mpw.list(pattern: 'existing').length)
|
||||
assert_equal(2, @mpw.list(pattern: 'host_[eu]').length)
|
||||
assert_equal(1, @mpw.list(group: @fixtures['add']['group']).length)
|
||||
assert_equal(1, @mpw.list(pattern: 'gogole').length)
|
||||
assert_equal(2, @mpw.list(pattern: 'example[2\.]').length)
|
||||
end
|
||||
|
||||
def test_06_add_gpg_key
|
||||
|
|
Loading…
Add table
Reference in a new issue