mpw 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
 
@@ -12,18 +13,18 @@ Gem::Specification.new do |spec|
12
13
  spec.homepage = 'https://github.com/nishiki/manage-password'
13
14
  spec.license = 'GPL-2.0'
14
15
 
15
- spec.files = `git ls-files -z`.split("\x0")
16
+ spec.files = %x(git ls-files -z).split("\x0")
16
17
  spec.executables = ['mpw']
17
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
19
  spec.require_paths = ['lib']
19
20
 
20
- spec.add_dependency "i18n", "~> 0.7", ">= 0.7.0"
21
- spec.add_dependency "gpgme", "~> 2.0", ">= 2.0.12"
22
- spec.add_dependency "highline", "~> 1.7", ">= 1.7.8"
23
- spec.add_dependency "locale", "~> 2.1", ">= 2.1.2"
24
- spec.add_dependency "colorize", "~> 0.8", ">= 0.8.1"
25
- spec.add_dependency "net-ssh", "~> 3.2", ">= 3.2.0"
26
- spec.add_dependency "net-sftp", "~> 2.1", ">= 2.1.2"
27
- spec.add_dependency "clipboard", "~> 1.1", ">= 1.1.1"
28
- spec.add_dependency "rotp", "~> 3.1", ">= 3.1.0"
21
+ spec.required_ruby_version = '>= 2.1'
22
+
23
+ spec.add_dependency 'i18n', '~> 0.7', '>= 0.7.0'
24
+ spec.add_dependency 'gpgme', '~> 2.0', '>= 2.0.12'
25
+ spec.add_dependency 'highline', '~> 1.7', '>= 1.7.8'
26
+ spec.add_dependency 'locale', '~> 2.1', '>= 2.1.2'
27
+ spec.add_dependency 'colorize', '~> 0.8', '>= 0.8.1'
28
+ spec.add_dependency 'clipboard', '~> 1.1', '>= 1.1.1'
29
+ spec.add_dependency 'rotp', '~> 3.1', '>= 3.1.0'
29
30
  end
@@ -1,9 +1,9 @@
1
1
  ---
2
- host: # <%= I18n.t('form.add_item.host') %>
3
- user: # <%= I18n.t('form.add_item.login') %>
4
- group: # <%= I18n.t('form.add_item.group') %>
5
- protocol: # <%= I18n.t('form.add_item.protocol') %><% if not password %>
6
- password: # <%= I18n.t('form.add_item.password') %><% end %>
7
- port: # <%= I18n.t('form.add_item.port') %>
8
- comment: # <%= I18n.t('form.add_item.comment') %>
9
- otp_key: # <%= I18n.t('form.add_item.otp_key') %>
2
+ host: <%= options[:host] %> # <%= I18n.t('form.add_item.host') %>
3
+ user: <%= options[:user] %> # <%= I18n.t('form.add_item.login') %>
4
+ group: <%= options[:group] %> # <%= I18n.t('form.add_item.group') %>
5
+ protocol: <%= options[:protocol] %> # <%= I18n.t('form.add_item.protocol') %><% unless password %>
6
+ password: # <%= I18n.t('form.add_item.password') %><% end %>
7
+ port: <%= options[:port] %> # <%= I18n.t('form.add_item.port') %>
8
+ comment: <%= options[:comment] %> # <%= I18n.t('form.add_item.comment') %>
9
+ otp_key: <%= options[:otp] %> # <%= I18n.t('form.add_item.otp_key') %>
@@ -1,17 +1,17 @@
1
1
  ---
2
2
  # <%= I18n.t('form.update_item.host') %>
3
- host: <%= item.host %>
3
+ host: <% if options[:host] %><%= options[:host] %><% else %><%= item.host %><% end %>
4
4
  # <%= I18n.t('form.update_item.login') %>
5
- user: <%= item.user %><% if not password %>
5
+ user: <% if options[:user] %><%= options[:user] %><% else %><%= item.user %><% end %><% unless password %>
6
6
  # <%= I18n.t('form.update_item.password') %>
7
7
  password: <% end %>
8
8
  # <%= I18n.t('form.update_item.group') %>
9
- group: <%= item.group %>
9
+ group: <% if options[:group] %><%= options[:group] %><% else %><%= item.group %><% end %>
10
10
  # <%= I18n.t('form.update_item.protocol') %>
