pog19 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,209 @@
1
+ # Copyright (c) 2007 Operis Systems, LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ require 'test/unit'
15
+ require File.join( File.dirname(__FILE__), '..', 'lib', 'pog.rb' )
16
+
17
+ class TC_PasswordTests < Test::Unit::TestCase
18
+ def test_length
19
+ tests = get_password_tests({ :bad => 'fubar', :good => 'foobar', :extra_good => 'foobar0' },
20
+ { :test_length => 6 })
21
+
22
+ make_assertions_on_tests tests, :test_length
23
+ end
24
+
25
+ def test_minimum_alphas
26
+ tests = get_password_tests({ :bad => 'f00', :good => 'fo0', :extra_good => 'foo' },
27
+ { :test_minimum_alphas => 2 })
28
+
29
+ make_assertions_on_tests tests, :test_minimum_alphas
30
+ end
31
+
32
+ def test_maximum_alphas
33
+ tests = get_password_tests({ :bad => 'foo', :good => 'fo0', :extra_good => 'f00' },
34
+ { :test_maximum_alphas => 2 })
35
+
36
+ make_assertions_on_tests tests, :test_maximum_alphas
37
+ end
38
+
39
+ def test_minimum_upper_alphas
40
+ tests = get_password_tests({ :bad => 'Foo', :good => 'FOo', :extra_good => 'FOO' },
41
+ { :test_minimum_upper_alphas => 2 })
42
+
43
+ make_assertions_on_tests tests, :test_minimum_upper_alphas
44
+ end
45
+
46
+ def test_maximum_upper_alphas
47
+ tests = get_password_tests({ :bad => 'FOO', :good => 'FOo', :extra_good => 'Foo' },
48
+ { :test_maximum_upper_alphas => 2 })
49
+
50
+ make_assertions_on_tests tests, :test_maximum_upper_alphas
51
+ end
52
+
53
+ def test_minimum_lower_alphas
54
+ tests = get_password_tests({ :bad => 'FOo', :good => 'Foo', :extra_good => 'foo' },
55
+ { :test_minimum_lower_alphas => 2 })
56
+
57
+ make_assertions_on_tests tests, :test_minimum_lower_alphas
58
+ end
59
+
60
+ def test_maximum_lower_alphas
61
+ tests = get_password_tests({ :bad => 'foo', :good => 'Foo', :extra_good => 'FOo' },
62
+ { :test_maximum_lower_alphas => 2 })
63
+
64
+ make_assertions_on_tests tests, :test_maximum_lower_alphas
65
+ end
66
+
67
+ def test_minimum_numerals
68
+ tests = get_password_tests({ :bad => 'fo0', :good => 'f00', :extra_good => '000' },
69
+ { :test_minimum_numerals => 2 })
70
+
71
+ make_assertions_on_tests tests, :test_minimum_numerals
72
+ end
73
+
74
+ def test_maximum_numerals
75
+ tests = get_password_tests({ :bad => '000', :good => 'f00', :extra_good => 'fo0' },
76
+ { :test_maximum_numerals => 2 })
77
+
78
+ make_assertions_on_tests tests, :test_maximum_numerals
79
+ end
80
+
81
+ def test_minimum_non_alphanumeric
82
+ tests = get_password_tests({ :bad => 'fo@', :good => 'f@@', :extra_good => '@@@' },
83
+ { :test_minimum_non_alphanumeric => 2 })
84
+
85
+ make_assertions_on_tests tests, :test_minimum_non_alphanumeric
86
+ end
87
+
88
+ def test_maximum_non_alphanumeric
89
+ tests = get_password_tests({ :bad => '@@@', :good => 'f@@', :extra_good => 'fo@' },
90
+ { :test_maximum_non_alphanumeric => 2 })
91
+
92
+ make_assertions_on_tests tests, :test_maximum_non_alphanumeric
93
+ end
94
+
95
+ def test_maximum_non_alpha
96
+ tests = get_password_tests({ :bad => '@@@', :good => 'f@@', :extra_good => 'fo@' },
97
+ { :test_maximum_non_alpha => 2 })
98
+
99
+ make_assertions_on_tests tests, :test_maximum_non_alpha
100
+ end
101
+
102
+ def test_minimum_non_alpha
103
+ tests = get_password_tests({ :bad => 'foo', :good => 'f@@', :extra_good => 'fo@b#$' },
104
+ { :test_minimum_non_alpha => 2 })
105
+
106
+ make_assertions_on_tests tests, :test_minimum_non_alpha
107
+ end
108
+
109
+ def test_run
110
+ tests = PasswordTests.new( 'FooBar', :test_length => 8,
111
+ :test_minimum_alphas => 2 )
112
+
113
+ assert_equal({ :test_length => false,
114
+ :test_minimum_alphas => true }, tests.run)
115
+ end
116
+
117
+ def test_repetitions
118
+ assert PasswordTests.repetitions('fobar').empty?
119
+
120
+ assert_equal( {'o'=>1},
121
+ PasswordTests.repetitions('foobar') )
122
+
123
+ assert_equal( {'o'=>3, 'oo'=>1},
124
+ PasswordTests.repetitions('fooboo') )
125
+
126
+ assert_equal( {'f' => 1, 'o'=>3, 'oo'=>1, 'foo'=>1},
127
+ PasswordTests.repetitions('foofoo') )
128
+ end
129
+
130
+ def test_qualitative_strength
131
+ assert_operator 0, :== , PasswordTests.qualitative_strength( '123456' )
132
+
133
+ assert_operator 0, :== , PasswordTests.qualitative_strength( 'foo' )
134
+
135
+ assert_operator 0, :<= , PasswordTests.qualitative_strength( 'fooo' )
136
+ end
137
+
138
+ def test_entropy
139
+ assert_operator 3.3, :< , PasswordTests.entropy( '1' )
140
+
141
+ assert_operator 4.7, :< , PasswordTests.entropy( 'f' )
142
+
143
+ assert_operator 5.0, :< ,PasswordTests.entropy( '$' )
144
+
145
+ assert_operator 6.6, :< ,PasswordTests.entropy( '12' )
146
+ end
147
+
148
+ def test_default_levels
149
+ # low
150
+ assert_equal({:test_length=>true, :test_minimum_alphas=>false}, PasswordTests.new('123456', :low).run)
151
+ assert_equal({:test_length=>true, :test_minimum_alphas=>true}, PasswordTests.new('f123456', :low).run)
152
+ assert_equal({:test_length=>true, :test_minimum_alphas=>true}, PasswordTests.new('fo0bar', :low).run)
153
+
154
+ # medium-low
155
+ assert_equal({:test_length=>true, :test_minimum_non_alpha=>false, :test_minimum_alphas=>true},
156
+ PasswordTests.new('abcdefgh', :medium_low).run)
157
+ assert_equal({:test_length=>true, :test_minimum_non_alpha=>true, :test_minimum_alphas=>true},
158
+ PasswordTests.new('abcdefgh0', :medium_low).run)
159
+ assert_equal({:test_length=>true, :test_minimum_non_alpha=>true, :test_minimum_alphas=>true},
160
+ PasswordTests.new('fo0barf00', :medium_low).run)
161
+
162
+ # medium-high
163
+ assert_equal({:test_length=>true, :test_minimum_upper_alphas=>false, :test_minimum_non_alpha=>false, :test_minimum_lower_alphas=>true},
164
+ PasswordTests.new('abcdefgh', :medium_high).run)
165
+ assert_equal({:test_length=>true, :test_minimum_upper_alphas=>true, :test_minimum_non_alpha=>true, :test_minimum_lower_alphas=>true},
166
+ PasswordTests.new('Abcdefgh0', :medium_high).run)
167
+ assert_equal({:test_length=>true, :test_minimum_upper_alphas=>true, :test_minimum_non_alpha=>true, :test_minimum_lower_alphas=>true},
168
+ PasswordTests.new('fo0barF00', :medium_high).run)
169
+
170
+ # The default level should be medium_low
171
+ assert_equal({:test_length=>true, :test_minimum_non_alpha=>false, :test_minimum_alphas=>true}, PasswordTests.new('abcdefgh').run)
172
+ assert_equal({:test_length=>true, :test_minimum_non_alpha=>true, :test_minimum_alphas=>true}, PasswordTests.new('abcdefgh0').run)
173
+ assert_equal({:test_length=>true, :test_minimum_non_alpha=>true, :test_minimum_alphas=>true}, PasswordTests.new('fo0barf00').run)
174
+
175
+ # high
176
+ assert_equal({:test_minimum_numerals=>false, :test_length=>true, :test_minimum_upper_alphas=>false, :test_minimum_lower_alphas=>true,
177
+ :test_minimum_non_alphanumeric=>false}, PasswordTests.new('abcdefgh', :high).run)
178
+ assert_equal({:test_minimum_numerals=>true, :test_length=>true, :test_minimum_upper_alphas=>true, :test_minimum_lower_alphas=>true,
179
+ :test_minimum_non_alphanumeric=>true}, PasswordTests.new('Abcdefgh0#', :high).run)
180
+ assert_equal({:test_minimum_numerals=>true, :test_length=>true, :test_minimum_upper_alphas=>true, :test_minimum_lower_alphas=>true,
181
+ :test_minimum_non_alphanumeric=>true}, PasswordTests.new('fo0barF##', :high).run)
182
+
183
+ # invalid level
184
+ assert_raise(RuntimeError) { PasswordTests.new('fooey', :foobar) }
185
+ end
186
+
187
+ private
188
+
189
+ ##
190
+ # Gets a hash of PasswordTests classes for each of the given passwords in the
191
+ # test_password_hash with the given test_hash
192
+ #
193
+ def get_password_tests( test_password_hash , test_hash )
194
+ tests = Hash.new { |hash, key|
195
+ hash[key] = PasswordTests.new( test_password_hash[key], test_hash ) }
196
+ test_password_hash.each_key { |name| tests[name] }
197
+ return tests
198
+ end
199
+
200
+ ##
201
+ # Executes the given method on the cases :bad, :good, and :extra_good and
202
+ # asserts that :bad is false, and :good and :extra_good are true
203
+ #
204
+ def make_assertions_on_tests( tests, method )
205
+ assert_equal false, tests[:bad].__send__( method )
206
+ assert_equal true, tests[:good].__send__( method )
207
+ assert_equal true, tests[:extra_good].__send__( method )
208
+ end
209
+ end
@@ -0,0 +1,133 @@
1
+ # Copyright (c) 2007 Operis Systems, LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ require 'test/unit'
15
+ require File.join( File.dirname(__FILE__), '..', 'lib', 'pog.rb' )
16
+
17
+ class TC_PasswordTests < Test::Unit::TestCase
18
+ def test_shuffle_string
19
+ str = "qwertyuiopQWERTYUIOP"
20
+ str_freq = frequencies(str)
21
+ str_2 = RandomStringGenerator.shuffle_string str
22
+ assert_not_equal str_2, str
23
+ assert_equal frequencies(str_2), frequencies(str)
24
+ end
25
+
26
+ def frequencies( str )
27
+ r = {}
28
+ for i in 0...str.length do
29
+ c = str[i]
30
+ if r[c]
31
+ r[c] += 1
32
+ else
33
+ r[c] = 1
34
+ end
35
+ end
36
+ end
37
+
38
+ def test_rand_char
39
+ rsg = RandomStringGenerator.new
40
+ rsg.set_characters_array
41
+ assert_not_nil rsg.rand_char
42
+ end
43
+
44
+ def test_rand_char_with_delete
45
+ rsg = RandomStringGenerator.new(2, :special => 'abd')
46
+ rsg.set_characters_array
47
+ 3.times do
48
+ assert_not_nil rsg.rand_char( true )
49
+ end
50
+
51
+ rsg = RandomStringGenerator.new(2, :special => 'abd')
52
+ rsg.set_characters_array
53
+ 3.times do
54
+ assert_nothing_raised { rsg.rand_char( true ) }
55
+ end
56
+ assert_raise RuntimeError do
57
+ rsg.rand_char( true )
58
+ end
59
+ end
60
+
61
+ def test_noduplicates_safety
62
+ rsg = RandomStringGenerator.new(3, :special => 'ab', :no_duplicates => true)
63
+ assert_raise RuntimeError do
64
+ rsg.generate
65
+ end
66
+ end
67
+
68
+ def test_generation
69
+ rsg = RandomStringGenerator.new
70
+ assert_not_nil rsg.generate
71
+
72
+ rsg.set_option :single_quotes => true, :double_quotes => true, :backtick => true
73
+
74
+ assert_not_nil rsg.generate
75
+ assert_equal rsg.generate.length, 8
76
+
77
+ rsg = RandomStringGenerator.new(9, :all => true)
78
+
79
+ assert_not_nil rsg.generate
80
+ assert_equal rsg.generate.length, 9
81
+
82
+ rsg = RandomStringGenerator.new(10, :all_except_quotes => true)
83
+
84
+ assert_not_nil rsg.generate
85
+ assert_equal rsg.generate.length, 10
86
+
87
+ rsg.set_option :special => 5
88
+ assert_raise(ArgumentError) { rsg.set_characters_array }
89
+ end
90
+
91
+ def test_bad_range
92
+ rsg = RandomStringGenerator.new
93
+ assert_raise(ArgumentError) { rsg.range('foo') }
94
+ end
95
+
96
+ def test_wep_generation
97
+ ascii64_wep = RandomStringGenerator.generate_wep(64,:ascii)
98
+ ascii128_wep = RandomStringGenerator.generate_wep(128,:ascii)
99
+ hex152_wep = RandomStringGenerator.generate_wep(152)
100
+ hex256_wep = RandomStringGenerator.generate_wep(256)
101
+
102
+ assert_not_nil ascii64_wep
103
+ assert_not_nil ascii128_wep
104
+ assert_not_nil hex152_wep
105
+ assert_not_nil hex256_wep
106
+
107
+ assert_equal ascii64_wep.length, 5
108
+ assert_equal ascii128_wep.length, 13
109
+ assert_equal hex152_wep.length, 32
110
+ assert_equal hex256_wep.length, 58
111
+
112
+ assert_raise(RuntimeError) { RandomStringGenerator.generate_wep(152, :not_a_type) }
113
+ end
114
+
115
+ def test_attrs
116
+ rsg = RandomStringGenerator.new
117
+
118
+ assert_equal rsg.length, 8
119
+ rsg.length = 7
120
+ assert_equal rsg.length, 7
121
+
122
+ assert_equal rsg.options, {:lower_alphas => true,
123
+ :upper_alphas => true,
124
+ :numerals => true,
125
+ :no_duplicates=> false }
126
+ rsg.set_option :symbols => false, :no_duplicates=> true
127
+ assert_equal rsg.options, {:lower_alphas => true,
128
+ :upper_alphas => true,
129
+ :numerals => true,
130
+ :no_duplicates=> true,
131
+ :symbols => false }
132
+ end
133
+ end
data/test/tc_salt.rb ADDED
@@ -0,0 +1,78 @@
1
+ # Copyright (c) 2007 Operis Systems, LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ require 'test/unit'
15
+ require 'base64'
16
+ require File.join( File.dirname(__FILE__), '..', 'lib', 'pog.rb' )
17
+
18
+ TEST_PASS = '/O0op;G75wu3saMv|N9&DA?I*/!3-gqHUe9{VZL{M3YVoYUQ]6q{]Poz%c)V#T,i=g.G8>&'
19
+ TEST_SALT = 'foobar'
20
+
21
+ class TC_Salt < Test::Unit::TestCase
22
+
23
+ def test_new
24
+ salt = Salt.new( TEST_SALT )
25
+ assert_equal :end, salt.placement
26
+
27
+ salt = Salt.new( TEST_SALT, :beginning )
28
+ assert_equal :beginning, salt.placement
29
+
30
+ salt = Salt.new( :new, :end, :length => 8 )
31
+ assert_not_nil salt.string
32
+ assert_equal 8, salt.string.length
33
+ assert_equal :end, salt.placement
34
+ end
35
+
36
+ def test_generate_str
37
+ for len in -32..32
38
+ salt = Salt.generate_str( len )
39
+ assert salt.length == (len >= 0 ? len : 0), "test_generate_salt failed for length #{len}"
40
+ end
41
+ end
42
+
43
+ def test_salt_password
44
+ salt = Salt.new( TEST_SALT, :beginning )
45
+ assert_equal TEST_SALT + TEST_PASS,
46
+ salt.salt_password( TEST_PASS ),
47
+ "test_salt_password failed for beginning"
48
+
49
+ salt = Salt.new( TEST_SALT, :end )
50
+ assert_equal TEST_PASS + TEST_SALT,
51
+ salt.salt_password( TEST_PASS ),
52
+ "test_salt_password failed for end"
53
+
54
+ salt = Salt.new( "foobar", :split )
55
+ assert_equal 'foo' + TEST_PASS + 'bar',
56
+ salt.salt_password( TEST_PASS ),
57
+ "test_salt_password failed for even split"
58
+
59
+ salt = Salt.new( 'fooba', :split )
60
+ assert_equal 'fo' + TEST_PASS + 'oba',
61
+ salt.salt_password( TEST_PASS ),
62
+ "test_salt_password failed for odd split"
63
+
64
+ end
65
+
66
+ def test_setters
67
+ salt = Salt.new
68
+ salt.string = TEST_SALT
69
+ assert_equal salt.string, TEST_SALT
70
+
71
+ salt.placement = 'foo'
72
+ assert_equal salt.placement, :foo
73
+
74
+ assert_raise RuntimeError do
75
+ salt.salt_password 'foo'
76
+ end
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pog19
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 1
8
+ - 1
9
+ version: 1.1.1
10
+ platform: ruby
11
+ authors:
12
+ - Operis Systems, LLC
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-06 00:00:00 -08:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: A Ruby gem for simplifying random password generation, password strength testing, password hashing and salting, and password-hash authentication.
22
+ email: ""
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - CHANGELOG
31
+ - lib/character_ranges.rb
32
+ - lib/encoding_translation.rb
33
+ - lib/password.rb
34
+ - lib/password_tests.rb
35
+ - lib/pog.rb
36
+ - lib/random_string_generator.rb
37
+ - lib/salt.rb
38
+ - lib/string.rb
39
+ - LICENSE
40
+ - NOTICE
41
+ - pog1-9.gemspec
42
+ - Rakefile
43
+ - README
44
+ - SECURITY
45
+ - test/tc_password.rb
46
+ - test/tc_password_tests.rb
47
+ - test/tc_random_string_generator.rb
48
+ - test/tc_salt.rb
49
+ - VERSION
50
+ has_rdoc: true
51
+ homepage: http://pog.rubyforge.org/
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --all
57
+ - --inline-source
58
+ - --main
59
+ - lib/*.rb
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ requirements: []
77
+
78
+ rubyforge_project: pog
79
+ rubygems_version: 1.3.6
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: A Ruby gem for simplifying random password generation
83
+ test_files: []
84
+