1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2025-02-20 01:50:04 +00:00

add test with travis

This commit is contained in:
Adrien Waksberg 2016-11-10 23:57:16 +01:00
parent 0c93fd9eea
commit 59e850cfeb
11 changed files with 192 additions and 269 deletions

13
.travis.yml Normal file
View file

@ -0,0 +1,13 @@
language: ruby
rvm:
- 2.3.1
- 2.2.5
- 2.1.10
install:
- bundle install
- gem install 'test-unit'
- echo 9999 > VERSION
- gem build mpw.gemspec
- gem install mpw-9999.gem
script:
- ruby ./test/tests.rb

View file

@ -1,7 +1,8 @@
MPW: Manage your passwords!
*******************************************************
|Build Status| |License|
mpw is a little software which stores your passwords in `GnuPG <http://www.gnupg.org/>` encrypted files.
mpw is a little software which stores your passwords in `GnuPG <http://www.gnupg.org/>`_ encrypted files.
Features
========
@ -48,6 +49,8 @@ Output::
Licence |License|
=================
Full license here: `LICENSE <https://github.com/nishiki/manage-password/blob/master/LICENSE>`
Full license here: `LICENSE <https://github.com/nishiki/manage-password/blob/master/LICENSE>`_
.. |License| image:: https://img.shields.io/badge/license-GPL--2.0-blue.svg
.. |Build Status| image:: https://travis-ci.org/nishiki/manage-password.svg?branch=master
:target: https://travis-ci.org/nishiki/manage-password

View file

@ -1,5 +1,4 @@
add_new:
name: 'test_name'
group: 'test_group'
host: 'test_host'
protocol: 'test_protocol'
@ -10,7 +9,6 @@ add_new:
add_existing:
id: 'TEST-ID-XXXXX'
name: 'test_name_existing'
group: 'test_group_existing'
host: 'test_host_existing'
protocol: 'test_protocol_existing'
@ -21,7 +19,6 @@ add_existing:
created: 1386752948
update:
name: 'test_name_update'
group: 'test_group_update'
host: 'test_host_update'
protocol: 'test_protocol_update'
@ -29,4 +26,3 @@ update:
password: 'test_password_update'
port: '43'
comment: 'test_comment_update'

View file

@ -1,3 +0,0 @@
name,group,protocol,host,user,password,port,comment
test_name,test_group,test_protocol,test_host,test_user,test_password,42,test_comment
test_name_update,test_group_update,test_protocol_update,test_host_update,test_user_update,test_password_update,43,test_comment_update
1 name group protocol host user password port comment
2 test_name test_group test_protocol test_host test_user test_password 42 test_comment
3 test_name_update test_group_update test_protocol_update test_host_update test_user_update test_password_update 43 test_comment_update

View file

@ -1,23 +0,0 @@
---
XWas7vpy0HerhOYd:
id: XWas7vpy0HerhOYd
name: test_name
group: test_group
host: test_host
protocol: test_protocol
user: test_user
password: test_password
port: 42
comment: test_comment
date: 1419858983
D7URyJENLa91jt0b:
id: D7URyJENLa91jt0b
name: test_name_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
date: 1419858983

1
test/test.sh Normal file
View file

@ -0,0 +1 @@
echo "test\ntest\n" | ruby ./bin/mpw config --init test@test.com

11
test/test2.rb Normal file
View file

@ -0,0 +1,11 @@
require 'open3'
Open3.popen3("./bin/mpw config --init test@test.com") do |stdin, stdout, stderr, thread|
stdin.puts 'test'
stdin.puts 'test'
end
Open3.popen3("./bin/mpw list") do |stdin, stdout, stderr, thread|
stdin.puts 'test'
puts stdout
end

40
test/test_config.rb Normal file
View file