11
- protocol: <%= item.protocol %>
11
+ protocol: <% if options[:protocol] %><%= options[:protocol] %><% else %><%= item.protocol %><% end %>
12
12
  # <%= I18n.t('form.update_item.port') %>
13
- port: <%= item.port %>
13
+ port: <% if options[:port] %><%= options[:port] %><% else %><%= item.port %><% end %>
14
14
  # <%= I18n.t('form.update_item.otp_key') %>
15
- otp_key:
15
+ otp_key: <% if options[:otp_key] %><%= options[:otp_key] %><% end %>
16
16
  # <%= I18n.t('form.update_item.comment') %>
17
- comment: <%= item.comment %>
17
+ comment: <% if options[:comment] %><%= options[:comment] %><% else %><%= item.comment %><% end %>
@@ -6,59 +6,74 @@ require 'locale'
6
6
  require 'i18n'
7
7
 
8
8
  class TestConfig < Test::Unit::TestCase
9
- def setup
10
- lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
11
-
12
- if defined?(I18n.enforce_available_locales)
13
- I18n.enforce_available_locales = true
14
- end
15
-
16
- I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
17
- I18n.load_path = Dir["#{File.expand_path('../../i18n', __FILE__)}/*.yml"]
18
- I18n.default_locale = :en
19
- I18n.locale = lang.to_sym
20
- end
21
-
22
- def test_00_config
23
- data = { gpg_key: 'test@example.com',
24
- lang: 'en',
25
- wallet_dir: '/tmp/test',
26
- gpg_exe: '',
27
- }
28
-
29
- @config = MPW::Config.new
30
- @config.setup(data)
31
- @config.load_config
32
-
33
- data.each do |k,v|
34
- assert_equal(v, @config.send(k))
35
- end
36
-
37
- @config.setup_gpg_key('password', 'test@example.com', 2048)
38
- assert(@config.check_gpg_key?)
39
- end
40
-
41
- def test_01_password
42
- data = { pwd_alpha: false,
43
- pwd_numeric: false,
44
- pwd_special: true,
45
- pwd_length: 32,
46
- }
47
-
48
- @config = MPW::Config.new
49
- @config.load_config
50
-
51
- assert_equal(@config.password[:length], 16)
52
- assert(@config.password[:alpha])
53
- assert(@config.password[:numeric])
54
- assert(!@config.password[:special])
55
-
56
- @config.setup(data)
57
- @config.load_config
58
-
59
- assert_equal(@config.password[:length], data[:pwd_length])
60
- assert(!@config.password[:alpha])
61
- assert(!@config.password[:numeric])
62
- assert(@config.password[:special])
63
- end
9
+ def setup
10
+ lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
11
+
12
+ if defined?(I18n.enforce_available_locales)
13
+ I18n.enforce_available_locales = true
14
+ end
15
+
16
+ I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
17
+ I18n.load_path = Dir["#{File.expand_path('../../i18n', __FILE__)}/*.yml"]
18
+ I18n.default_locale = :en
19
+ I18n.locale = lang.to_sym
20
+ end
21
+
22
+ def test_00_config
23
+ data = { gpg_key: 'test@example.com',
24
+ lang: 'en',
25
+ wallet_dir: '/tmp/test',
26
+ gpg_exe: '',
27
+ }
28
+
29
+ @config = MPW::Config.new
30
+ @config.setup(data)
31
+ @config.load_config
32
+
33
+ data.each do |k,v|
34
+ assert_equal(v, @config.send(k))
35
+ end
36
+
37
+ @config.setup_gpg_key('password', 'test@example.com', 2048)
38
+ assert(@config.check_gpg_key?)
39
+ end
40
+
41
+ def test_01_password
42
+ data = { pwd_alpha: false,
43
+ pwd_numeric: false,
44
+ pwd_special: true,
45
+ pwd_length: 32,
46
+ }
47
+
48
+ @config = MPW::Config.new
49
+ @config.load_config
50
+
51
+ assert_equal(@config.password[:length], 16)
52
+ assert(@config.password[:alpha])
53
+ assert(@config.password[:numeric])
54
+ assert(!@config.password[:special])
55
+
56
+ @config.setup(data)
57
+ @config.load_config
58
+
59
+ assert_equal(@config.password[:length], data[:pwd_length])
60
+ assert(!@config.password[:alpha])
61
+ assert(!@config.password[:numeric])
62
+ assert(@config.password[:special])
63
+ end
64
+
65
+ def test_02_wallet_paths
66
+ new_path = '/tmp/mpw-test'
67
+
68
+ @config = MPW::Config.new
69
+ @config.load_config
70
+
71
+ assert(!@config.wallet_paths['default'])
72
+
73
+ @config.set_wallet_path(new_path, 'default')
74
+ assert_equal(@config.wallet_paths['default'], new_path)
75
+
76
+ @config.set_wallet_path('default', 'default')
77
+ assert(!@config.wallet_paths['default'])
78
+ end
64
79
  end
