to_pass 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.travis.yml +1 -0
- data/.vclog/rules.rb +35 -0
- data/.yardopts +6 -0
- data/Gemfile +14 -0
- data/README.rdoc +1 -1
- data/Rakefile +144 -0
- data/TODO +9 -23
- data/bin/password_of +1 -5
- data/bin/to_pass +1 -5
- data/data/to_pass/config +1 -1
- data/doc/CHANGELOG +209 -94
- data/lib/to_pass/algorithm_reader.rb +1 -1
- data/lib/to_pass/base.rb +2 -1
- data/lib/to_pass/cli.rb +41 -16
- data/lib/to_pass/directories.rb +31 -2
- data/lib/to_pass/file_reader.rb +2 -2
- data/lib/to_pass/version.rb +1 -1
- data/setup.rb +1368 -0
- data/test/fixtures/user_config +3 -0
- data/test/helper.rb +64 -9
- data/test/test_base.rb +8 -24
- data/test/test_cli.rb +66 -27
- data/test/test_configs.rb +11 -4
- data/test/test_directories.rb +48 -0
- data/test/tests.watchr +4 -1
- data/to_pass.gemspec +34 -0
- metadata +18 -6
data/test/helper.rb
CHANGED
@@ -4,6 +4,7 @@ require 'test/unit'
|
|
4
4
|
require 'mocha'
|
5
5
|
require 'rbconfig'
|
6
6
|
require 'pathname'
|
7
|
+
require 'fileutils'
|
7
8
|
|
8
9
|
# optional libraries
|
9
10
|
begin
|
@@ -46,23 +47,73 @@ Test::Unit::TestCase.class_eval do
|
|
46
47
|
|
47
48
|
def standard_directories
|
48
49
|
dirs = []
|
49
|
-
dirs << Pathname.new(
|
50
|
+
dirs << Pathname.new("#{user_dir}").expand_path # user
|
50
51
|
dirs << "#{ruby_data_dir}/#{ToPass::APP_NAME}" # installed
|
51
52
|
dirs << "#{File.dirname(__FILE__)}/../data/#{ToPass::APP_NAME}" if in_to_pass_soure_tree? # source [in github]
|
52
53
|
|
53
54
|
dirs
|
54
55
|
end
|
55
56
|
|
56
|
-
def with_algorithm_in_user_dir
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
def with_algorithm_in_user_dir(dir = "#{user_dir}/algorithms")
|
58
|
+
with_dir(dir) do
|
59
|
+
safe_copy(
|
60
|
+
"#{File.dirname(__FILE__)}/fixtures/user_alg.yml",
|
61
|
+
"#{dir}/user_alg.yml",
|
62
|
+
&Proc.new
|
63
|
+
)
|
64
|
+
end
|
60
65
|
end
|
61
|
-
|
62
66
|
def with_converters_in_user_dir
|
63
|
-
|
64
|
-
|
65
|
-
|
67
|
+
with_dir("#{user_dir}/converters") do
|
68
|
+
safe_copy(
|
69
|
+
"#{File.dirname(__FILE__)}/fixtures/user_converter.rb",
|
70
|
+
"#{user_dir}/converters/userize.rb",
|
71
|
+
&Proc.new
|
72
|
+
)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
def with_config_in_user_dir
|
76
|
+
with_dir("#{user_dir}") do
|
77
|
+
safe_copy(
|
78
|
+
"#{File.dirname(__FILE__)}/fixtures/user_config",
|
79
|
+
"#{user_dir}/config",
|
80
|
+
&Proc.new
|
81
|
+
)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
def without_config_user_dir
|
85
|
+
with_dir("#{user_dir}") do
|
86
|
+
safe_copy(
|
87
|
+
nil,
|
88
|
+
"#{user_dir}/config",
|
89
|
+
&Proc.new
|
90
|
+
)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def with_dir(dir)
|
95
|
+
FileUtils.mkpath("#{dir}")
|
96
|
+
|
97
|
+
result = yield
|
98
|
+
|
99
|
+
Dir.rmdir("#{dir}") if ( Dir.entries("#{dir}") == ['.', '..'] )
|
100
|
+
|
101
|
+
result
|
102
|
+
end
|
103
|
+
def safe_copy(source, target)
|
104
|
+
begin
|
105
|
+
target = File.expand_path(target)
|
106
|
+
backup = "#{target}.backup"
|
107
|
+
|
108
|
+
FileUtils.mv(target, backup) if File.exists?(target)
|
109
|
+
FileUtils.cp(source, target) unless source.nil?
|
110
|
+
|
111
|
+
yield
|
112
|
+
|
113
|
+
FileUtils.rm(target) unless source.nil?
|
114
|
+
ensure
|
115
|
+
FileUtils.mv(backup, target) if File.exists?(backup)
|
116
|
+
end
|
66
117
|
end
|
67
118
|
|
68
119
|
def in_to_pass_soure_tree?
|
@@ -72,6 +123,10 @@ Test::Unit::TestCase.class_eval do
|
|
72
123
|
def ruby_data_dir
|
73
124
|
RbConfig::CONFIG['data-dir'] || RbConfig::CONFIG['datadir']
|
74
125
|
end
|
126
|
+
|
127
|
+
def user_dir
|
128
|
+
ToPass::Directories[:user]
|
129
|
+
end
|
75
130
|
end
|
76
131
|
|
77
132
|
unless Pathname.new("#{File.dirname(__FILE__)}/../to_pass.gemspec").expand_path.exist?
|
data/test/test_base.rb
CHANGED
@@ -12,6 +12,14 @@ class TestBase < Test::Unit::TestCase
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
def test_options
|
16
|
+
with_dir('/tmp/my_to_pass') do
|
17
|
+
with_algorithm_in_user_dir('/tmp/my_to_pass/algorithms') do
|
18
|
+
assert_equal 'te/t', ToPass::Base.new('test', :user_alg, :path => Pathname.new('/tmp/my_to_pass').expand_path).to_s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
15
23
|
def test_version
|
16
24
|
assert_match /\d+.\d+.\d+/, ToPass::VERSION
|
17
25
|
end
|
@@ -36,23 +44,6 @@ class TestBase < Test::Unit::TestCase
|
|
36
44
|
end
|
37
45
|
end
|
38
46
|
|
39
|
-
def test_directories
|
40
|
-
dirs = ToPass::Directories
|
41
|
-
|
42
|
-
assert defined?(dirs)
|
43
|
-
assert_respond_to dirs, :[]
|
44
|
-
|
45
|
-
assert_equal '~/.to_pass', dirs[:user]
|
46
|
-
assert_equal "#{ruby_data_dir}/#{ToPass::APP_NAME}", dirs[:data]
|
47
|
-
|
48
|
-
if in_to_pass_soure_tree?
|
49
|
-
assert_equal Pathname.new("#{File.dirname(__FILE__)}/../").expand_path.to_s, dirs[:base]
|
50
|
-
assert_equal Pathname.new("#{File.dirname(__FILE__)}/../data/#{ToPass::APP_NAME}").expand_path.to_s, dirs[:source_data]
|
51
|
-
end
|
52
|
-
|
53
|
-
assert_equal [ dirs[:user], dirs[:data], dirs[:source_data] ], dirs[:standard]
|
54
|
-
end
|
55
|
-
|
56
47
|
def test_release_notes
|
57
48
|
fn = File.expand_path('../../doc/RELEASE_NOTES', __FILE__)
|
58
49
|
|
@@ -62,11 +53,4 @@ class TestBase < Test::Unit::TestCase
|
|
62
53
|
assert_nil ToPass::RELEASE_NOTES
|
63
54
|
end
|
64
55
|
end
|
65
|
-
|
66
|
-
# def test_uses_to_passrc_for_configuration
|
67
|
-
# assert_nothing_raised do
|
68
|
-
# # make default algorithm configurable in .to_passrc [kronn/to_pass GH-1]
|
69
|
-
# fail 'this needs to be implemeted'
|
70
|
-
# end
|
71
|
-
# end
|
72
56
|
end
|
data/test/test_cli.rb
CHANGED
@@ -6,14 +6,18 @@ class TestCli < Test::Unit::TestCase
|
|
6
6
|
test_presence ToPass::Cli
|
7
7
|
|
8
8
|
def test_cli_usage_without_algorithm
|
9
|
-
|
10
|
-
|
9
|
+
without_config_user_dir do
|
10
|
+
assert_nothing_raised do
|
11
|
+
assert_equal "$78bRkT5eT0n5Fk", `#{binpath}to_pass test`.chomp
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
16
|
def test_cli_usage_with_password_of
|
15
|
-
|
16
|
-
|
17
|
+
without_config_user_dir do
|
18
|
+
assert_nothing_raised do
|
19
|
+
assert_equal "$78bRkT5eT0n5Fk", `#{binpath}password_of test`.chomp
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
@@ -24,20 +28,26 @@ class TestCli < Test::Unit::TestCase
|
|
24
28
|
end
|
25
29
|
|
26
30
|
def test_cli_usage_with_pipes
|
27
|
-
|
28
|
-
|
31
|
+
without_config_user_dir do
|
32
|
+
assert_nothing_raised do
|
33
|
+
assert_equal '$78bRkT5eT0n5Fk', `echo "test" | #{binpath}to_pass`
|
34
|
+
end
|
29
35
|
end
|
30
36
|
end
|
31
37
|
|
32
38
|
def test_cli_usage_with_pipe_input
|
33
|
-
|
34
|
-
|
39
|
+
without_config_user_dir do
|
40
|
+
assert_nothing_raised do
|
41
|
+
assert_equal '$78bRkT5eT0n5Fk', `echo "test" | #{binpath}to_pass --no-pipe`.chomp
|
42
|
+
end
|
35
43
|
end
|
36
44
|
end
|
37
45
|
|
38
46
|
def test_cli_usage_with_pipe_output
|
39
|
-
|
40
|
-
|
47
|
+
without_config_user_dir do
|
48
|
+
assert_nothing_raised do
|
49
|
+
assert_equal '$78bRkT5eT0n5Fk', `#{binpath}to_pass test --pipe`
|
50
|
+
end
|
41
51
|
end
|
42
52
|
end
|
43
53
|
|
@@ -73,24 +83,53 @@ class TestCli < Test::Unit::TestCase
|
|
73
83
|
assert_match /Show this message/, result, 'should contain hint for help'
|
74
84
|
end
|
75
85
|
|
86
|
+
def test_cli_usage_with_user_config
|
87
|
+
with_algorithm_in_user_dir do
|
88
|
+
with_config_in_user_dir do
|
89
|
+
assert_equal "le1/2%z", `#{binpath}to_pass 'leasbpc'`.chomp
|
90
|
+
assert_equal "le1/2%z", `#{binpath}to_pass 'luke eats all sausagages because peter cries'`.chomp
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_configuration_path_is_configurable
|
96
|
+
FileUtils.rm_r('/tmp/my_to_pass', :force => true, :secure => true)
|
76
97
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
98
|
+
[
|
99
|
+
`#{binpath}to_pass test -c /tmp/my_to_pass`,
|
100
|
+
`#{binpath}to_pass test --config /tmp/my_to_pass`
|
101
|
+
].each do |result|
|
102
|
+
assert_match /configuration path not found/, result, 'should output an errormessage'
|
103
|
+
assert_match %r!to_pass --setup /tmp/my_to_pass!, result, 'should provide a hint how to fix it'
|
104
|
+
end
|
105
|
+
|
106
|
+
with_algorithm_in_user_dir('/tmp/my_to_pass/algorithms') do
|
107
|
+
assert_equal 'te/t', `#{binpath}to_pass test -c /tmp/my_to_pass -a user_alg`.chomp
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_cli_has_setup_command
|
112
|
+
path = Pathname.new('/tmp/my_to_pass')
|
113
|
+
|
114
|
+
FileUtils.rm_r(path, :force => true, :secure => true)
|
115
|
+
|
116
|
+
assert !path.exist?
|
117
|
+
|
118
|
+
assert_match /successfully created configuration directory in #{path}/i,
|
119
|
+
`#{binpath}to_pass --setup #{path} 2>&1`,
|
120
|
+
'should print success message'
|
121
|
+
|
122
|
+
assert path.exist?
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_cli_has_setup_command_with_default
|
126
|
+
with_config_in_user_dir do
|
127
|
+
dir = Pathname.new(user_dir).expand_path
|
128
|
+
result = `#{binpath}to_pass --setup 2>&1`
|
129
|
+
assert_match /configuration in #{dir} not overwritten/, result
|
130
|
+
assert_match /successfully created configuration directory in #{dir}/i, result, 'should print success message'
|
131
|
+
end
|
132
|
+
end
|
94
133
|
|
95
134
|
def test_cli_can_output_algorithms
|
96
135
|
algorithms = %w(basic_de basic_en secure)
|
data/test/test_configs.rb
CHANGED
@@ -4,14 +4,22 @@ require File.expand_path('../helper', __FILE__)
|
|
4
4
|
|
5
5
|
class TestConfigs < Test::Unit::TestCase
|
6
6
|
def config
|
7
|
-
|
7
|
+
@config ||= begin
|
8
|
+
@config = nil
|
9
|
+
|
10
|
+
without_config_user_dir do
|
11
|
+
@config = ToPass::ConfigReader.load('config')
|
12
|
+
end
|
13
|
+
|
14
|
+
@config
|
15
|
+
end
|
8
16
|
end
|
9
17
|
|
10
|
-
def
|
18
|
+
def test_default_algorithm_is_secure
|
11
19
|
result = config[:algorithm]
|
12
20
|
|
13
21
|
assert_not_nil result, 'the algorithm should be configured by default'
|
14
|
-
assert_equal :
|
22
|
+
assert_equal :secure, result
|
15
23
|
end
|
16
24
|
def test_default_pipe_out_behaviour_is_false
|
17
25
|
result = config[:pipe_out]
|
@@ -25,5 +33,4 @@ class TestConfigs < Test::Unit::TestCase
|
|
25
33
|
assert_not_nil result
|
26
34
|
assert_equal false, result
|
27
35
|
end
|
28
|
-
|
29
36
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# vim:ft=ruby:fileencoding=utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../helper', __FILE__)
|
4
|
+
|
5
|
+
class TestDirectories < Test::Unit::TestCase
|
6
|
+
test_presence ToPass::Directories
|
7
|
+
|
8
|
+
def test_directories
|
9
|
+
assert_respond_to dirs, :[]
|
10
|
+
|
11
|
+
assert_equal '~/.to_pass', dirs[:user]
|
12
|
+
assert_equal "#{ruby_data_dir}/#{ToPass::APP_NAME}", dirs[:data]
|
13
|
+
|
14
|
+
if in_to_pass_soure_tree?
|
15
|
+
assert_equal Pathname.new("#{File.dirname(__FILE__)}/../").expand_path.to_s, dirs[:base]
|
16
|
+
assert_equal Pathname.new("#{File.dirname(__FILE__)}/../data/#{ToPass::APP_NAME}").expand_path.to_s, dirs[:source_data]
|
17
|
+
end
|
18
|
+
|
19
|
+
assert_equal [ dirs[:user], dirs[:data], dirs[:source_data] ], dirs[:standard]
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_directories_can_be_extended
|
23
|
+
assert_respond_to dirs, :[]=
|
24
|
+
|
25
|
+
new_dir = Pathname.new('/tmp/my_to_pass')
|
26
|
+
|
27
|
+
assert_equal new_dir, ( dirs[:new] = new_dir )
|
28
|
+
assert_include new_dir, dirs
|
29
|
+
assert_equal new_dir, dirs[:new]
|
30
|
+
|
31
|
+
assert_include new_dir, dirs[:all]
|
32
|
+
assert_equal new_dir, dirs[:all].first
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_directories_can_be_searched
|
36
|
+
assert_respond_to dirs, :include?
|
37
|
+
|
38
|
+
# assert_include(needle, haystack[, msg]) uses include? to verify.
|
39
|
+
assert_include :user, dirs
|
40
|
+
assert_include '~/.to_pass', dirs
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def dirs
|
46
|
+
ToPass::Directories
|
47
|
+
end
|
48
|
+
end
|
data/test/tests.watchr
CHANGED
@@ -29,9 +29,12 @@ single_test = lambda { |m|
|
|
29
29
|
watch '^data/to_pass/(algorithms|converters)/*.rb' do |m|
|
30
30
|
single_or_all("test/test_#{m[1]}.rb")
|
31
31
|
end
|
32
|
-
watch '^data/config' do |m|
|
32
|
+
watch '^data/to_pass/config' do |m|
|
33
33
|
single_or_all("test/test_configs.rb")
|
34
34
|
end
|
35
|
+
watch '^test/(helper|all).rb' do |m|
|
36
|
+
run_all
|
37
|
+
end
|
35
38
|
|
36
39
|
# simple mappings
|
37
40
|
watch '^lib/to_pass/(.*).rb', &single_test
|
data/to_pass.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# vim:ft=ruby:fileencoding=utf-8
|
2
|
+
|
3
|
+
require File.expand_path('../lib/to_pass/version.rb', __FILE__)
|
4
|
+
|
5
|
+
spec = Gem::Specification.new do |s|
|
6
|
+
s.name = ToPass::APP_NAME
|
7
|
+
s.version = ToPass::VERSION
|
8
|
+
s.date = ToPass::DATE
|
9
|
+
s.summary = ToPass::SUMMARY
|
10
|
+
s.description = ToPass::DESCRIPTION
|
11
|
+
|
12
|
+
s.authors = ["Matthias Viehweger"]
|
13
|
+
s.email = 'kronn@kronn.de'
|
14
|
+
s.homepage = 'http://github.com/kronn/to_pass'
|
15
|
+
s.rubyforge_project = '[none]' # to supress the warning
|
16
|
+
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.executables = ["password_of", "to_pass"]
|
19
|
+
s.files = `git ls-files`.split("\n") - ['.gitignore']
|
20
|
+
s.test_files = `git ls-files test`.split("\n")
|
21
|
+
|
22
|
+
s.has_rdoc = true
|
23
|
+
s.rdoc_options = ['--charset=utf-8', '--fmt=shtml', '--all', '--include=data/to_pass/converters/']
|
24
|
+
s.extra_rdoc_files = ToPass::EXTRA_RDOC_FILES
|
25
|
+
s.post_install_message = ToPass::RELEASE_NOTES
|
26
|
+
|
27
|
+
|
28
|
+
# for tests, needed
|
29
|
+
s.add_development_dependency 'mocha'
|
30
|
+
|
31
|
+
# for release and doc generation, more less optional
|
32
|
+
s.add_development_dependency 'ronn'
|
33
|
+
s.add_development_dependency 'sdoc'
|
34
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to_pass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
- 9
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matthias Viehweger
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-15 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -73,6 +73,14 @@ extra_rdoc_files:
|
|
73
73
|
- README.rdoc
|
74
74
|
- TODO
|
75
75
|
files:
|
76
|
+
- .gemtest
|
77
|
+
- .travis.yml
|
78
|
+
- .vclog/rules.rb
|
79
|
+
- .yardopts
|
80
|
+
- Gemfile
|
81
|
+
- README.rdoc
|
82
|
+
- Rakefile
|
83
|
+
- TODO
|
76
84
|
- bin/password_of
|
77
85
|
- bin/to_pass
|
78
86
|
- data/to_pass/algorithms/basic_de.yml
|
@@ -111,8 +119,10 @@ files:
|
|
111
119
|
- man/to_pass-algorithm.5.ronn
|
112
120
|
- man/to_pass-converter.5.ronn
|
113
121
|
- man/to_pass.1.ronn
|
122
|
+
- setup.rb
|
114
123
|
- test/all.rb
|
115
124
|
- test/fixtures/user_alg.yml
|
125
|
+
- test/fixtures/user_config
|
116
126
|
- test/fixtures/user_converter.rb
|
117
127
|
- test/helper.rb
|
118
128
|
- test/test_algorithm_reader.rb
|
@@ -124,11 +134,11 @@ files:
|
|
124
134
|
- test/test_converter.rb
|
125
135
|
- test/test_converter_reader.rb
|
126
136
|
- test/test_converters.rb
|
137
|
+
- test/test_directories.rb
|
127
138
|
- test/test_file_reader.rb
|
128
139
|
- test/test_integration.rb
|
129
140
|
- test/tests.watchr
|
130
|
-
-
|
131
|
-
- TODO
|
141
|
+
- to_pass.gemspec
|
132
142
|
has_rdoc: true
|
133
143
|
homepage: http://github.com/kronn/to_pass
|
134
144
|
licenses: []
|
@@ -169,6 +179,7 @@ summary: generate password from words or sentences
|
|
169
179
|
test_files:
|
170
180
|
- test/all.rb
|
171
181
|
- test/fixtures/user_alg.yml
|
182
|
+
- test/fixtures/user_config
|
172
183
|
- test/fixtures/user_converter.rb
|
173
184
|
- test/helper.rb
|
174
185
|
- test/test_algorithm_reader.rb
|
@@ -180,6 +191,7 @@ test_files:
|
|
180
191
|
- test/test_converter.rb
|
181
192
|
- test/test_converter_reader.rb
|
182
193
|
- test/test_converters.rb
|
194
|
+
- test/test_directories.rb
|
183
195
|
- test/test_file_reader.rb
|
184
196
|
- test/test_integration.rb
|
185
197
|
- test/tests.watchr
|