mpw 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_item.rb ADDED
@@ -0,0 +1,218 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require_relative '../lib/Item'
4
+ require 'test/unit'
5
+ require 'yaml'
6
+
7
+ class TestItem < Test::Unit::TestCase
8
+ def setup
9
+ @fixture_file = 'files/fixtures.yml'
10
+ @fixtures = YAML.load_file(@fixture_file)
11
+
12
+ if defined?(I18n.enforce_available_locales)
13
+ I18n.enforce_available_locales = false
14
+ end
15
+
16
+ I18n.load_path = Dir['../i18n/cli/*.yml']
17
+ I18n.default_locale = :en
18
+
19
+
20
+ puts
21
+ end
22
+
23
+ def test_00_add_without_name
24
+ assert_raise(RuntimeError){MPW::Item.new}
25
+ end
26
+
27
+ def test_01_add_new
28
+ data = {name: @fixtures['add_new']['name'],
29
+ group: @fixtures['add_new']['group'],
30
+ host: @fixtures['add_new']['host'],
31
+ protocol: @fixtures['add_new']['protocol'],
32
+ user: @fixtures['add_new']['user'],
33
+ password: @fixtures['add_new']['password'],
34
+ port: @fixtures['add_new']['port'],
35
+ comment: @fixtures['add_new']['comment'],
36
+ }
37
+
38
+ item = MPW::Item.new(data)
39
+
40
+ assert(!item.nil?)
41
+ assert(!item.empty?)
42
+
43
+ assert_equal(@fixtures['add_new']['name'], item.name)
44
+ assert_equal(@fixtures['add_new']['group'], item.group)
45
+ assert_equal(@fixtures['add_new']['host'], item.host)
46
+ assert_equal(@fixtures['add_new']['protocol'], item.protocol)
47
+ assert_equal(@fixtures['add_new']['user'], item.user)
48
+ assert_equal(@fixtures['add_new']['password'], item.password)
49
+ assert_equal(@fixtures['add_new']['port'].to_i, item.port)
50
+ assert_equal(@fixtures['add_new']['comment'], item.comment)
51
+ end
52
+
53
+ def test_02_add_existing
54
+ data = {id: @fixtures['add_existing']['id'],
55
+ name: @fixtures['add_existing']['name'],
56
+ group: @fixtures['add_existing']['group'],
57
+ host: @fixtures['add_existing']['host'],
58
+ protocol: @fixtures['add_existing']['protocol'],
59
+ user: @fixtures['add_existing']['user'],
60
+ password: @fixtures['add_existing']['password'],
61
+ port: @fixtures['add_existing']['port'],
62
+ comment: @fixtures['add_existing']['comment'],
63
+ created: @fixtures['add_existing']['created'],
64
+ }
65
+
66
+ item = MPW::Item.new(data)
67
+
68
+ assert(!item.nil?)
69
+ assert(!item.empty?)
70
+
71
+ assert_equal(@fixtures['add_existing']['id'], item.id)
72
+ assert_equal(@fixtures['add_existing']['name'], item.name)
73
+ assert_equal(@fixtures['add_existing']['group'], item.group)
74
+ assert_equal(@fixtures['add_existing']['host'], item.host)
75
+ assert_equal(@fixtures['add_existing']['protocol'], item.protocol)
76
+ assert_equal(@fixtures['add_existing']['user'], item.user)
77
+ assert_equal(@fixtures['add_existing']['password'], item.password)
78
+ assert_equal(@fixtures['add_existing']['port'].to_i, item.port)
79
+ assert_equal(@fixtures['add_existing']['comment'], item.comment)
80
+ assert_equal(@fixtures['add_existing']['created'], item.created)
81
+ end
82
+
83
+ def test_03_update
84
+ data = {name: @fixtures['add_new']['name'],
85
+ group: @fixtures['add_new']['group'],
86
+ host: @fixtures['add_new']['host'],
87
+ protocol: @fixtures['add_new']['protocol'],
88
+ user: @fixtures['add_new']['user'],
89
+ password: @fixtures['add_new']['password'],
90
+ port: @fixtures['add_new']['port'],
91
+ comment: @fixtures['add_new']['comment'],
92
+ }
93
+
94
+ item = MPW::Item.new(data)
95
+
96
+ assert(!item.nil?)
97
+ assert(!item.empty?)
98
+
99
+ created = item.created
100
+ last_edit = item.last_edit
101
+
102
+ data = {name: @fixtures['update']['name'],
103
+ group: @fixtures['update']['group'],
104
+ host: @fixtures['update']['host'],
105
+ protocol: @fixtures['update']['protocol'],
106
+ user: @fixtures['update']['user'],
107
+ password: @fixtures['update']['password'],
108
+ port: @fixtures['update']['port'],
109
+ comment: @fixtures['update']['comment'],
110
+ }
111
+
112
+ sleep(1)
113
+ assert(item.update(data))
114
+
115
+ assert(!item.empty?)
116
+
117
+ assert_equal(@fixtures['update']['name'], item.name)
118
+ assert_equal(@fixtures['update']['group'], item.group)
119
+ assert_equal(@fixtures['update']['host'], item.host)
120
+ assert_equal(@fixtures['update']['protocol'], item.protocol)
121
+ assert_equal(@fixtures['update']['user'], item.user)
122
+ assert_equal(@fixtures['update']['password'], item.password)
123
+ assert_equal(@fixtures['update']['port'].to_i, item.port)
124
+ assert_equal(@fixtures['update']['comment'], item.comment)
125
+
126
+ assert_equal(created, item.created)
127
+ assert_not_equal(last_edit, item.last_edit)
128
+ end
129
+
130
+ def test_04_update_with_empty_name
131
+ data = {name: @fixtures['add_new']['name'],
132
+ group: @fixtures['add_new']['group'],
133
+ host: @fixtures['add_new']['host'],
134
+ protocol: @fixtures['add_new']['protocol'],
135
+ user: @fixtures['add_new']['user'],
136
+ password: @fixtures['add_new']['password'],
137
+ port: @fixtures['add_new']['port'],
138
+ comment: @fixtures['add_new']['comment'],
139
+ }
140
+
141
+ item = MPW::Item.new(data)
142
+
143
+ assert(!item.nil?)
144
+ assert(!item.empty?)
145
+
146
+ last_edit = item.last_edit
147
+
148
+ sleep(1)
149
+ assert(!item.update({name: ''}))
150
+
151
+ assert_equal(last_edit, item.last_edit)
152
+ end
153
+
154
+ def test_05_update_one_element
155
+ data = {name: @fixtures['add_new']['name'],
156
+ group: @fixtures['add_new']['group'],
157
+ host: @fixtures['add_new']['host'],
158
+ protocol: @fixtures['add_new']['protocol'],
159
+ user: @fixtures['add_new']['user'],
160
+ password: @fixtures['add_new']['password'],
161
+ port: @fixtures['add_new']['port'],
162
+ comment: @fixtures['add_new']['comment'],
163
+ }
164
+
165
+ item = MPW::Item.new(data)
166
+
167
+ assert(!item.nil?)
168
+ assert(!item.empty?)
169
+
170
+ last_edit = item.last_edit
171
+
172
+ sleep(1)
173
+ assert(item.update({comment: @fixtures['update']['comment']}))
174
+
175
+ assert_equal(@fixtures['add_new']['name'], item.name)
176
+ assert_equal(@fixtures['add_new']['group'], item.group)
177
+ assert_equal(@fixtures['add_new']['host'], item.host)
178
+ assert_equal(@fixtures['add_new']['protocol'], item.protocol)
179
+ assert_equal(@fixtures['add_new']['user'], item.user)
180
+ assert_equal(@fixtures['add_new']['password'], item.password)
181
+ assert_equal(@fixtures['add_new']['port'].to_i, item.port)
182
+ assert_equal(@fixtures['update']['comment'], item.comment)
183
+
184
+ assert_not_equal(last_edit, item.last_edit)
185
+ end
186
+
187
+ def test_05_delete
188
+ data = {name: @fixtures['add_new']['name'],
189
+ group: @fixtures['add_new']['group'],
190
+ host: @fixtures['add_new']['host'],
191
+ protocol: @fixtures['add_new']['protocol'],
192
+ user: @fixtures['add_new']['user'],
193
+ password: @fixtures['add_new']['password'],
194
+ port: @fixtures['add_new']['port'],
195
+ comment: @fixtures['add_new']['comment'],
196
+ }
197
+
198
+ item = MPW::Item.new(data)
199
+
200
+ assert(!item.nil?)
201
+ assert(!item.empty?)
202
+
203
+ assert(item.delete)
204
+ assert(!item.nil?)
205
+ assert(item.empty?)
206
+
207
+ assert_equal(nil, item.id)
208
+ assert_equal(nil, item.name)
209
+ assert_equal(nil, item.group)
210
+ assert_equal(nil, item.host)
211
+ assert_equal(nil, item.protocol)
212
+ assert_equal(nil, item.user)
213
+ assert_equal(nil, item.password)
214
+ assert_equal(nil, item.port)
215
+ assert_equal(nil, item.comment)
216
+ assert_equal(nil, item.created)
217
+ end
218
+ end
data/test/test_mpw.rb ADDED
@@ -0,0 +1,191 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require_relative '../lib/MPW'
4
+ require_relative '../lib/Item'
5
+ require 'test/unit'
6
+ require 'yaml'
7
+ require 'csv'
8
+
9
+ class TestMPW < Test::Unit::TestCase
10
+ def setup
11
+ fixture_file = 'files/fixtures.yml'
12
+
13
+ file_gpg = 'test.gpg'
14
+ key = ENV['MPW_TEST_KEY']
15
+
16
+ puts
17
+
18
+ if defined?(I18n.enforce_available_locales)
19
+ I18n.enforce_available_locales = false
20
+ end
21
+
22
+ File.delete(file_gpg) if File.exist?(file_gpg)
23
+
24
+ @mpw = MPW::MPW.new(file_gpg, key)
25
+ @fixtures = YAML.load_file(fixture_file)
26
+ end
27
+
28
+ def test_01_import_yaml
29
+ import_file = 'files/test_import.yml'
30
+
31
+ assert(@mpw.import(import_file, :yaml))
32
+ assert_equal(2, @mpw.list.length)
33
+
34
+ item = @mpw.list[0]
35
+ assert_equal(@fixtures['add_new']['name'], item.name)
36
+ assert_equal(@fixtures['add_new']['group'], item.group)
37
+ assert_equal(@fixtures['add_new']['host'], item.host)
38
+ assert_equal(@fixtures['add_new']['protocol'], item.protocol)
39
+ assert_equal(@fixtures['add_new']['user'], item.user)
40
+ assert_equal(@fixtures['add_new']['password'], item.password)
41
+ assert_equal(@fixtures['add_new']['port'].to_i, item.port)
42
+ assert_equal(@fixtures['add_new']['comment'], item.comment)
43
+ end
44
+
45
+ def test_02_export_yaml
46
+ import_file = 'files/test_import.yml'
47
+ export_file = 'test_export.yml'
48
+
49
+ assert(@mpw.import(import_file))
50
+ assert_equal(2, @mpw.list.length)
51
+ assert(@mpw.export(export_file, :yaml))
52
+ export = YAML::load_file(export_file)
53
+ assert_equal(2, export.length)
54
+
55
+ result = export.values[0]
56
+ assert_equal(@fixtures['add_new']['name'], result['name'])
57
+ assert_equal(@fixtures['add_new']['group'], result['group'])
58
+ assert_equal(@fixtures['add_new']['host'], result['host'])
59
+ assert_equal(@fixtures['add_new']['protocol'], result['protocol'])
60
+ assert_equal(@fixtures['add_new']['user'], result['user'])
61
+ assert_equal(@fixtures['add_new']['password'], result['password'])
62
+ assert_equal(@fixtures['add_new']['port'].to_i, result['port'])
63
+ assert_equal(@fixtures['add_new']['comment'], result['comment'])
64
+
65
+ File.unlink(export_file)
66
+ end
67
+
68
+ def test_03_import_csv
69
+ import_file = 'files/test_import.csv'
70
+
71
+ assert(@mpw.import(import_file, :csv))
72
+ assert_equal(2, @mpw.list.length)
73
+
74
+ import = CSV.parse(File.read(import_file), headers: true)
75
+
76
+ item = @mpw.list[0]
77
+ assert_equal(import[0]['name'], item.name)
78
+ assert_equal(import[0]['group'], item.group)
79
+ assert_equal(import[0]['host'], item.host)
80
+ assert_equal(import[0]['protocol'], item.protocol)
81
+ assert_equal(import[0]['user'], item.user)
82
+ assert_equal(import[0]['password'], item.password)
83
+ assert_equal(import[0]['port'].to_i, item.port)
84
+ assert_equal(import[0]['comment'], item.comment)
85
+ end
86
+
87
+ def test_04_export_csv
88
+ import_file = 'files/test_import.csv'
89
+ export_file = 'test_export.csv'
90
+
91
+ assert(@mpw.import(import_file, :csv))
92
+ assert_equal(2, @mpw.list.length)
93
+ assert(@mpw.export(export_file, :csv))
94
+ export = CSV.parse(File.read(export_file), headers: true)
95
+ assert_equal(2, export.length)
96
+
97
+ result = export[0]
98
+ assert_equal(@fixtures['add_new']['name'], result['name'])
99
+ assert_equal(@fixtures['add_new']['group'], result['group'])
100
+ assert_equal(@fixtures['add_new']['host'], result['host'])
101
+ assert_equal(@fixtures['add_new']['protocol'], result['protocol'])
102
+ assert_equal(@fixtures['add_new']['user'], result['user'])
103
+ assert_equal(@fixtures['add_new']['password'], result['password'])
104
+ assert_equal(@fixtures['add_new']['port'], result['port'])
105
+ assert_equal(@fixtures['add_new']['comment'], result['comment'])
106
+
107
+ File.unlink(export_file)
108
+ end
109
+
110
+ def test_05_add_item
111
+ data = {name: @fixtures['add_new']['name'],
112
+ group: @fixtures['add_new']['group'],
113
+ host: @fixtures['add_new']['host'],
114
+ protocol: @fixtures['add_new']['protocol'],
115
+ user: @fixtures['add_new']['user'],
116
+ password: @fixtures['add_new']['password'],
117
+ port: @fixtures['add_new']['port'],
118
+ comment: @fixtures['add_new']['comment'],
119
+ }
120
+
121
+ item = MPW::Item.new(data)
122
+
123
+ assert(!item.nil?)
124
+ assert(!item.empty?)
125
+
126
+ assert(@mpw.add(item))
127
+
128
+ assert_equal(1, @mpw.list.length)
129
+
130
+ item = @mpw.list[0]
131
+ assert_equal(@fixtures['add_new']['name'], item.name)
132
+ assert_equal(@fixtures['add_new']['group'], item.group)
133
+ assert_equal(@fixtures['add_new']['host'], item.host)
134
+ assert_equal(@fixtures['add_new']['protocol'], item.protocol)
135
+ assert_equal(@fixtures['add_new']['user'], item.user)
136
+ assert_equal(@fixtures['add_new']['password'], item.password)
137
+ assert_equal(@fixtures['add_new']['port'].to_i, item.port)
138
+ assert_equal(@fixtures['add_new']['comment'], item.comment)
139
+ end
140
+
141
+ def test_11_encrypt_empty_file
142
+ assert(@mpw.encrypt)
143
+ end
144
+
145
+ def test_12_encrypt
146
+ import_file = 'files/test_import.yml'
147
+
148
+ assert(@mpw.import(import_file, :yaml))
149
+ assert_equal(2, @mpw.list.length)
150
+
151
+ assert(@mpw.encrypt)
152
+ end
153
+
154
+ def test_13_decrypt_empty_file
155
+ assert(@mpw.decrypt)
156
+ assert_equal(0, @mpw.list.length)
157
+ end
158
+
159
+ def test_14_decrypt
160
+ import_file = 'files/test_import.yml'
161
+
162
+ assert(@mpw.import(import_file, :yaml))
163
+ assert_equal(2, @mpw.list.length)
164
+
165
+ assert(@mpw.encrypt)
166
+
167
+ assert(@mpw.decrypt)
168
+ assert_equal(2, @mpw.list.length)
169
+
170
+ item = @mpw.list[0]
171
+ assert_equal(@fixtures['add_new']['name'], item.name)
172
+ assert_equal(@fixtures['add_new']['group'], item.group)
173
+ assert_equal(@fixtures['add_new']['host'], item.host)
174
+ assert_equal(@fixtures['add_new']['protocol'], item.protocol)
175
+ assert_equal(@fixtures['add_new']['user'], item.user)
176
+ assert_equal(@fixtures['add_new']['password'], item.password)
177
+ assert_equal(@fixtures['add_new']['port'].to_i, item.port)
178
+ assert_equal(@fixtures['add_new']['comment'], item.comment)
179
+ end
180
+
181
+ def test_15_search
182
+ import_file = 'files/test_import.yml'
183
+
184
+ assert(@mpw.import(import_file, :yaml))
185
+ assert_equal(2, @mpw.list.length)
186
+
187
+ assert_equal(1, @mpw.list(group: @fixtures['add_new']['group']).length)
188
+ assert_equal(1, @mpw.list(protocol: @fixtures['add_new']['protocol']).length)
189
+ assert_equal(2, @mpw.list(search: @fixtures['add_new']['name'][0..-2]).length)
190
+ end
191
+ end
data/test/tests.rb ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require_relative 'test_mpw.rb'
4
+ require_relative 'test_item.rb'
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mpw
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - nishiki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Save and read your password with gpg
14
+ email:
15
+ - gems@yae.im
16
+ executables:
17
+ - mpw
18
+ - mpw-server
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".gitignore"
23
+ - CHANGELOG
24
+ - Gemfile
25
+ - LICENSE
26
+ - README.md
27
+ - VERSION
28
+ - bin/mpw
29
+ - bin/mpw-server
30
+ - bin/mpw-ssh
31
+ - i18n/cli/en.yml
32
+ - i18n/cli/fr.yml
33
+ - i18n/server/en.yml
34
+ - i18n/server/fr.yml
35
+ - lib/mpw/config.rb
36
+ - lib/mpw/item.rb
37
+ - lib/mpw/mpw.rb
38
+ - lib/mpw/server.rb
39
+ - lib/mpw/sync.rb
40
+ - lib/mpw/sync/ftp.rb
41
+ - lib/mpw/sync/mpw.rb
42
+ - lib/mpw/sync/ssh.rb
43
+ - lib/mpw/ui/cli.rb
44
+ - lib/mpw/ui/clissh.rb
45
+ - mpw.gemspec
46
+ - test/files/fixtures.yml
47
+ - test/files/test_import.csv
48
+ - test/files/test_import.yml
49
+ - test/test_item.rb
50
+ - test/test_mpw.rb
51
+ - test/tests.rb
52
+ homepage: https://github.com/nishiki/manage-password
53
+ licenses:
54
+ - GPL
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.2.2
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Manage your password
76
+ test_files:
77
+ - test/files/fixtures.yml
78
+ - test/files/test_import.csv
79
+ - test/files/test_import.yml
80
+ - test/test_item.rb
81
+ - test/test_mpw.rb
82
+ - test/tests.rb