@@ -1,172 +1,172 @@
1
1
  #!/usr/bin/ruby
2
-
2
+
3
3
  require 'mpw/item'
4
4
  require 'test/unit'
5
5
  require 'yaml'
6
-
6
+
7
7
  class TestItem < Test::Unit::TestCase
8
- def setup
9
- @fixture_file = 'test/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 = { group: @fixtures['add_new']['group'],
29
- host: @fixtures['add_new']['host'],
30
- protocol: @fixtures['add_new']['protocol'],
31
- user: @fixtures['add_new']['user'],
32
- port: @fixtures['add_new']['port'],
33
- comment: @fixtures['add_new']['comment'],
34
- }
35
-
36
- item = MPW::Item.new(data)
37
-
38
- assert(!item.nil?)
39
- assert(!item.empty?)
40
-
41
- assert_equal(@fixtures['add_new']['group'], item.group)
42
- assert_equal(@fixtures['add_new']['host'], item.host)
43
- assert_equal(@fixtures['add_new']['protocol'], item.protocol)
44
- assert_equal(@fixtures['add_new']['user'], item.user)
45
- assert_equal(@fixtures['add_new']['port'].to_i, item.port)
46
- assert_equal(@fixtures['add_new']['comment'], item.comment)
47
- end
48
-
49
- def test_02_add_existing
50
- data = { id: @fixtures['add_existing']['id'],
51
- group: @fixtures['add_existing']['group'],
52
- host: @fixtures['add_existing']['host'],
53
- protocol: @fixtures['add_existing']['protocol'],
54
- user: @fixtures['add_existing']['user'],
55
- port: @fixtures['add_existing']['port'],
56
- comment: @fixtures['add_existing']['comment'],
57
- created: @fixtures['add_existing']['created'],
58
- }
59
-
60
- item = MPW::Item.new(data)
61
-
62
- assert(!item.nil?)
63
- assert(!item.empty?)
64
-
65
- assert_equal(@fixtures['add_existing']['id'], item.id)
66
- assert_equal(@fixtures['add_existing']['group'], item.group)
67
- assert_equal(@fixtures['add_existing']['host'], item.host)
68
- assert_equal(@fixtures['add_existing']['protocol'], item.protocol)
69
- assert_equal(@fixtures['add_existing']['user'], item.user)
70
- assert_equal(@fixtures['add_existing']['port'].to_i, item.port)
71
- assert_equal(@fixtures['add_existing']['comment'], item.comment)
72
- assert_equal(@fixtures['add_existing']['created'], item.created)
73
- end
74
-
75
- def test_03_update
76
- data = { group: @fixtures['add_new']['group'],
77
- host: @fixtures['add_new']['host'],
78
- protocol: @fixtures['add_new']['protocol'],
79
- user: @fixtures['add_new']['user'],
80
- port: @fixtures['add_new']['port'],
81
- comment: @fixtures['add_new']['comment'],
82
- }
83
-
84
- item = MPW::Item.new(data)
85
-
86
- assert(!item.nil?)
87
- assert(!item.empty?)
88
-
89
- created = item.created
90
- last_edit = item.last_edit
91
-
92
- data = { group: @fixtures['update']['group'],
93
- host: @fixtures['update']['host'],
94
- protocol: @fixtures['update']['protocol'],
95
- user: @fixtures['update']['user'],
96
- port: @fixtures['update']['port'],
97
- comment: @fixtures['update']['comment'],
98
- }
99
-
100
- sleep(1)
101
- assert(item.update(data))
102
-
103
- assert(!item.empty?)
104
-
105
- assert_equal(@fixtures['update']['group'], item.group)
106
- assert_equal(@fixtures['update']['host'], item.host)
107
- assert_equal(@fixtures['update']['protocol'], item.protocol)
108
- assert_equal(@fixtures['update']['user'], item.user)
109
- assert_equal(@fixtures['update']['port'].to_i, item.port)
110
- assert_equal(@fixtures['update']['comment'], item.comment)
111
-
112
- assert_equal(created, item.created)
113
- assert_not_equal(last_edit, item.last_edit)
114
- end
115
-
116
- def test_05_update_one_element
117
- data = { group: @fixtures['add_new']['group'],
118
- host: @fixtures['add_new']['host'],
119
- protocol: @fixtures['add_new']['protocol'],
120
- user: @fixtures['add_new']['user'],
121
- port: @fixtures['add_new']['port'],
122
- comment: @fixtures['add_new']['comment'],
123
- }
124
-
125
- item = MPW::Item.new(data)
126
-
127
- assert(!item.nil?)
128
- assert(!item.empty?)
129
-
130
- last_edit = item.last_edit
131
-
132
- sleep(1)
133
- assert(item.update({comment: @fixtures['update']['comment']}))
134
-
135
- assert_equal(@fixtures['add_new']['group'], item.group)
136
- assert_equal(@fixtures['add_new']['host'], item.host)
137
- assert_equal(@fixtures['add_new']['protocol'], item.protocol)
138
- assert_equal(@fixtures['add_new']['user'], item.user)
139
- assert_equal(@fixtures['add_new']['port'].to_i, item.port)
140
- assert_equal(@fixtures['update']['comment'], item.comment)
141
-
142
- assert_not_equal(last_edit, item.last_edit)
143
- end
144
-
145
- def test_05_delete
146
- data = { group: @fixtures['add_new']['group'],
147
- host: @fixtures['add_new']['host'],
148
- protocol: @fixtures['add_new']['protocol'],
149
- user: @fixtures['add_new']['user'],
150
- port: @fixtures['add_new']['port'],
151
- comment: @fixtures['add_new']['comment'],
152
- }
153
-
154
- item = MPW::Item.new(data)
155
-
156
- assert(!item.nil?)
157
- assert(!item.empty?)
158
-
159
- item.delete
160
- assert(!item.nil?)
161
- assert(item.empty?)
162
-
163
- assert_equal(nil, item.id)
164
- assert_equal(nil, item.group)
165
- assert_equal(nil, item.host)
166
- assert_equal(nil, item.protocol)
167
- assert_equal(nil, item.user)
168
- assert_equal(nil, item.port)
169
- assert_equal(nil, item.comment)
170
- assert_equal(nil, item.created)
171
- end
172
- end
8
+ def setup
9
+ @fixture_file = 'test/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 = { group: @fixtures['add_new']['group'],
29
+ host: @fixtures['add_new']['host'],
30
+ protocol: @fixtures['add_new']['protocol'],
31
+ user: @fixtures['add_new']['user'],
32
+ port: @fixtures['add_new']['port'],
33
+ comment: @fixtures['add_new']['comment'],
34
+ }
35
+
36
+ item = MPW::Item.new(data)
37
+
38
+ assert(!item.nil?)
39
+ assert(!item.empty?)
40
+
41
+ assert_equal(@fixtures['add_new']['group'], item.group)
42
+ assert_equal(@fixtures['add_new']['host'], item.host)
43
+ assert_equal(@fixtures['add_new']['protocol'], item.protocol)
44
+ assert_equal(@fixtures['add_new']['user'], item.user)
45
+ assert_equal(@fixtures['add_new']['port'].to_i, item.port)
46
+ assert_equal(@fixtures['add_new']['comment'], item.comment)
47
+ end
48
+
49
+ def test_02_add_existing
50
+ data = { id: @fixtures['add_existing']['id'],
51
+ group: @fixtures['add_existing']['group'],
52
+ host: @fixtures['add_existing']['host'],
53
+ protocol: @fixtures['add_existing']['protocol'],
54
+ user: @fixtures['add_existing']['user'],
55
+ port: @fixtures['add_existing']['port'],
56
+ comment: @fixtures['add_existing']['comment'],
57
+ created: @fixtures['add_existing']['created'],
58
+ }
59
+
60
+ item = MPW::Item.new(data)
61
+
62
+ assert(!item.nil?)
63
+ assert(!item.empty?)
64
+
65
+ assert_equal(@fixtures['add_existing']['id'], item.id)
66
+ assert_equal(@fixtures['add_existing']['group'], item.group)
67
+ assert_equal(@fixtures['add_existing']['host'], item.host)
68
+ assert_equal(@fixtures['add_existing']['protocol'], item.protocol)
69
+ assert_equal(@fixtures['add_existing']['user'], item.user)
70
+ assert_equal(@fixtures['add_existing']['port'].to_i, item.port)
71
+ assert_equal(@fixtures['add_existing']['comment'], item.comment)
72
+ assert_equal(@fixtures['add_existing']['created'], item.created)
73
+ end
74
+
75
+ def test_03_update
76
+ data = { group: @fixtures['add_new']['group'],
77
+ host: @fixtures['add_new']['host'],
78
+ protocol: @fixtures['add_new']['protocol'],
79
+ user: @fixtures['add_new']['user'],
80
+ port: @fixtures['add_new']['port'],
81
+ comment: @fixtures['add_new']['comment'],
82
+ }
83
+
84
+ item = MPW::Item.new(data)
85
+
86
+ assert(!item.nil?)
87
+ assert(!item.empty?)
88
+
89
+ created = item.created
90
+ last_edit = item.last_edit
91
+
92
+ data = { group: @fixtures['update']['group'],
93
+ host: @fixtures['update']['host'],
94
+ protocol: @fixtures['update']['protocol'],
95
+ user: @fixtures['update']['user'],
96
+ port: @fixtures['update']['port'],
97
+ comment: @fixtures['update']['comment'],
98
+ }
99
+
100
+ sleep(1)
101
+ assert(item.update(data))
102
+
103
+ assert(!item.empty?)
104
+
105
+ assert_equal(@fixtures['update']['group'], item.group)
106
+ assert_equal(@fixtures['update']['host'], item.host)
107
+ assert_equal(@fixtures['update']['protocol'], item.protocol)
108
+ assert_equal(@fixtures['update']['user'], item.user)
109
+ assert_equal(@fixtures['update']['port'].to_i, item.port)
110
+ assert_equal(@fixtures['update']['comment'], item.comment)
111
+
112
+ assert_equal(created, item.created)
113
+ assert_not_equal(last_edit, item.last_edit)
114
+ end
115
+
116
+ def test_05_update_one_element
117
+ data = { group: @fixtures['add_new']['group'],
118
+ host: @fixtures['add_new']['host'],
119
+ protocol: @fixtures['add_new']['protocol'],
120
+ user: @fixtures['add_new']['user'],
121
+ port: @fixtures['add_new']['port'],
122
+ comment: @fixtures['add_new']['comment'],
123
+ }
124
+
125
+ item = MPW::Item.new(data)
126
+
127
+ assert(!item.nil?)
128
+ assert(!item.empty?)
129
+
130
+ last_edit = item.last_edit
131
+
132
+ sleep(1)
133
+ assert(item.update({comment: @fixtures['update']['comment']}))
134
+
135
+ assert_equal(@fixtures['add_new']['group'], item.group)
136
+ assert_equal(@fixtures['add_new']['host'], item.host)
137
+ assert_equal(@fixtures['add_new']['protocol'], item.protocol)
138
+ assert_equal(@fixtures['add_new']['user'], item.user)
139
+ assert_equal(@fixtures['add_new']['port'].to_i, item.port)
140
+ assert_equal(@fixtures['update']['comment'], item.comment)
141
+
142
+ assert_not_equal(last_edit, item.last_edit)
143
+ end
144
+
145
+ def test_05_delete
146
+ data = { group: @fixtures['add_new']['group'],
147
+ host: @fixtures['add_new']['host'],
148
+ protocol: @fixtures['add_new']['protocol'],
149
+ user: @fixtures['add_new']['user'],
150
+ port: @fixtures['add_new']['port'],
151
+ comment: @fixtures['add_new']['comment'],
152
+ }
153
+
154
+ item = MPW::Item.new(data)
155
+
156
+ assert(!item.nil?)
157
+ assert(!item.empty?)
158
+
159
+ item.delete
160
+ assert(!item.nil?)
161
+ assert(item.empty?)
162
+
163
+ assert_equal(nil, item.id)
164
+ assert_equal(nil, item.group)
165
+ assert_equal(nil, item.host)
166
+ assert_equal(nil, item.protocol)
167
+ assert_equal(nil, item.user)
168
+ assert_equal(nil, item.port)
169
+ assert_equal(nil, item.comment)
170
+ assert_equal(nil, item.created)
171
+ end
172
+ end