@ -0,0 +1,40 @@
#!/usr/bin/ruby
require 'mpw/config'
require 'test/unit'
require 'locale'
require 'i18n'
class TestConfig < Test::Unit::TestCase
def setup
lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
if defined?(I18n.enforce_available_locales)
I18n.enforce_available_locales = true
end
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
I18n.load_path = Dir["#{File.expand_path('../../i18n', __FILE__)}/*.yml"]
I18n.default_locale = :en
I18n.locale = lang.to_sym
end
def test_00_config
data = { key: 'test@example.com',
lang: 'en',
wallet_dir: '/tmp/test',
gpg_exe: '',
}
@config = MPW::Config.new
@config.setup(data[:key], data[:lang], data[:wallet_dir], data[:gpg_exe])
@config.load_config
data.each do |k,v|
assert_equal(v, @config.send(k))
end
@config.setup_gpg_key('password', 'test@example.com', 2048)
assert(@config.check_gpg_key?)
end
end

View file

@ -1,19 +1,19 @@
#!/usr/bin/ruby
require_relative '../lib/Item'
require 'mpw/item'
require 'test/unit'
require 'yaml'
class TestItem < Test::Unit::TestCase
def setup
@fixture_file = 'files/fixtures.yml'
@fixture_file = 'test/files/fixtures.yml'
@fixtures = YAML.load_file(@fixture_file)
if defined?(I18n.enforce_available_locales)
I18n.enforce_available_locales = false
end
I18n.load_path = Dir['../i18n/cli/*.yml']
I18n.load_path = Dir['./i18n/cli/*.yml']
I18n.default_locale = :en
@ -25,14 +25,12 @@ class TestItem < Test::Unit::TestCase
end
def test_01_add_new
data = {name: @fixtures['add_new']['name'],
group: @fixtures['add_new']['group'],
host: @fixtures['add_new']['host'],
protocol: @fixtures['add_new']['protocol'],
user: @fixtures['add_new']['user'],
password: @fixtures['add_new']['password'],
port: @fixtures['add_new']['port'],
comment: @fixtures['add_new']['comment'],
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'],
}
item = MPW::Item.new(data)
@ -40,27 +38,23 @@ class TestItem < Test::Unit::TestCase
assert(!item.nil?)
assert(!item.empty?)
assert_equal(@fixtures['add_new']['name'], item.name)
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']['password'], item.password)
assert_equal(@fixtures['add_new']['port'].to_i, item.port)
assert_equal(@fixtures['add_new']['comment'], item.comment)
end
def test_02_add_existing
data = {id: @fixtures['add_existing']['id'],
name: @fixtures['add_existing']['name'],
group: @fixtures['add_existing']['group'],
host: @fixtures['add_existing']['host'],
protocol: @fixtures['add_existing']['protocol'],
user: @fixtures['add_existing']['user'],
password: @fixtures['add_existing']['password'],
port: @fixtures['add_existing']['port'],
comment: @fixtures['add_existing']['comment'],
created: @fixtures['add_existing']['created'],
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'],
}
item = MPW::Item.new(data)
@ -69,26 +63,22 @@ class TestItem < Test::Unit::TestCase
assert(!item.empty?)
assert_equal(@fixtures['add_existing']['id'], item.id)
assert_equal(@fixtures['add_existing']['name'], item.name)
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']['password'], item.password)
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)
end
def test_03_update
data = {name: @fixtures['add_new']['name'],
group: @fixtures['add_new']['group'],
host: @fixtures['add_new']['host'],
protocol: @fixtures['add_new']['protocol'],
user: @fixtures['add_new']['user'],
password: @fixtures['add_new']['password'],
port: @fixtures['add_new']['port'],
comment: @fixtures['add_new']['comment'],
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'],
}
item = MPW::Item.new(data)
@ -99,14 +89,12 @@ class TestItem < Test::Unit::TestCase
created = item.created
last_edit = item.last_edit
data = {name: @fixtures['update']['name'],
group: @fixtures['update']['group'],
host: @fixtures['update']['host'],
protocol: @fixtures['update']['protocol'],
user: @fixtures['update']['user'],
password: @fixtures['update']['password'],
port: @fixtures['update']['port'],
comment: @fixtures['update']['comment'],
data = { group: @fixtures['update']['group'],
host: @fixtures['update']['host'],
protocol: @fixtures['update']['protocol'],
user: @fixtures['update']['user'],
port: @fixtures['update']['port'],
comment: @fixtures['update']['comment'],
}
sleep(1)
@ -114,12 +102,10 @@ class TestItem < Test::Unit::TestCase
assert(!item.empty?)
assert_equal(@fixtures['update']['name'], item.name)
assert_equal(@fixtures['update']['group'], item.group)
assert_equal(@fixtures['update']['host'], item.host)
assert_equal(@fixtures['update']['protocol'], item.protocol)
assert_equal(@fixtures['update']['user'], item.user)
assert_equal(@fixtures['update']['password'], item.password)
assert_equal(@fixtures['update']['port'].to_i, item.port)
assert_equal(@fixtures['update']['comment'], item.comment)
@ -127,39 +113,13 @@ class TestItem < Test::Unit::TestCase
assert_not_equal(last_edit, item.last_edit)
end
def test_04_update_with_empty_name
data = {name: @fixtures['add_new']['name'],
group: @fixtures['add_new']['group'],
host: @fixtures['add_new']['host'],
protocol: @fixtures['add_new']['protocol'],
user: @fixtures['add_new']['user'],
password: @fixtures['add_new']['password'],
port: @fixtures['add_new']['port'],
comment: @fixtures['add_new']['comment'],
}
item = MPW::Item.new(data)
assert(!item.nil?)
assert(!item.empty?)
last_edit = item.last_edit
sleep(1)
assert(!item.update({name: ''}))
assert_equal(last_edit, item.last_edit)
end
def test_05_update_one_element
data = {name: @fixtures['add_new']['name'],
group: @fixtures['add_new']['group'],
host: @fixtures['add_new']['host'],
protocol: @fixtures['add_new']['protocol'],
user: @fixtures['add_new']['user'],
password: @fixtures['add_new']['password'],
port: @fixtures['add_new']['port'],
comment: @fixtures['add_new']['comment'],
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'],
}
item = MPW::Item.new(data)
@ -172,12 +132,10 @@ class TestItem < Test::Unit::TestCase
sleep(1)
assert(item.update({comment: @fixtures['update']['comment']}))
assert_equal(@fixtures['add_new']['name'], item.name)
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']['password'], item.password)
assert_equal(@fixtures['add_new']['port'].to_i, item.port)
assert_equal(@fixtures['update']['comment'], item.comment)
@ -185,14 +143,12 @@ class TestItem < Test::Unit::TestCase
end
def test_05_delete
data = {name: @fixtures['add_new']['name'],
group: @fixtures['add_new']['group'],
host: @fixtures['add_new']['host'],
protocol: @fixtures['add_new']['protocol'],
user: @fixtures['add_new']['user'],
password: @fixtures['add_new']['password'],
port: @fixtures['add_new']['port'],
comment: @fixtures['add_new']['comment'],
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'],
}
item = MPW::Item.new(data)
@ -200,17 +156,15 @@ class TestItem < Test::Unit::TestCase
assert(!item.nil?)
assert(!item.empty?)
assert(item.delete)
item.delete
assert(!item.nil?)
assert(item.empty?)
assert_equal(nil, item.id)
assert_equal(nil, item.name)
assert_equal(nil, item.group)
assert_equal(nil, item.host)
assert_equal(nil, item.protocol)
assert_equal(nil, item.user)
assert_equal(nil, item.password)
assert_equal(nil, item.port)
assert_equal(nil, item.comment)
assert_equal(nil, item.created)

View file

@ -1,121 +1,44 @@
#!/usr/bin/ruby
require_relative '../lib/MPW'
require_relative '../lib/Item'
require 'mpw/mpw'
require 'mpw/item'
require 'test/unit'
require 'yaml'
require 'csv'
class TestMPW < Test::Unit::TestCase
def setup
fixture_file = 'files/fixtures.yml'
fixture_file = './test/files/fixtures.yml'
file_gpg = 'test.gpg'
key = ENV['MPW_TEST_KEY']
puts
wallet_file = 'default.gpg'
key = 'test@example.com'
password = 'password'
if defined?(I18n.enforce_available_locales)
I18n.enforce_available_locales = false
end
File.delete(file_gpg) if File.exist?(file_gpg)
@mpw = MPW::MPW.new(file_gpg, key)
@mpw = MPW::MPW.new(key, wallet_file, password)
@fixtures = YAML.load_file(fixture_file)
end
def test_01_import_yaml
import_file = 'files/test_import.yml'
assert(@mpw.import(import_file, :yaml))
assert_equal(2, @mpw.list.length)
item = @mpw.list[0]
assert_equal(@fixtures['add_new']['name'], item.name)
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']['password'], item.password)
assert_equal(@fixtures['add_new']['port'].to_i, item.port)
assert_equal(@fixtures['add_new']['comment'], item.comment)
def test_00_decrypt_empty_file
@mpw.read_data
assert_equal(0, @mpw.list.length)
end
def test_02_export_yaml
import_file = 'files/test_import.yml'
export_file = 'test_export.yml'
assert(@mpw.import(import_file))
assert_equal(2, @mpw.list.length)
assert(@mpw.export(export_file, :yaml))
export = YAML::load_file(export_file)
assert_equal(2, export.length)
result = export.values[0]
assert_equal(@fixtures['add_new']['name'], result['name'])
assert_equal(@fixtures['add_new']['group'], result['group'])
assert_equal(@fixtures['add_new']['host'], result['host'])
assert_equal(@fixtures['add_new']['protocol'], result['protocol'])
assert_equal(@fixtures['add_new']['user'], result['user'])
assert_equal(@fixtures['add_new']['password'], result['password'])
assert_equal(@fixtures['add_new']['port'].to_i, result['port'])
assert_equal(@fixtures['add_new']['comment'], result['comment'])
File.unlink(export_file)
def test_01_encrypt_empty_file
@mpw.read_data
@mpw.write_data
end
def test_03_import_csv
import_file = 'files/test_import.csv'
assert(@mpw.import(import_file, :csv))
assert_equal(2, @mpw.list.length)
import = CSV.parse(File.read(import_file), headers: true)
item = @mpw.list[0]
assert_equal(import[0]['name'], item.name)
assert_equal(import[0]['group'], item.group)
assert_equal(import[0]['host'], item.host)
assert_equal(import[0]['protocol'], item.protocol)
assert_equal(import[0]['user'], item.user)
assert_equal(import[0]['password'], item.password)
assert_equal(import[0]['port'].to_i, item.port)
assert_equal(import[0]['comment'], item.comment)
end
def test_04_export_csv
import_file = 'files/test_import.csv'
export_file = 'test_export.csv'
assert(@mpw.import(import_file, :csv))
assert_equal(2, @mpw.list.length)
assert(@mpw.export(export_file, :csv))
export = CSV.parse(File.read(export_file), headers: true)
assert_equal(2, export.length)
result = export[0]
assert_equal(@fixtures['add_new']['name'], result['name'])
assert_equal(@fixtures['add_new']['group'], result['group'])
assert_equal(@fixtures['add_new']['host'], result['host'])
assert_equal(@fixtures['add_new']['protocol'], result['protocol'])
assert_equal(@fixtures['add_new']['user'], result['user'])
assert_equal(@fixtures['add_new']['password'], result['password'])
assert_equal(@fixtures['add_new']['port'], result['port'])
assert_equal(@fixtures['add_new']['comment'], result['comment'])
File.unlink(export_file)
end
def test_05_add_item
data = {name: @fixtures['add_new']['name'],
group: @fixtures['add_new']['group'],
host: @fixtures['add_new']['host'],
protocol: @fixtures['add_new']['protocol'],
user: @fixtures['add_new']['user'],
password: @fixtures['add_new']['password'],
port: @fixtures['add_new']['port'],
comment: @fixtures['add_new']['comment'],
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'],
}
item = MPW::Item.new(data)
@ -123,69 +46,76 @@ class TestMPW < Test::Unit::TestCase
assert(!item.nil?)
assert(!item.empty?)
assert(@mpw.add(item))
@mpw.read_data
@mpw.add(item)
@mpw.set_password(item.id, @fixtures['add_new']['password'])
assert_equal(1, @mpw.list.length)
item = @mpw.list[0]
assert_equal(@fixtures['add_new']['name'], item.name)
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']['password'], item.password)
assert_equal(@fixtures['add_new']['port'].to_i, item.port)
assert_equal(@fixtures['add_new']['comment'], item.comment)
@fixtures['add_new'].each do |k,v|
if k == 'password'
assert_equal(v, @mpw.get_password(item.id))
else
assert_equal(v, item.send(k).to_s)
end
end
@mpw.write_data
end
def test_11_encrypt_empty_file
assert(@mpw.encrypt)
end
def test_12_encrypt
import_file = 'files/test_import.yml'
assert(@mpw.import(import_file, :yaml))
assert_equal(2, @mpw.list.length)
assert(@mpw.encrypt)
end
def test_13_decrypt_empty_file
assert(@mpw.decrypt)
assert_equal(0, @mpw.list.length)
end
def test_14_decrypt
import_file = 'files/test_import.yml'
assert(@mpw.import(import_file, :yaml))
assert_equal(2, @mpw.list.length)
assert(@mpw.encrypt)
assert(@mpw.decrypt)
assert_equal(2, @mpw.list.length)
def test_03_decrypt_file
@mpw.read_data
assert_equal(1, @mpw.list.length)
item = @mpw.list[0]
assert_equal(@fixtures['add_new']['name'], item.name)
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']['password'], item.password)
assert_equal(@fixtures['add_new']['port'].to_i, item.port)
assert_equal(@fixtures['add_new']['comment'], item.comment)
@fixtures['add_new'].each do |k,v|
if k == 'password'
assert_equal(v, @mpw.get_password(item.id))
else
assert_equal(v, item.send(k).to_s)
end
end
end
def test_15_search
import_file = 'files/test_import.yml'
def test_04_delete_item
@mpw.read_data
assert(@mpw.import(import_file, :yaml))
assert_equal(2, @mpw.list.length)
assert_equal(1, @mpw.list.length)
@mpw.list.each do |item|
item.delete
end
assert_equal(0, @mpw.list.length)
@mpw.write_data
end
def test_05_search
@mpw.read_data
@fixtures.each_value do |v|
data = { group: v['group'],
host: v['host'],
protocol: v['protocol'],
user: v['user'],
port: v['port'],
comment: v['comment'],
}
item = MPW::Item.new(data)
assert(!item.nil?)
assert(!item.empty?)
@mpw.add(item)
@mpw.set_password(item.id, v['password'])
end
assert_equal(3, @mpw.list.length)
assert_equal(1, @mpw.list(group: @fixtures['add_new']['group']).length)
assert_equal(1, @mpw.list(protocol: @fixtures['add_new']['protocol']).length)
assert_equal(2, @mpw.list(search: @fixtures['add_new']['name'][0..-2]).length)
assert_equal(1, @mpw.list(pattern: 'existing').length)
assert_equal(2, @mpw.list(pattern: 'host_[eu]').length)
end
end

View file

@ -1,4 +1,5 @@
#!/usr/bin/ruby
require_relative 'test_mpw.rb'
require_relative 'test_config.rb'
require_relative 'test_item.rb'
require_relative 'test_mpw.rb'