encrypted_strings 0.1.1 → 0.2.0
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.
- data/CHANGELOG.rdoc +8 -0
- data/README.rdoc +23 -23
- data/Rakefile +1 -1
- data/lib/encrypted_strings/{asymmetric_encryptor.rb → asymmetric_cipher.rb} +30 -37
- data/lib/encrypted_strings/{encryptor.rb → cipher.rb} +3 -3
- data/lib/encrypted_strings/extensions/string.rb +49 -40
- data/lib/encrypted_strings/{sha_encryptor.rb → sha_cipher.rb} +13 -11
- data/lib/encrypted_strings/symmetric_cipher.rb +102 -0
- data/lib/encrypted_strings.rb +4 -4
- data/test/asymmetric_cipher_test.rb +183 -0
- data/test/cipher_test.rb +15 -0
- data/test/keys/encrypted_private +12 -12
- data/test/sha_cipher_test.rb +81 -0
- data/test/string_test.rb +22 -22
- data/test/symmetric_cipher_test.rb +99 -0
- metadata +13 -23
- data/lib/encrypted_strings/no_key_error.rb +0 -7
- data/lib/encrypted_strings/no_private_key_error.rb +0 -7
- data/lib/encrypted_strings/no_public_key_error.rb +0 -7
- data/lib/encrypted_strings/symmetric_encryptor.rb +0 -134
- data/test/asymmetric_encryptor_test.rb +0 -194
- data/test/encryptor_test.rb +0 -15
- data/test/keys/pkcs5_encrypted_private +0 -12
- data/test/no_key_error_test.rb +0 -7
- data/test/no_private_key_error_test.rb +0 -7
- data/test/no_public_key_error_test.rb +0 -7
- data/test/sha_encryptor_test.rb +0 -81
- data/test/symmetric_encryptor_test.rb +0 -137
@@ -1,194 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class AsymmetricEncryptorByDefaultTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:public_key_file => File.dirname(__FILE__) + '/keys/public')
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_should_raise_an_exception
|
9
|
-
assert_raise(ArgumentError) {PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new}
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_should_not_have_a_public_key_file
|
13
|
-
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:private_key_file => File.dirname(__FILE__) + '/keys/private')
|
14
|
-
assert_nil @asymmetric_encryptor.public_key_file
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_should_not_have_a_private_key_file
|
18
|
-
assert_nil @asymmetric_encryptor.private_key_file
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_should_not_have_an_algorithm
|
22
|
-
assert_nil @asymmetric_encryptor.algorithm
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_should_not_have_a_password
|
26
|
-
assert_nil @asymmetric_encryptor.password
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class AsymmetricEncryptorWithCustomDefaultsTest < Test::Unit::TestCase
|
31
|
-
def setup
|
32
|
-
@original_default_public_key_file = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_public_key_file
|
33
|
-
@original_default_private_key_file = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_private_key_file
|
34
|
-
@original_default_algorithm = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_algorithm
|
35
|
-
|
36
|
-
PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_public_key_file = File.dirname(__FILE__) + '/keys/public'
|
37
|
-
PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_private_key_file = File.dirname(__FILE__) + '/keys/private'
|
38
|
-
PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_algorithm = 'DES-EDE3-CBC'
|
39
|
-
|
40
|
-
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_should_use_default_public_key_file
|
44
|
-
assert_equal File.dirname(__FILE__) + '/keys/public', @asymmetric_encryptor.public_key_file
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_should_use_default_private_key_file
|
48
|
-
assert_equal File.dirname(__FILE__) + '/keys/private', @asymmetric_encryptor.private_key_file
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_should_use_the_default_algorithm
|
52
|
-
assert_equal 'DES-EDE3-CBC', @asymmetric_encryptor.algorithm
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_should_not_have_a_password
|
56
|
-
assert_nil @asymmetric_encryptor.password
|
57
|
-
end
|
58
|
-
|
59
|
-
def teardown
|
60
|
-
PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_public_key_file = @original_default_public_key_file
|
61
|
-
PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_private_key_file = @original_default_private_key_file
|
62
|
-
PluginAWeek::EncryptedStrings::AsymmetricEncryptor.default_algorithm = @original_default_algorithm
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
class AsymmetricEncryptorWithInvalidOptionsTest < Test::Unit::TestCase
|
67
|
-
def test_should_throw_an_exception
|
68
|
-
assert_raise(ArgumentError) {PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:invalid => true)}
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
class AsymmetricEncryptorTest < Test::Unit::TestCase
|
73
|
-
def setup
|
74
|
-
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:public_key_file => File.dirname(__FILE__) + '/keys/public')
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_should_be_able_to_decrypt
|
78
|
-
assert @asymmetric_encryptor.can_decrypt?
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
class AsymmetricEncryptorWithoutPublicKeyTest < Test::Unit::TestCase
|
83
|
-
def setup
|
84
|
-
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:public_key_file => nil, :private_key_file => File.dirname(__FILE__) + '/keys/private')
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_should_not_be_public
|
88
|
-
assert !@asymmetric_encryptor.public?
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_should_not_be_able_to_encrypt
|
92
|
-
assert_raise(PluginAWeek::EncryptedStrings::NoPublicKeyError) {@asymmetric_encryptor.encrypt('test')}
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
class AsymmetricEncryptorWithPublicKeyTest < Test::Unit::TestCase
|
97
|
-
def setup
|
98
|
-
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:public_key_file => File.dirname(__FILE__) + '/keys/public')
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_should_be_public
|
102
|
-
assert @asymmetric_encryptor.public?
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_should_not_be_private
|
106
|
-
assert !@asymmetric_encryptor.private?
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_should_be_able_to_encrypt
|
110
|
-
assert_equal 90, @asymmetric_encryptor.encrypt('test').length
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_should_not_be_able_to_decrypt
|
114
|
-
assert_raise(PluginAWeek::EncryptedStrings::NoPrivateKeyError) {@asymmetric_encryptor.decrypt("HbEh0Hwri26S7SWYqO26DBbzfhR1h/0pXYLjSKUpxF5DOaOCtD9oRN748+Na\nrfNaVN5Eg7RUhbRFZE+UnNHo6Q==\n")}
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
class AsymmetricEncryptorWithoutPrivateKeyTest < Test::Unit::TestCase
|
119
|
-
def setup
|
120
|
-
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:private_key_file => nil, :public_key_file => File.dirname(__FILE__) + '/keys/public')
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_should_not_be_private
|
124
|
-
assert !@asymmetric_encryptor.private?
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_should_not_be_able_to_decrypt
|
128
|
-
assert_raise(PluginAWeek::EncryptedStrings::NoPrivateKeyError) {@asymmetric_encryptor.decrypt("HbEh0Hwri26S7SWYqO26DBbzfhR1h/0pXYLjSKUpxF5DOaOCtD9oRN748+Na\nrfNaVN5Eg7RUhbRFZE+UnNHo6Q==\n")}
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
class AsymmetricEncryptorWithPrivateKeyTest < Test::Unit::TestCase
|
133
|
-
def setup
|
134
|
-
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:private_key_file => File.dirname(__FILE__) + '/keys/private')
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_should_not_be_public
|
138
|
-
assert !@asymmetric_encryptor.public?
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_should_be_private
|
142
|
-
assert @asymmetric_encryptor.private?
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_not_should_be_able_to_encrypt
|
146
|
-
assert_raise(PluginAWeek::EncryptedStrings::NoPublicKeyError) {@asymmetric_encryptor.encrypt('test')}
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_should_be_able_to_decrypt
|
150
|
-
assert_equal 'test', @asymmetric_encryptor.decrypt("HbEh0Hwri26S7SWYqO26DBbzfhR1h/0pXYLjSKUpxF5DOaOCtD9oRN748+Na\nrfNaVN5Eg7RUhbRFZE+UnNHo6Q==\n")
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
class AsymmetricEncryptorWithEncryptedPrivateKeyTest < Test::Unit::TestCase
|
155
|
-
def setup
|
156
|
-
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:private_key_file => File.dirname(__FILE__) + '/keys/encrypted_private', :algorithm => 'DES-EDE3-CBC', :password => 'secret')
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_should_not_be_public
|
160
|
-
assert !@asymmetric_encryptor.public?
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_should_be_private
|
164
|
-
assert @asymmetric_encryptor.private?
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_should_not_be_able_to_encrypt
|
168
|
-
assert_raise(PluginAWeek::EncryptedStrings::NoPublicKeyError) {@asymmetric_encryptor.encrypt('test')}
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_should_be_able_to_decrypt
|
172
|
-
assert_equal 'test', @asymmetric_encryptor.decrypt("HbEh0Hwri26S7SWYqO26DBbzfhR1h/0pXYLjSKUpxF5DOaOCtD9oRN748+Na\nrfNaVN5Eg7RUhbRFZE+UnNHo6Q==\n")
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
class AsymmetricEncryptorWithPKCS5CompliancyTest < Test::Unit::TestCase
|
177
|
-
def setup
|
178
|
-
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:private_key_file => File.dirname(__FILE__) + '/keys/pkcs5_encrypted_private', :algorithm => 'DES-EDE3-CBC', :password => 'secret', :pkcs5_compliant => true)
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_should_be_able_to_decrypt
|
182
|
-
assert_equal 'test', @asymmetric_encryptor.decrypt("HbEh0Hwri26S7SWYqO26DBbzfhR1h/0pXYLjSKUpxF5DOaOCtD9oRN748+Na\nrfNaVN5Eg7RUhbRFZE+UnNHo6Q==\n")
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
class AsymmetricEncyrptorWithDeprecatedKeyTest < Test::Unit::TestCase
|
187
|
-
def setup
|
188
|
-
@asymmetric_encryptor = PluginAWeek::EncryptedStrings::AsymmetricEncryptor.new(:private_key_file => File.dirname(__FILE__) + '/keys/encrypted_private', :key => 'secret')
|
189
|
-
end
|
190
|
-
|
191
|
-
def test_should_set_password
|
192
|
-
assert_equal 'secret', @asymmetric_encryptor.password
|
193
|
-
end
|
194
|
-
end
|
data/test/encryptor_test.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class EncryptorByDefaultTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@encryptor = PluginAWeek::EncryptedStrings::Encryptor.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_should_be_able_to_decrypt_by_default
|
9
|
-
assert @encryptor.can_decrypt?
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_should_raise_exception_if_decrypt_not_implemented
|
13
|
-
assert_raises(NotImplementedError) {@encryptor.decrypt('test')}
|
14
|
-
end
|
15
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
TGr8Jm/7zh1dfjjoNJtOncvX/BdUL47b8k2rQbMTY7VD6ZpD317NTuVX1hHV
|
2
|
-
54Nm6pnCId5wcga3sI3TqolTxkqKBy7Rb1mPVBeJyd7ZuoD7zp65+ws+o4Lr
|
3
|
-
Xn/3WculfuThUnDESqD53vnKPCfRK6hoMDygEV7urmuide5ogpZp52lidUku
|
4
|
-
cXOHDqfVETX7NNnHHghg/6qDUX7+0qf+XeKe8uiI0cPoE5YFnOHyF7oOBGtR
|
5
|
-
IqJG97q1InCJMeAbMSxcjO71Te51Z098yI+XN4rGmXbmzSrVKHMUk0tdsVxi
|
6
|
-
CE5OmnzLeXK1xomxkRmXZzl10WDBn9e4knoLJTlDdNR3fA4gLRfy3r6RBlDl
|
7
|
-
j7HI53o5gi9PTshSXwHr6Q8SV9fty2Nz3/yRT/ZPLUJC1GUqErLl2j6zYbVR
|
8
|
-
8YMaLt1Zqi79ycPZxZV4Zh57YE86nUqepS1pzVpcS8dHZMne846lTyaOyxZ8
|
9
|
-
dxW+18s7E7KqpHj17QYrF6c7R5ZHgoNAbLFeGSUCXqkW8YdyidLqQTzWN7hF
|
10
|
-
roVcZWFe8YfSUKmgndVBOHGHxMGr+OYgVdAStOEwmRHaNGgSBE4FCkKXYJUj
|
11
|
-
ec3zNpiOCb8zxfNku5nT5nIHnGqO4JKWDvDGVioV+ffHwXpAw3OFE5n+M/uo
|
12
|
-
4ZZbVSh1qZxd
|
data/test/no_key_error_test.rb
DELETED
data/test/sha_encryptor_test.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class ShaEncryptorByDefaulTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@sha_encryptor = PluginAWeek::EncryptedStrings::ShaEncryptor.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_should_use_default_salt
|
9
|
-
assert_equal 'salt', @sha_encryptor.salt
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_should_encrypt_using_default_salt
|
13
|
-
assert_equal 'f438229716cab43569496f3a3630b3727524b81b', @sha_encryptor.encrypt('test')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class ShaEncryptorWithCustomDefaultsTest < Test::Unit::TestCase
|
18
|
-
def setup
|
19
|
-
@original_default_salt = PluginAWeek::EncryptedStrings::ShaEncryptor.default_salt
|
20
|
-
PluginAWeek::EncryptedStrings::ShaEncryptor.default_salt = 'custom_salt'
|
21
|
-
@sha_encryptor = PluginAWeek::EncryptedStrings::ShaEncryptor.new
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_should_use_custom_default_salt
|
25
|
-
assert_equal 'custom_salt', @sha_encryptor.salt
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_should_encrypt_using_custom_default_salt
|
29
|
-
assert_equal '280f3c516070b09aa3eb755378509c725a9c6561', @sha_encryptor.encrypt('test')
|
30
|
-
end
|
31
|
-
|
32
|
-
def teardown
|
33
|
-
PluginAWeek::EncryptedStrings::ShaEncryptor.default_salt = @original_default_salt
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class ShaEncryptorWithInvalidOptionsTest < Test::Unit::TestCase
|
38
|
-
def test_should_throw_an_exception
|
39
|
-
assert_raise(ArgumentError) {PluginAWeek::EncryptedStrings::ShaEncryptor.new(:invalid => true)}
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class ShaEncryptorTest < Test::Unit::TestCase
|
44
|
-
def setup
|
45
|
-
@sha_encryptor = PluginAWeek::EncryptedStrings::ShaEncryptor.new
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_should_not_be_able_to_decrypt
|
49
|
-
assert !PluginAWeek::EncryptedStrings::ShaEncryptor.new.can_decrypt?
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_should_raise_exception_if_trying_to_decrypt
|
53
|
-
assert_raises(NotImplementedError) {PluginAWeek::EncryptedStrings::ShaEncryptor.new.decrypt('test')}
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class ShaEncryptorWithCustomOptionsTest < Test::Unit::TestCase
|
58
|
-
def setup
|
59
|
-
@sha_encryptor = PluginAWeek::EncryptedStrings::ShaEncryptor.new(:salt => 'different salt')
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_should_use_custom_salt
|
63
|
-
assert_equal 'different salt', @sha_encryptor.salt
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_should_encrypt_using_custom_salt
|
67
|
-
assert_equal '18e3256d71529db8fa65b2eef24a69ddad7070f3', @sha_encryptor.encrypt('test')
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
class ShaEncryptorWithNonStringSaltTest < Test::Unit::TestCase
|
72
|
-
require 'time'
|
73
|
-
|
74
|
-
def setup
|
75
|
-
@sha_encryptor = PluginAWeek::EncryptedStrings::ShaEncryptor.new(:salt => Time.parse('Tue Jan 01 00:00:00 UTC 2008'))
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_should_stringify_salt
|
79
|
-
assert_equal 'Tue Jan 01 00:00:00 UTC 2008', @sha_encryptor.salt
|
80
|
-
end
|
81
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class SymmetricEncryptorByDefaultTest < Test::Unit::TestCase
|
4
|
-
def setup
|
5
|
-
@symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:password => 'secret')
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_should_use_default_algorithm
|
9
|
-
assert_equal 'DES-EDE3-CBC', @symmetric_encryptor.algorithm
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_should_raise_exception
|
13
|
-
assert_raise(PluginAWeek::EncryptedStrings::NoKeyError) {PluginAWeek::EncryptedStrings::SymmetricEncryptor.new}
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_should_encrypt_using_default_configuration
|
17
|
-
assert_equal "MU6e/5LvhKA=\n", @symmetric_encryptor.encrypt('test')
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_should_decrypt_encrypted_string_using_default_configuration
|
21
|
-
assert_equal 'test', @symmetric_encryptor.decrypt("MU6e/5LvhKA=\n")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class SymmetricEncryptorWithCustomDefaultsTest < Test::Unit::TestCase
|
26
|
-
def setup
|
27
|
-
@original_default_algorithm = PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_algorithm
|
28
|
-
@original_default_password = PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_password
|
29
|
-
|
30
|
-
PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_algorithm = 'DES-EDE3-CFB'
|
31
|
-
PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_password = 'secret'
|
32
|
-
@symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_should_use_custom_default_algorithm
|
36
|
-
assert_equal 'DES-EDE3-CFB', @symmetric_encryptor.algorithm
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_should_use_custom_default_password
|
40
|
-
assert_equal 'secret', @symmetric_encryptor.password
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_should_encrypt_using_custom_default_configuration
|
44
|
-
assert_equal "C7D9mg==\n", @symmetric_encryptor.encrypt('test')
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_should_decrypt_encrypted_string_using_custom_default_configuration
|
48
|
-
assert_equal 'test', @symmetric_encryptor.decrypt("C7D9mg==\n")
|
49
|
-
end
|
50
|
-
|
51
|
-
def teardown
|
52
|
-
PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_algorithm = @original_default_algorithm
|
53
|
-
PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_password = @original_default_password
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class SymmetricEncryptorWithInvalidOptionsTest < Test::Unit::TestCase
|
58
|
-
def test_should_throw_an_exception
|
59
|
-
assert_raise(ArgumentError) {PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:invalid => true)}
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class SymmetricEncryptorTest < Test::Unit::TestCase
|
64
|
-
def setup
|
65
|
-
@symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:password => 'secret')
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_should_be_able_to_decrypt
|
69
|
-
assert @symmetric_encryptor.can_decrypt?
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
class SymmetricEncryptorWithCustomOptionsTest < Test::Unit::TestCase
|
74
|
-
def setup
|
75
|
-
@symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:algorithm => 'DES-EDE3-CFB', :password => 'secret')
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_should_use_custom_algorithm
|
79
|
-
assert_equal 'DES-EDE3-CFB', @symmetric_encryptor.algorithm
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_should_use_custom_password
|
83
|
-
assert_equal 'secret', @symmetric_encryptor.password
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_should_encrypt_using_custom_options
|
87
|
-
assert_equal "C7D9mg==\n", @symmetric_encryptor.encrypt('test')
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_should_decrypt_using_custom_options
|
91
|
-
assert_equal 'test', @symmetric_encryptor.decrypt("C7D9mg==\n")
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
class SymmetricEncryptorWithPKCS5CompliancyTest < Test::Unit::TestCase
|
96
|
-
def setup
|
97
|
-
@symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:password => 'secret', :pkcs5_compliant => true)
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_should_encrypt_using_pkcs5_generated_key
|
101
|
-
assert_equal "oTxJd67ElLY=\n", @symmetric_encryptor.encrypt('test')
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_should_decrypt_using_pkcs5_generated_key
|
105
|
-
assert_equal 'test', @symmetric_encryptor.decrypt("oTxJd67ElLY=\n" )
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
class SymmetricEncryptorWithDeprecatedDefaultsTest < Test::Unit::TestCase
|
110
|
-
def setup
|
111
|
-
@original_default_password = PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_password
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_should_set_password_when_setting_key
|
115
|
-
PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_key = 'secret'
|
116
|
-
assert_equal 'secret', PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_password
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_should_get_password_when_getting_key
|
120
|
-
PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_key = 'secret'
|
121
|
-
assert_equal 'secret', PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_key
|
122
|
-
end
|
123
|
-
|
124
|
-
def teardown
|
125
|
-
PluginAWeek::EncryptedStrings::SymmetricEncryptor.default_password = @original_default_password
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
class SymmetricEncryptorWithDeprecatedKeyTest < Test::Unit::TestCase
|
130
|
-
def setup
|
131
|
-
@symmetric_encryptor = PluginAWeek::EncryptedStrings::SymmetricEncryptor.new(:key => 'secret')
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_should_set_password
|
135
|
-
assert_equal 'secret', @symmetric_encryptor.password
|
136
|
-
end
|
137
|
-
end
|