mpw 4.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +122 -0
- data/.travis.yml +2 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +7 -9
- data/README.md +1 -7
- data/VERSION +1 -1
- data/bin/mpw +25 -25
- data/bin/mpw-add +54 -25
- data/bin/mpw-config +74 -62
- data/bin/mpw-copy +25 -30
- data/bin/mpw-delete +24 -29
- data/bin/mpw-export +27 -32
- data/bin/mpw-genpwd +22 -22
- data/bin/mpw-import +20 -25
- data/bin/mpw-list +24 -29
- data/bin/mpw-update +61 -32
- data/bin/mpw-wallet +48 -73
- data/i18n/en.yml +15 -26
- data/i18n/fr.yml +15 -26
- data/lib/mpw/cli.rb +554 -546
- data/lib/mpw/config.rb +168 -139
- data/lib/mpw/item.rb +75 -82
- data/lib/mpw/mpw.rb +328 -465
- data/mpw.gemspec +11 -10
- data/templates/add_form.erb +8 -8
- data/templates/update_form.erb +7 -7
- data/test/test_config.rb +70 -55
- data/test/test_item.rb +167 -167
- data/test/test_mpw.rb +132 -132
- data/test/test_translate.rb +23 -23
- data/test/tests.rb +1 -1
- metadata +4 -45
- data/lib/mpw/sync/ftp.rb +0 -68
- data/lib/mpw/sync/ssh.rb +0 -67
data/mpw.gemspec
CHANGED
@@ -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 =
|
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.
|
21
|
-
|
22
|
-
spec.add_dependency
|
23
|
-
spec.add_dependency
|
24
|
-
spec.add_dependency
|
25
|
-
spec.add_dependency
|
26
|
-
spec.add_dependency
|
27
|
-
spec.add_dependency
|
28
|
-
spec.add_dependency
|
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
|
data/templates/add_form.erb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
---
|
2
|
-
host:
|
3
|
-
user:
|
4
|
-
group:
|
5
|
-
protocol:
|
6
|
-
password:
|
7
|
-
port:
|
8
|
-
comment:
|
9
|
-
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') %>
|
data/templates/update_form.erb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
---
|
2
2
|
# <%= I18n.t('form.update_item.host') %>
|
3
|
-
host:
|
3
|
+
host: <% if options[:host] %><%= options[:host] %><% else %><%= item.host %><% end %>
|
4
4
|
# <%= I18n.t('form.update_item.login') %>
|
5
|
-
user:
|
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:
|
9
|
+
group: <% if options[:group] %><%= options[:group] %><% else %><%= item.group %><% end %>
|
10
10
|
# <%= I18n.t('form.update_item.protocol') %>
|
11
|
-
protocol:
|
11
|
+
protocol: <% if options[:protocol] %><%= options[:protocol] %><% else %><%= item.protocol %><% end %>
|
12
12
|
# <%= I18n.t('form.update_item.port') %>
|
13
|
-
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:
|
17
|
+
comment: <% if options[:comment] %><%= options[:comment] %><% else %><%= item.comment %><% end %>
|
data/test/test_config.rb
CHANGED
@@ -6,59 +6,74 @@ require 'locale'
|
|
6
6
|
require 'i18n'
|
7
7
|
|
8
8
|
class TestConfig < Test::Unit::TestCase
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
data/test/test_item.rb
CHANGED
@@ -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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
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
|