sentry 0.3.1 → 0.5.3
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/lib/active_record/sentry.rb +81 -58
- data/lib/sentry.rb +26 -1
- data/lib/sentry/asymmetric_sentry.rb +53 -5
- data/lib/sentry/asymmetric_sentry_callback.rb +7 -7
- data/lib/sentry/symmetric_sentry_callback.rb +8 -8
- data/test/abstract_unit.rb +27 -16
- data/test/asymmetric_sentry_callback_test.rb +66 -5
- data/test/asymmetric_sentry_test.rb +21 -12
- data/test/database.yml +2 -2
- data/test/debug.log +180 -31
- data/test/fixtures/user.rb +22 -21
- data/test/fixtures/users.yml +3 -5
- data/test/rsa_key_test.rb +11 -0
- data/test/schema.rb +2 -2
- data/test/sha_sentry_test.rb +28 -24
- data/test/symmetric_sentry_callback_test.rb +28 -23
- metadata +73 -59
data/lib/active_record/sentry.rb
CHANGED
|
@@ -3,77 +3,100 @@ module ActiveRecord # :nodoc:
|
|
|
3
3
|
def self.included(base) # :nodoc:
|
|
4
4
|
base.extend ClassMethods
|
|
5
5
|
end
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
module ClassMethods
|
|
8
8
|
def generates_crypted(attr_name, options = {})
|
|
9
|
-
mode = options[:mode] || :
|
|
9
|
+
mode = options[:mode] || :asymmetric
|
|
10
10
|
case mode
|
|
11
|
-
when :sha
|
|
12
|
-
|
|
11
|
+
#when :sha
|
|
12
|
+
# generates_crypted_hash_of(attr_name)
|
|
13
13
|
when :asymmetric, :asymmetrical
|
|
14
14
|
asymmetrically_encrypts(attr_name)
|
|
15
|
-
when :symmetric, :symmetrical
|
|
16
|
-
|
|
15
|
+
#when :symmetric, :symmetrical
|
|
16
|
+
# symmetrically_encrypts(attr_name)
|
|
17
17
|
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def generates_crypted_hash_of(attribute)
|
|
21
|
-
before_validation ::Sentry::ShaSentry.new(attribute)
|
|
22
|
-
attr_accessor attribute
|
|
23
18
|
end
|
|
24
19
|
|
|
25
|
-
def
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
define_method(attr_name) do |*optional|
|
|
31
|
-
send("#{attr_name}!", *optional) rescue nil
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
define_method("#{attr_name}!") do |*optional|
|
|
35
|
-
return decrypted_values[attr_name] unless decrypted_values[attr_name].nil?
|
|
36
|
-
return nil if send("crypted_#{attr_name}").nil?
|
|
37
|
-
key = optional.shift
|
|
38
|
-
::Sentry::AsymmetricSentry.decrypt_from_base64(send("crypted_#{attr_name}"), key)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
define_method("#{attr_name}=") do |value|
|
|
42
|
-
decrypted_values[attr_name] = value
|
|
43
|
-
nil
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
private
|
|
47
|
-
define_method(:decrypted_values) do
|
|
48
|
-
@decrypted_values ||= {}
|
|
49
|
-
end
|
|
50
|
-
end
|
|
20
|
+
#def generates_crypted_hash_of(attribute)
|
|
21
|
+
# before_validation ::Sentry::ShaSentry.new(attribute)
|
|
22
|
+
# attr_accessor attribute
|
|
23
|
+
#end
|
|
51
24
|
|
|
52
|
-
def
|
|
53
|
-
temp_sentry = ::Sentry::
|
|
54
|
-
before_validation temp_sentry
|
|
55
|
-
after_save temp_sentry
|
|
25
|
+
def asymmetrically_encrypts(attr_name, options = {})
|
|
26
|
+
#temp_sentry = ::Sentry::AsymmetricSentryCallback.new(attr_name)
|
|
27
|
+
#before_validation temp_sentry
|
|
28
|
+
#after_save temp_sentry
|
|
29
|
+
unless instance_methods.include?("#{attr_name}_with_decryption")
|
|
30
|
+
define_read_methods
|
|
56
31
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
32
|
+
define_method("#{attr_name}_with_decryption") do |*optional|
|
|
33
|
+
begin
|
|
34
|
+
crypted_value = self.send("#{attr_name}_without_decryption")
|
|
35
|
+
#puts "crypted value: #{crypted_value}"
|
|
36
|
+
return nil if crypted_value.nil?
|
|
37
|
+
key = optional.shift || (options[:key].is_a?(Proc) ? options[:key].call : options[:key]) || ::Sentry.default_key
|
|
38
|
+
decrypted_value = ::Sentry::AsymmetricSentry.decrypt_large_from_base64(crypted_value, key)
|
|
39
|
+
return decrypted_value
|
|
40
|
+
rescue Exception => e
|
|
41
|
+
nil
|
|
42
|
+
end
|
|
43
|
+
end
|
|
60
44
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
private
|
|
73
|
-
define_method(:decrypted_values) do
|
|
74
|
-
@decrypted_values ||= {}
|
|
45
|
+
alias_method_chain attr_name, :decryption
|
|
46
|
+
alias_method "crypted_#{attr_name}", "#{attr_name}_without_decryption"
|
|
47
|
+
alias_method "#{attr_name}_before_type_cast", "#{attr_name}_with_decryption"
|
|
48
|
+
|
|
49
|
+
define_method("#{attr_name}_with_encryption=") do |value|
|
|
50
|
+
encrypted_value = self.class.encrypt_for_sentry(value)
|
|
51
|
+
self.send("#{attr_name}_without_encryption=", encrypted_value)
|
|
52
|
+
nil
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
alias_method_chain "#{attr_name}=", :encryption
|
|
75
56
|
end
|
|
57
|
+
|
|
76
58
|
end
|
|
59
|
+
|
|
60
|
+
def encrypt_for_sentry(string)
|
|
61
|
+
return nil if string.nil?
|
|
62
|
+
return ::Sentry::AsymmetricSentry.encrypt_large_to_base64(string)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
#def symmetrically_encrypts(attr_name)
|
|
68
|
+
# temp_sentry = ::Sentry::SymmetricSentryCallback.new(attr_name)
|
|
69
|
+
# before_validation temp_sentry
|
|
70
|
+
# after_save temp_sentry
|
|
71
|
+
#
|
|
72
|
+
# define_method(attr_name) do
|
|
73
|
+
# send("#{attr_name}!") rescue nil
|
|
74
|
+
# end
|
|
75
|
+
#
|
|
76
|
+
# define_method("#{attr_name}!") do
|
|
77
|
+
# return decrypted_values[attr_name] unless decrypted_values[attr_name].nil?
|
|
78
|
+
# return nil if send("crypted_#{attr_name}").nil?
|
|
79
|
+
# ::Sentry::SymmetricSentry.decrypt_from_base64(send("crypted_#{attr_name}"))
|
|
80
|
+
# end
|
|
81
|
+
#
|
|
82
|
+
# define_method("#{attr_name}=") do |value|
|
|
83
|
+
# decrypted_values[attr_name] = value
|
|
84
|
+
# nil
|
|
85
|
+
# end
|
|
86
|
+
#
|
|
87
|
+
# private
|
|
88
|
+
# define_method(:decrypted_values) do
|
|
89
|
+
# @decrypted_values ||= {}
|
|
90
|
+
# end
|
|
91
|
+
#end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
@@CHARS = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
|
|
95
|
+
|
|
96
|
+
def self.rand_string(length=8)
|
|
97
|
+
s=''
|
|
98
|
+
length.times{ s << @@CHARS[rand(@@CHARS.length)] }
|
|
99
|
+
s
|
|
77
100
|
end
|
|
78
101
|
end
|
|
79
102
|
end
|
data/lib/sentry.rb
CHANGED
|
@@ -34,6 +34,7 @@ module Sentry
|
|
|
34
34
|
end
|
|
35
35
|
class NoPrivateKeyError < StandardError
|
|
36
36
|
end
|
|
37
|
+
mattr_accessor :default_key
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
begin
|
|
@@ -43,4 +44,28 @@ begin
|
|
|
43
44
|
end
|
|
44
45
|
rescue NameError
|
|
45
46
|
nil
|
|
46
|
-
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
class OpenSSL::PKey::RSA
|
|
50
|
+
def max_encryptable_length
|
|
51
|
+
@max_encryption_length ||= calc_max_encrypted_length
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def calc_max_encrypted_length
|
|
57
|
+
upper_bound = 4*1024
|
|
58
|
+
test_length = upper_bound / 2
|
|
59
|
+
while test_length != (upper_bound - 1)
|
|
60
|
+
probe = "a" * test_length
|
|
61
|
+
begin
|
|
62
|
+
self.public_encrypt(probe)
|
|
63
|
+
test_length = test_length + ((upper_bound - test_length) / 2)
|
|
64
|
+
rescue Exception => e
|
|
65
|
+
upper_bound = test_length
|
|
66
|
+
test_length = test_length / 2
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
return test_length
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -13,14 +13,52 @@ module Sentry
|
|
|
13
13
|
# * <tt>:symmetric_algorithm</tt> - algorithm to use for SymmetricSentry
|
|
14
14
|
def initialize(options = {})
|
|
15
15
|
@public_key = @private_key = nil
|
|
16
|
-
private_key_file = options[:private_key_file]
|
|
17
|
-
public_key_file = options[:public_key_file] || @@default_public_key_file
|
|
16
|
+
self.private_key_file = options[:private_key_file]
|
|
17
|
+
self.public_key_file = options[:public_key_file] || @@default_public_key_file
|
|
18
18
|
@symmetric_algorithm = options[:symmetric_algorithm] || @@default_symmetric_algorithm
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def encrypt(data)
|
|
22
22
|
raise NoPublicKeyError unless public?
|
|
23
|
-
public_rsa
|
|
23
|
+
rsa = public_rsa
|
|
24
|
+
return rsa.public_encrypt(data)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def decrypt_large_from_base64(data, key=nil)
|
|
28
|
+
raise NoPrivateKeyError unless private?
|
|
29
|
+
chunk_length = public_rsa.max_encryptable_length + 11 # 11 is magic padding for RSA encoding
|
|
30
|
+
b64_decoded = Base64.decode64(data)
|
|
31
|
+
padding_length = b64_decoded[0]
|
|
32
|
+
data = b64_decoded[1, data.length]
|
|
33
|
+
return (0...data.length).step(chunk_length).inject("") { |accum, idx| accum + decrypt_with_padding(data.slice(idx, chunk_length), padding_length, key)}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def chunk_size(padding_length)
|
|
37
|
+
return public_rsa.max_encryptable_length - padding_length
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def encrypt_large_to_base64(data)
|
|
41
|
+
raise NoPublicKeyError unless public?
|
|
42
|
+
padding_length = 8
|
|
43
|
+
chunk_length = chunk_size(padding_length)
|
|
44
|
+
return Base64.encode64(padding_length.chr + (0...data.length).step(chunk_length).inject("") {|accum, idx| accum + encrypt_with_padding( data.slice(idx, chunk_length), padding_length)} )
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def decrypt_with_padding(data, padding_length, key=nil)
|
|
48
|
+
decrypted = decrypt(data, key)
|
|
49
|
+
return decrypted[0, decrypted.length - padding_length]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def encrypt_with_padding(data, padding_length)
|
|
53
|
+
encrypt(data + rand_string(padding_length))
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
@@CHARS = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
|
|
57
|
+
|
|
58
|
+
def rand_string(length=8)
|
|
59
|
+
s=''
|
|
60
|
+
length.times{ s << @@CHARS[rand(@@CHARS.length)] }
|
|
61
|
+
s
|
|
24
62
|
end
|
|
25
63
|
|
|
26
64
|
def encrypt_to_base64(data)
|
|
@@ -29,7 +67,8 @@ module Sentry
|
|
|
29
67
|
|
|
30
68
|
def decrypt(data, key = nil)
|
|
31
69
|
raise NoPrivateKeyError unless private?
|
|
32
|
-
private_rsa(key)
|
|
70
|
+
rsa = private_rsa(key)
|
|
71
|
+
return rsa.private_decrypt(data)
|
|
33
72
|
end
|
|
34
73
|
|
|
35
74
|
def decrypt_from_base64(data, key = nil)
|
|
@@ -74,11 +113,19 @@ module Sentry
|
|
|
74
113
|
def encrypt_to_base64(data)
|
|
75
114
|
self.new.encrypt_to_base64(data)
|
|
76
115
|
end
|
|
116
|
+
|
|
117
|
+
def encrypt_large_to_base64(data)
|
|
118
|
+
self.new.encrypt_large_to_base64(data)
|
|
119
|
+
end
|
|
77
120
|
|
|
78
121
|
def decrypt(data, key = nil)
|
|
79
122
|
self.new.decrypt(data, key)
|
|
80
123
|
end
|
|
81
124
|
|
|
125
|
+
def decrypt_large_from_base64(data, key = nil)
|
|
126
|
+
self.new.decrypt_large_from_base64(data, key)
|
|
127
|
+
end
|
|
128
|
+
|
|
82
129
|
def decrypt_from_base64(data, key = nil)
|
|
83
130
|
self.new.decrypt_from_base64(data, key)
|
|
84
131
|
end
|
|
@@ -120,6 +167,7 @@ module Sentry
|
|
|
120
167
|
if @private_key_file and File.file?(@private_key_file)
|
|
121
168
|
@private_key = File.open(@private_key_file) { |f| f.read }
|
|
122
169
|
end
|
|
170
|
+
return @private_key
|
|
123
171
|
end
|
|
124
172
|
|
|
125
173
|
def load_public_key
|
|
@@ -141,4 +189,4 @@ module Sentry
|
|
|
141
189
|
@public_rsa ||= OpenSSL::PKey::RSA.new(@public_key)
|
|
142
190
|
end
|
|
143
191
|
end
|
|
144
|
-
end
|
|
192
|
+
end
|
|
@@ -5,13 +5,13 @@ module Sentry
|
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
# Performs encryption on before_validation Active Record callback
|
|
8
|
-
def before_validation(model)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
end
|
|
8
|
+
#def before_validation(model)
|
|
9
|
+
# return if model.send(@attr_name).blank?
|
|
10
|
+
# model.send("crypted_#{@attr_name}=", AsymmetricSentry.encrypt_to_base64(model.send(@attr_name)))
|
|
11
|
+
#end
|
|
12
12
|
|
|
13
|
-
def after_save(model)
|
|
14
|
-
|
|
15
|
-
end
|
|
13
|
+
#def after_save(model)
|
|
14
|
+
# model.send("#{@attr_name}=", nil)
|
|
15
|
+
#end
|
|
16
16
|
end
|
|
17
17
|
end
|
|
@@ -4,14 +4,14 @@ module Sentry
|
|
|
4
4
|
@attr_name = attr_name
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
def before_validation(model)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
end
|
|
7
|
+
## Performs encryption on before_validation Active Record callback
|
|
8
|
+
#def before_validation(model)
|
|
9
|
+
# return if model.send(@attr_name).blank?
|
|
10
|
+
# model.send("crypted_#{@attr_name}=", SymmetricSentry.encrypt_to_base64(model.send(@attr_name)))
|
|
11
|
+
#end
|
|
12
12
|
|
|
13
|
-
def after_save(model)
|
|
14
|
-
|
|
15
|
-
end
|
|
13
|
+
#def after_save(model)
|
|
14
|
+
# #model.send("#{@attr_name}=", nil)
|
|
15
|
+
#end
|
|
16
16
|
end
|
|
17
17
|
end
|
data/test/abstract_unit.rb
CHANGED
|
@@ -4,30 +4,41 @@ require 'rubygems'
|
|
|
4
4
|
require 'test/unit'
|
|
5
5
|
require 'active_record'
|
|
6
6
|
require 'active_record/fixtures'
|
|
7
|
-
require 'active_support/
|
|
8
|
-
require 'active_support/
|
|
7
|
+
require 'active_support/test_case'
|
|
8
|
+
#require 'active_support/binding_of_caller'
|
|
9
|
+
#require 'active_support/breakpoint'
|
|
9
10
|
require "#{File.dirname(__FILE__)}/../lib/sentry"
|
|
10
11
|
|
|
11
12
|
config_location = File.dirname(__FILE__) + '/database.yml'
|
|
12
13
|
|
|
13
14
|
config = YAML::load(IO.read(config_location))
|
|
14
15
|
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
|
15
|
-
ActiveRecord::Base.establish_connection(config[ENV['DB'] || '
|
|
16
|
+
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'mysql'])
|
|
17
|
+
ActiveRecord::Base.configurations["test"] = "lolcatz"
|
|
16
18
|
|
|
17
19
|
load(File.dirname(__FILE__) + "/schema.rb")
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
class ActiveSupport::TestCase #:nodoc:
|
|
22
|
+
include ActiveRecord::TestFixtures
|
|
23
|
+
#def create_fixtures(*table_names)
|
|
24
|
+
# if block_given?
|
|
25
|
+
# Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names) { yield }
|
|
26
|
+
# else
|
|
27
|
+
# Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names)
|
|
28
|
+
# end
|
|
29
|
+
#end
|
|
30
|
+
|
|
31
|
+
self.use_instantiated_fixtures = false
|
|
32
|
+
self.use_transactional_fixtures = true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def create_fixtures(*table_names, &block)
|
|
36
|
+
Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names, {}, &block)
|
|
32
37
|
end
|
|
33
38
|
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
ActiveSupport::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
|
|
42
|
+
ActiveSupport::TestCase.use_instantiated_fixtures = true
|
|
43
|
+
ActiveSupport::TestCase.use_transactional_fixtures = (ENV['AR_TX_FIXTURES'] == "yes")
|
|
44
|
+
$LOAD_PATH.unshift(ActiveSupport::TestCase.fixture_path)
|
|
@@ -1,22 +1,70 @@
|
|
|
1
1
|
require 'abstract_unit'
|
|
2
2
|
require 'fixtures/user'
|
|
3
3
|
|
|
4
|
-
class AsymmetricSentryCallbackTest <
|
|
4
|
+
class AsymmetricSentryCallbackTest < ActiveSupport::TestCase
|
|
5
5
|
fixtures :users
|
|
6
6
|
|
|
7
7
|
def setup
|
|
8
|
+
super
|
|
8
9
|
@str = 'sentry'
|
|
9
10
|
@key = 'secret'
|
|
10
11
|
@public_key_file = File.dirname(__FILE__) + '/keys/public'
|
|
11
12
|
@private_key_file = File.dirname(__FILE__) + '/keys/private'
|
|
12
13
|
@encrypted_public_key_file = File.dirname(__FILE__) + '/keys/encrypted_public'
|
|
13
14
|
@encrypted_private_key_file = File.dirname(__FILE__) + '/keys/encrypted_private'
|
|
14
|
-
|
|
15
|
+
|
|
15
16
|
@orig = 'sentry'
|
|
16
17
|
Sentry::AsymmetricSentry.default_public_key_file = @public_key_file
|
|
17
18
|
Sentry::AsymmetricSentry.default_private_key_file = @private_key_file
|
|
19
|
+
Sentry::SymmetricSentry.default_key = @key
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def teardown
|
|
23
|
+
super
|
|
24
|
+
Sentry.default_key = nil
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_encryption_should_use_default_key_when_present
|
|
28
|
+
use_encrypted_keys
|
|
29
|
+
|
|
30
|
+
assert_nil users(:user_2).creditcard
|
|
31
|
+
Sentry.default_key = @key
|
|
32
|
+
|
|
33
|
+
assert_equal @orig, users(:user_2).creditcard
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_encrypt_for_sentry
|
|
37
|
+
assert_not_nil User.encrypt_for_sentry("hello")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_encryption_with_random_padding
|
|
41
|
+
# system works with unsaved record
|
|
42
|
+
u = User.new :login => 'jones'
|
|
43
|
+
u.creditcard = @orig
|
|
44
|
+
assert_equal @orig, u.creditcard
|
|
45
|
+
u.save!
|
|
46
|
+
|
|
47
|
+
# reload after save and check the decrypt works
|
|
48
|
+
u = User.find(u.id)
|
|
49
|
+
assert_equal @orig, u.creditcard
|
|
50
|
+
original_crypttext = u.crypted_creditcard
|
|
51
|
+
|
|
52
|
+
# set to same plaintext
|
|
53
|
+
u.creditcard = @orig
|
|
54
|
+
u.save!
|
|
55
|
+
|
|
56
|
+
# expect different crypttext (due to random padding)
|
|
57
|
+
assert_not_equal original_crypttext, u.crypted_creditcard
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_should_handle_nils
|
|
61
|
+
u = User.create :login => 'john'
|
|
62
|
+
u.creditcard = nil
|
|
63
|
+
assert u.save
|
|
64
|
+
assert u.crypted_creditcard.nil?
|
|
65
|
+
assert u.creditcard.nil?
|
|
18
66
|
end
|
|
19
|
-
|
|
67
|
+
|
|
20
68
|
def test_should_encrypt_creditcard
|
|
21
69
|
u = User.create :login => 'jones'
|
|
22
70
|
u.creditcard = @orig
|
|
@@ -24,6 +72,15 @@ class AsymmetricSentryCallbackTest < Test::Unit::TestCase
|
|
|
24
72
|
assert !u.crypted_creditcard.empty?
|
|
25
73
|
end
|
|
26
74
|
|
|
75
|
+
def test_should_deal_with_before_typecast
|
|
76
|
+
u = User.create :login => 'jones'
|
|
77
|
+
u.creditcard = "123123"
|
|
78
|
+
assert_equal "123123", u.creditcard_before_type_cast
|
|
79
|
+
assert u.save
|
|
80
|
+
u.reload
|
|
81
|
+
assert_equal "123123", u.creditcard_before_type_cast
|
|
82
|
+
end
|
|
83
|
+
|
|
27
84
|
def test_should_decrypt_creditcard
|
|
28
85
|
assert_equal @orig, users(:user_1).creditcard
|
|
29
86
|
end
|
|
@@ -40,7 +97,11 @@ class AsymmetricSentryCallbackTest < Test::Unit::TestCase
|
|
|
40
97
|
assert_nil users(:user_2).creditcard
|
|
41
98
|
assert_nil users(:user_2).creditcard('other secret')
|
|
42
99
|
end
|
|
43
|
-
|
|
100
|
+
|
|
101
|
+
def test_do_encryption
|
|
102
|
+
use_encrypted_keys
|
|
103
|
+
end
|
|
104
|
+
|
|
44
105
|
def test_should_encrypt_encrypted_creditcard
|
|
45
106
|
use_encrypted_keys
|
|
46
107
|
u = User.create :login => 'jones'
|
|
@@ -53,7 +114,7 @@ class AsymmetricSentryCallbackTest < Test::Unit::TestCase
|
|
|
53
114
|
use_encrypted_keys
|
|
54
115
|
assert_equal @orig, users(:user_2).creditcard(@key)
|
|
55
116
|
end
|
|
56
|
-
|
|
117
|
+
|
|
57
118
|
def use_encrypted_keys
|
|
58
119
|
Sentry::AsymmetricSentry.default_public_key_file = @encrypted_public_key_file
|
|
59
120
|
Sentry::AsymmetricSentry.default_private_key_file = @encrypted_private_key_file
|
|
@@ -2,6 +2,8 @@ require 'abstract_unit'
|
|
|
2
2
|
|
|
3
3
|
class AsymmetricSentryTest < Test::Unit::TestCase
|
|
4
4
|
def setup
|
|
5
|
+
Sentry::AsymmetricSentry.default_public_key_file = nil
|
|
6
|
+
Sentry::AsymmetricSentry.default_private_key_file = nil
|
|
5
7
|
@str = 'sentry'
|
|
6
8
|
@key = 'secret'
|
|
7
9
|
@public_key_file = File.dirname(__FILE__) + '/keys/public'
|
|
@@ -9,19 +11,17 @@ class AsymmetricSentryTest < Test::Unit::TestCase
|
|
|
9
11
|
@encrypted_public_key_file = File.dirname(__FILE__) + '/keys/encrypted_public'
|
|
10
12
|
@encrypted_private_key_file = File.dirname(__FILE__) + '/keys/encrypted_private'
|
|
11
13
|
@sentry = Sentry::AsymmetricSentry.new
|
|
12
|
-
|
|
14
|
+
|
|
13
15
|
@orig = 'sentry'
|
|
14
16
|
@data = "vYfMxtVB8ezXmQKSNqTC9sPgi8TbsYRxWd7DVbpprzyuEdZ7gftJ/0IXsbXm\nXCU08bTAl0uEFm7dau+eJMXEJg==\n"
|
|
15
17
|
@encrypted_data = "q2obYAITmK93ylzVS01mJx1jSlnmylMX15nFpb4uKesVgnqvtzBRHZ/SK+Nm\nEzceIoAcJc3DHosVa4VUE/aK/A==\n"
|
|
16
|
-
Sentry::AsymmetricSentry.default_public_key_file = nil
|
|
17
|
-
Sentry::AsymmetricSentry.default_private_key_file = nil
|
|
18
18
|
end
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
def test_should_decrypt_files
|
|
21
21
|
set_key_files @public_key_file, @private_key_file
|
|
22
22
|
assert_equal @orig, @sentry.decrypt_from_base64(@data)
|
|
23
23
|
end
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
def test_should_decrypt_files_with_encrypted_key
|
|
26
26
|
set_key_files @encrypted_public_key_file, @encrypted_private_key_file
|
|
27
27
|
assert_equal @orig, @sentry.decrypt_from_base64(@encrypted_data, @key)
|
|
@@ -32,7 +32,7 @@ class AsymmetricSentryTest < Test::Unit::TestCase
|
|
|
32
32
|
assert !@sentry.private?
|
|
33
33
|
set_key_files @public_key_file, @private_key_file
|
|
34
34
|
end
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
def test_should_read_encrypted_key_files
|
|
37
37
|
assert !@sentry.public?
|
|
38
38
|
assert !@sentry.private?
|
|
@@ -43,17 +43,25 @@ class AsymmetricSentryTest < Test::Unit::TestCase
|
|
|
43
43
|
set_default_key_files @public_key_file, @private_key_file
|
|
44
44
|
assert_equal @orig, @sentry.decrypt_from_base64(@data)
|
|
45
45
|
end
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
def test_should_decrypt_files_with_default_encrypted_key
|
|
48
48
|
set_default_key_files @encrypted_public_key_file, @encrypted_private_key_file
|
|
49
49
|
assert_equal @orig, @sentry.decrypt_from_base64(@encrypted_data, @key)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
+
def test_should_decrypt_block_by_block_for_large_data
|
|
53
|
+
set_default_key_files @encrypted_public_key_file, @encrypted_private_key_file
|
|
54
|
+
large_data = "asdf" * 2048
|
|
55
|
+
encrypted = @sentry.encrypt_large_to_base64(large_data)
|
|
56
|
+
assert_not_equal large_data, encrypted
|
|
57
|
+
assert_equal large_data, @sentry.decrypt_large_from_base64(encrypted, @key)
|
|
58
|
+
end
|
|
59
|
+
|
|
52
60
|
def test_should_decrypt_files_with_default_key_using_class_method
|
|
53
61
|
set_default_key_files @public_key_file, @private_key_file
|
|
54
62
|
assert_equal @orig, Sentry::AsymmetricSentry.decrypt_from_base64(@data)
|
|
55
63
|
end
|
|
56
|
-
|
|
64
|
+
|
|
57
65
|
def test_should_decrypt_files_with_default_encrypted_key_using_class_method
|
|
58
66
|
set_default_key_files @encrypted_public_key_file, @encrypted_private_key_file
|
|
59
67
|
assert_equal @orig, Sentry::AsymmetricSentry.decrypt_from_base64(@encrypted_data, @key)
|
|
@@ -64,25 +72,26 @@ class AsymmetricSentryTest < Test::Unit::TestCase
|
|
|
64
72
|
assert !@sentry.private?
|
|
65
73
|
set_default_key_files @public_key_file, @private_key_file
|
|
66
74
|
end
|
|
67
|
-
|
|
75
|
+
|
|
68
76
|
def test_should_read_encrypted_key_files_with_default_key
|
|
69
77
|
assert !@sentry.public?
|
|
70
78
|
assert !@sentry.private?
|
|
71
79
|
set_default_key_files @encrypted_public_key_file, @encrypted_private_key_file
|
|
72
80
|
end
|
|
73
81
|
|
|
74
|
-
private
|
|
82
|
+
private
|
|
83
|
+
|
|
75
84
|
def set_key_files(public_key, private_key)
|
|
76
85
|
@sentry.public_key_file = public_key
|
|
77
86
|
@sentry.private_key_file = private_key
|
|
78
87
|
assert @sentry.private?
|
|
79
88
|
assert @sentry.public?
|
|
80
89
|
end
|
|
81
|
-
|
|
90
|
+
|
|
82
91
|
def set_default_key_files(public_key, private_key)
|
|
83
92
|
Sentry::AsymmetricSentry.default_public_key_file = public_key
|
|
84
93
|
Sentry::AsymmetricSentry.default_private_key_file = private_key
|
|
85
94
|
assert @sentry.private?
|
|
86
95
|
assert @sentry.public?
|
|
87
96
|
end
|
|
88
|
-
end
|
|
97
|
+
end
|
data/test/database.yml
CHANGED
data/test/debug.log
CHANGED
|
@@ -1,31 +1,180 @@
|
|
|
1
|
-
# Logfile created on
|
|
2
|
-
[4;36;1mSQL (0.
|
|
3
|
-
[4;35;1mSQL (0.
|
|
4
|
-
[4;36;1mSQL (
|
|
5
|
-
[4;35;1mSQL (0.
|
|
6
|
-
[4;36;1mSQL (
|
|
7
|
-
[4;35;1mSQL (
|
|
8
|
-
[4;36;
|
|
9
|
-
[4;35;1mSQL (0.
|
|
10
|
-
[4;36;
|
|
11
|
-
[4;35;
|
|
12
|
-
[4;36;
|
|
13
|
-
[4;35;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
[4;36;
|
|
17
|
-
[4;35;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
[4;36;
|
|
21
|
-
[4;35;1mUser
|
|
22
|
-
[4;36;
|
|
23
|
-
[4;35;1mSQL (0.
|
|
24
|
-
[4;36;
|
|
25
|
-
[4;35;1mSQL (
|
|
26
|
-
[4;36;
|
|
27
|
-
[4;35;1mUser Load (0.
|
|
28
|
-
[4;36;
|
|
29
|
-
|
|
30
|
-
[4;
|
|
31
|
-
[4;
|
|
1
|
+
# Logfile created on Mon Nov 02 22:25:53 -0800 2009 by logger.rb/22283
|
|
2
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
|
|
3
|
+
[4;35;1mSQL (0.2ms)[0m [0mSHOW TABLES[0m
|
|
4
|
+
[4;36;1mSQL (13.0ms)[0m [0;1mCREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `password` varchar(255), `creditcard` varchar(255), `login` varchar(50), `type` varchar(20)) ENGINE=InnoDB[0m
|
|
5
|
+
[4;35;1mSQL (0.2ms)[0m [0mSHOW TABLES[0m
|
|
6
|
+
[4;36;1mSQL (15.9ms)[0m [0;1mCREATE TABLE `schema_migrations` (`version` varchar(255) NOT NULL) ENGINE=InnoDB[0m
|
|
7
|
+
[4;35;1mSQL (9.7ms)[0m [0mCREATE UNIQUE INDEX `unique_schema_migrations` ON `schema_migrations` (`version`)[0m
|
|
8
|
+
[4;36;1mSQL (0.4ms)[0m [0;1mSHOW TABLES[0m
|
|
9
|
+
[4;35;1mSQL (0.4ms)[0m [0mSELECT version FROM `schema_migrations`[0m
|
|
10
|
+
[4;36;1mSQL (0.3ms)[0m [0;1mINSERT INTO `schema_migrations` (version) VALUES ('1')[0m
|
|
11
|
+
[4;35;1mUser Columns (50.0ms)[0m [0mSHOW FIELDS FROM `users`[0m
|
|
12
|
+
[4;36;1mUser Load (0.1ms)[0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 2) [0m
|
|
13
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
14
|
+
[4;36;1mUser Create (0.1ms)[0m [0;1mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES('CAv8EHo5dvX6XoE1V7lsAZbnpTtrFCbJPGwg5vRaVGkHzUrbUnaJYW/xaOZk\n6fGb9aB+yGQTbGfzhtdK8NavDqY=\n', NULL, NULL, 'jones')[0m
|
|
15
|
+
[4;35;1mSQL (12.5ms)[0m [0mCOMMIT[0m
|
|
16
|
+
[4;36;1mUser Load (0.2ms)[0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 3) [0m
|
|
17
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
18
|
+
[4;36;1mUser Update (0.2ms)[0m [0;1mUPDATE `users` SET `creditcard` = 'CJgmQYPJL/JW3Y9soOooOFTS9DhkEou61CV9+7OQSbbWpbuYvO3S34KU7C46\n/47DGIJx7c0EQ/sJUUYfa+cTasE=\n' WHERE `id` = 3[0m
|
|
19
|
+
[4;35;1mSQL (3.7ms)[0m [0mCOMMIT[0m
|
|
20
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
21
|
+
[4;35;1mUser Create (0.2ms)[0m [0mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES(NULL, NULL, NULL, 'jones')[0m
|
|
22
|
+
[4;36;1mSQL (3.2ms)[0m [0;1mCOMMIT[0m
|
|
23
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
24
|
+
[4;36;1mUser Update (0.3ms)[0m [0;1mUPDATE `users` SET `creditcard` = 'CGtcyD/BXpdGeLHOP0TDYOUVDOsuxRMM3lxxwZdUkA/cIQHepNHXF9404fuO\ntDzgobBIVY/fJtC9Oxb7GgoG/+0=\n' WHERE `id` = 4[0m
|
|
25
|
+
[4;35;1mSQL (4.2ms)[0m [0mCOMMIT[0m
|
|
26
|
+
[4;36;1mUser Load (0.2ms)[0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 4) [0m
|
|
27
|
+
[4;35;1mUser Load (0.1ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
|
|
28
|
+
[4;36;1mUser Load (0.1ms)[0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 2) [0m
|
|
29
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
30
|
+
[4;36;1mUser Create (0.1ms)[0m [0;1mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES(NULL, NULL, NULL, 'jones')[0m
|
|
31
|
+
[4;35;1mSQL (0.3ms)[0m [0mCOMMIT[0m
|
|
32
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
33
|
+
[4;35;1mUser Update (0.1ms)[0m [0mUPDATE `users` SET `creditcard` = 'CDvJtbBuujAsuqJdmwQLnW5LAj+pNXiOdm79iD3DZE7ckQP2F4oLR6UuGLZK\n8752nplZqMMx5ngNsSe7yTWmuxE=\n' WHERE `id` = 5[0m
|
|
34
|
+
[4;36;1mSQL (0.4ms)[0m [0;1mCOMMIT[0m
|
|
35
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
36
|
+
[4;36;1mUser Create (0.1ms)[0m [0;1mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES(NULL, NULL, NULL, 'jones')[0m
|
|
37
|
+
[4;35;1mSQL (0.3ms)[0m [0mCOMMIT[0m
|
|
38
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
39
|
+
[4;35;1mUser Update (0.5ms)[0m [0mUPDATE `users` SET `creditcard` = 'CHEkm4TYxx3bl+lQ0ipw+qbeHOslQbyf3qvEGg90IRdLcJvBDpPt8g0CfnhI\nAWMviXbrYquAM7BLdytb5jr5n2Q=\n' WHERE `id` = 6[0m
|
|
40
|
+
[4;36;1mSQL (4.0ms)[0m [0;1mCOMMIT[0m
|
|
41
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
42
|
+
[4;36;1mUser Create (0.1ms)[0m [0;1mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES(NULL, NULL, NULL, 'john')[0m
|
|
43
|
+
[4;35;1mSQL (0.3ms)[0m [0mCOMMIT[0m
|
|
44
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
45
|
+
[4;35;1mSQL (0.1ms)[0m [0mCOMMIT[0m
|
|
46
|
+
[4;36;1mUser Load (0.1ms)[0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 2) [0m
|
|
47
|
+
[4;35;1mUser Load (0.1ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 2) [0m
|
|
48
|
+
[4;36;1mUser Load (0.1ms)[0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
|
|
49
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
|
|
50
|
+
[4;35;1mSQL (0.2ms)[0m [0mSHOW TABLES[0m
|
|
51
|
+
[4;36;1mSQL (1.0ms)[0m [0;1mDROP TABLE `users`[0m
|
|
52
|
+
[4;35;1mSQL (13.8ms)[0m [0mCREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `password` varchar(255), `creditcard` varchar(255), `login` varchar(50), `type` varchar(20)) ENGINE=InnoDB[0m
|
|
53
|
+
[4;36;1mSQL (0.2ms)[0m [0;1mSHOW TABLES[0m
|
|
54
|
+
[4;35;1mSQL (0.1ms)[0m [0mSELECT version FROM `schema_migrations`[0m
|
|
55
|
+
[4;36;1mUser Columns (1.1ms)[0m [0;1mSHOW FIELDS FROM `users`[0m
|
|
56
|
+
[4;35;1mUser Load (0.1ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 2) [0m
|
|
57
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
58
|
+
[4;35;1mUser Create (0.2ms)[0m [0mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES('CFwibEgT2ZiukiGmrrzWfobM1JY7tvpIx1C9C1pMiJLVOFeeZjCCl2yOWK1x\nkDrhD9dIGMP9KUCzt+tD3eLkd0s=\n', NULL, NULL, 'jones')[0m
|
|
59
|
+
[4;36;1mSQL (2.0ms)[0m [0;1mCOMMIT[0m
|
|
60
|
+
[4;35;1mUser Load (0.2ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 3) [0m
|
|
61
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
62
|
+
[4;35;1mUser Update (0.2ms)[0m [0mUPDATE `users` SET `creditcard` = 'CE1gz6XCWrmFybA6+rfMKBsoZBI0wYCkyzF0gTY4Ezvui4eD+BlJpzHRc4r8\nFoso0a+kCji4YlIYjlHzgq91diM=\n' WHERE `id` = 3[0m
|
|
63
|
+
[4;36;1mSQL (0.3ms)[0m [0;1mCOMMIT[0m
|
|
64
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
65
|
+
[4;36;1mUser Create (0.1ms)[0m [0;1mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES(NULL, NULL, NULL, 'jones')[0m
|
|
66
|
+
[4;35;1mSQL (0.3ms)[0m [0mCOMMIT[0m
|
|
67
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
68
|
+
[4;35;1mUser Update (0.1ms)[0m [0mUPDATE `users` SET `creditcard` = 'CHdTf8FCscyUXvzsVeT6PsRitL2S9C1J04HXkHJPX8rg85SDP2D0st+6oO4E\n1DiWbR6S01TSEHsbGMld29lA/60=\n' WHERE `id` = 4[0m
|
|
69
|
+
[4;36;1mSQL (26.0ms)[0m [0;1mCOMMIT[0m
|
|
70
|
+
[4;35;1mUser Load (0.2ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 4) [0m
|
|
71
|
+
[4;36;1mUser Load (0.1ms)[0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
|
|
72
|
+
[4;35;1mUser Load (0.1ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 2) [0m
|
|
73
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
74
|
+
[4;35;1mUser Create (0.1ms)[0m [0mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES(NULL, NULL, NULL, 'jones')[0m
|
|
75
|
+
[4;36;1mSQL (0.4ms)[0m [0;1mCOMMIT[0m
|
|
76
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
77
|
+
[4;36;1mUser Update (0.2ms)[0m [0;1mUPDATE `users` SET `creditcard` = 'CIC0NJ/fXURRYVa0VAoeYsMTXRV9eB6gFI84jWIdk6RFyQPoLF779EZ1FICI\ny4+7abuWMpdYI/wN6ySL7rMcb9w=\n' WHERE `id` = 5[0m
|
|
78
|
+
[4;35;1mSQL (3.8ms)[0m [0mCOMMIT[0m
|
|
79
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
80
|
+
[4;35;1mUser Create (0.1ms)[0m [0mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES(NULL, NULL, NULL, 'jones')[0m
|
|
81
|
+
[4;36;1mSQL (3.5ms)[0m [0;1mCOMMIT[0m
|
|
82
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
83
|
+
[4;36;1mUser Update (0.2ms)[0m [0;1mUPDATE `users` SET `creditcard` = 'CDlCzHCRQpVrhSHmqJJ9/l2s3/GM4lsWWNLN9sMKZlZs5u+3Ljndl4JL5GIA\n95pr3jCHIJULyG+OmFEB/TtHnPE=\n' WHERE `id` = 6[0m
|
|
84
|
+
[4;35;1mSQL (0.5ms)[0m [0mCOMMIT[0m
|
|
85
|
+
[4;36;1mSQL (0.0ms)[0m [0;1mBEGIN[0m
|
|
86
|
+
[4;35;1mUser Create (0.1ms)[0m [0mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES(NULL, NULL, NULL, 'john')[0m
|
|
87
|
+
[4;36;1mSQL (1.1ms)[0m [0;1mCOMMIT[0m
|
|
88
|
+
[4;35;1mSQL (0.0ms)[0m [0mBEGIN[0m
|
|
89
|
+
[4;36;1mSQL (0.0ms)[0m [0;1mCOMMIT[0m
|
|
90
|
+
[4;35;1mUser Load (0.1ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 2) [0m
|
|
91
|
+
[4;36;1mUser Load (0.1ms)[0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 2) [0m
|
|
92
|
+
[4;35;1mUser Load (0.2ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
|
|
93
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
|
|
94
|
+
[4;35;1mSQL (0.2ms)[0m [0mSHOW TABLES[0m
|
|
95
|
+
[4;36;1mSQL (1.1ms)[0m [0;1mDROP TABLE `users`[0m
|
|
96
|
+
[4;35;1mSQL (1.2ms)[0m [0mCREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `password` varchar(255), `creditcard` varchar(255), `login` varchar(50), `type` varchar(20)) ENGINE=InnoDB[0m
|
|
97
|
+
[4;36;1mSQL (0.2ms)[0m [0;1mSHOW TABLES[0m
|
|
98
|
+
[4;35;1mSQL (0.2ms)[0m [0mSELECT version FROM `schema_migrations`[0m
|
|
99
|
+
[4;36;1mUser Columns (1.0ms)[0m [0;1mSHOW FIELDS FROM `users`[0m
|
|
100
|
+
[4;35;1mUser Load (0.2ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 2) [0m
|
|
101
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
102
|
+
[4;35;1mUser Create (0.2ms)[0m [0mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES('CBH52Y1v8ftBqQbAmiw+ZN7QT/3/qzAG6jMvk47buwvy3fP07e+U1kVKp7pe\n/1mOY7L6V5zp7518tliO+QdH5F8=\n', NULL, NULL, 'jones')[0m
|
|
103
|
+
[4;36;1mSQL (20.3ms)[0m [0;1mCOMMIT[0m
|
|
104
|
+
[4;35;1mUser Load (0.3ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 3) [0m
|
|
105
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
106
|
+
[4;35;1mUser Update (0.2ms)[0m [0mUPDATE `users` SET `creditcard` = 'CHmkOdRkoQ8GuXzGusK+KtOT8WXgmwIje6lpKJCa+lu7s13QqUDIHGF0DUaU\njT5T5+qJarHI1UMeExWSHnCidHU=\n' WHERE `id` = 3[0m
|
|
107
|
+
[4;36;1mSQL (4.2ms)[0m [0;1mCOMMIT[0m
|
|
108
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
109
|
+
[4;36;1mUser Create (0.1ms)[0m [0;1mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES(NULL, NULL, NULL, 'jones')[0m
|
|
110
|
+
[4;35;1mSQL (3.6ms)[0m [0mCOMMIT[0m
|
|
111
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
112
|
+
[4;35;1mUser Update (0.2ms)[0m [0mUPDATE `users` SET `creditcard` = 'CBlTqEXFGU9LsAHf/tqd4QoHXD/JAJMflrdPJ7SQFnChy/2n4TlgCutLDiKg\n+bmBwuRJJLnWwUuAz2V1StdlahM=\n' WHERE `id` = 4[0m
|
|
113
|
+
[4;36;1mSQL (0.4ms)[0m [0;1mCOMMIT[0m
|
|
114
|
+
[4;35;1mUser Load (0.2ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 4) [0m
|
|
115
|
+
[4;36;1mUser Load (0.1ms)[0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
|
|
116
|
+
[4;35;1mUser Load (0.1ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 2) [0m
|
|
117
|
+
[4;36;1mSQL (0.0ms)[0m [0;1mBEGIN[0m
|
|
118
|
+
[4;35;1mUser Create (0.1ms)[0m [0mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES(NULL, NULL, NULL, 'jones')[0m
|
|
119
|
+
[4;36;1mSQL (0.3ms)[0m [0;1mCOMMIT[0m
|
|
120
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
121
|
+
[4;36;1mUser Update (0.1ms)[0m [0;1mUPDATE `users` SET `creditcard` = 'CJrq1AN1IcB/ySMbQXZup1RpnVlTu9t5RzITZ8tUsqdLQUuUAxXaXmvSMQ/W\nkg6p50EZrDRqgNy3Wwhs6VVDhfw=\n' WHERE `id` = 5[0m
|
|
122
|
+
[4;35;1mSQL (0.3ms)[0m [0mCOMMIT[0m
|
|
123
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
124
|
+
[4;35;1mUser Create (0.1ms)[0m [0mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES(NULL, NULL, NULL, 'jones')[0m
|
|
125
|
+
[4;36;1mSQL (0.3ms)[0m [0;1mCOMMIT[0m
|
|
126
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
127
|
+
[4;36;1mUser Update (0.1ms)[0m [0;1mUPDATE `users` SET `creditcard` = 'CKSt80/PI5nTJqxZXt9B70uIHTQDzE3Fu8rugIRXOdty0gRhMD6uddRCPnir\n5w0HjFN7H/jCIeHfjupxFTlaESw=\n' WHERE `id` = 6[0m
|
|
128
|
+
[4;35;1mSQL (21.8ms)[0m [0mCOMMIT[0m
|
|
129
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
130
|
+
[4;35;1mUser Create (0.1ms)[0m [0mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES(NULL, NULL, NULL, 'john')[0m
|
|
131
|
+
[4;36;1mSQL (3.1ms)[0m [0;1mCOMMIT[0m
|
|
132
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
133
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mCOMMIT[0m
|
|
134
|
+
[4;35;1mUser Load (0.1ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 2) [0m
|
|
135
|
+
[4;36;1mUser Load (0.1ms)[0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 2) [0m
|
|
136
|
+
[4;35;1mUser Load (0.1ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
|
|
137
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
|
|
138
|
+
[4;35;1mSQL (0.2ms)[0m [0mSHOW TABLES[0m
|
|
139
|
+
[4;36;1mSQL (1.1ms)[0m [0;1mDROP TABLE `users`[0m
|
|
140
|
+
[4;35;1mSQL (1.2ms)[0m [0mCREATE TABLE `users` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `password` varchar(255), `creditcard` varchar(255), `login` varchar(50), `type` varchar(20)) ENGINE=InnoDB[0m
|
|
141
|
+
[4;36;1mSQL (0.2ms)[0m [0;1mSHOW TABLES[0m
|
|
142
|
+
[4;35;1mSQL (0.1ms)[0m [0mSELECT version FROM `schema_migrations`[0m
|
|
143
|
+
[4;36;1mUser Columns (1.0ms)[0m [0;1mSHOW FIELDS FROM `users`[0m
|
|
144
|
+
[4;35;1mUser Load (0.1ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 2) [0m
|
|
145
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
146
|
+
[4;35;1mUser Create (0.1ms)[0m [0mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES('CHBD75M18kRhqolpWIH74E4RqwrUSb70NC8AN+XlrnpY1+W8b1SmiF01tCvk\npwIVB4YmN5I465+0d9g056QoKPc=\n', NULL, NULL, 'jones')[0m
|
|
147
|
+
[4;36;1mSQL (3.1ms)[0m [0;1mCOMMIT[0m
|
|
148
|
+
[4;35;1mUser Load (3.9ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 3) [0m
|
|
149
|
+
[4;36;1mSQL (1.2ms)[0m [0;1mBEGIN[0m
|
|
150
|
+
[4;35;1mUser Update (0.2ms)[0m [0mUPDATE `users` SET `creditcard` = 'CCvaVOholnuq41FcvUB2dkndppJ3hYxs6iycERN89tTC4FinoUFqoiM/3w72\njODz066XLTjxJ8rAxWYo5O9k42U=\n' WHERE `id` = 3[0m
|
|
151
|
+
[4;36;1mSQL (0.4ms)[0m [0;1mCOMMIT[0m
|
|
152
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
153
|
+
[4;36;1mUser Create (0.1ms)[0m [0;1mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES(NULL, NULL, NULL, 'jones')[0m
|
|
154
|
+
[4;35;1mSQL (0.3ms)[0m [0mCOMMIT[0m
|
|
155
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
156
|
+
[4;35;1mUser Update (0.1ms)[0m [0mUPDATE `users` SET `creditcard` = 'CFgvuQFPEQiMPVkTiysEpSrNJt9KLIAIQdN4FPHP1nMG5WXFLYmHLu6AdJg3\nb/MKH98D3IDJfc6Ci9l8V8wtaV8=\n' WHERE `id` = 4[0m
|
|
157
|
+
[4;36;1mSQL (32.3ms)[0m [0;1mCOMMIT[0m
|
|
158
|
+
[4;35;1mUser Load (0.2ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 4) [0m
|
|
159
|
+
[4;36;1mUser Load (0.1ms)[0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
|
|
160
|
+
[4;35;1mUser Load (0.2ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 2) [0m
|
|
161
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
162
|
+
[4;35;1mUser Create (0.1ms)[0m [0mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES(NULL, NULL, NULL, 'jones')[0m
|
|
163
|
+
[4;36;1mSQL (0.3ms)[0m [0;1mCOMMIT[0m
|
|
164
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
165
|
+
[4;36;1mUser Update (0.2ms)[0m [0;1mUPDATE `users` SET `creditcard` = 'CAtFGYw+FomeApMi+INaAlpQ2BIKCFUkkfMIUhdfFkohQYhYTaa/nd1/Mqi+\nGLPc1+LJQfbyCHMXoxwa4leHjjw=\n' WHERE `id` = 5[0m
|
|
166
|
+
[4;35;1mSQL (0.7ms)[0m [0mCOMMIT[0m
|
|
167
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
168
|
+
[4;35;1mUser Create (0.1ms)[0m [0mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES(NULL, NULL, NULL, 'jones')[0m
|
|
169
|
+
[4;36;1mSQL (7.3ms)[0m [0;1mCOMMIT[0m
|
|
170
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
171
|
+
[4;36;1mUser Update (0.3ms)[0m [0;1mUPDATE `users` SET `creditcard` = 'CK8GBBiDr2HHhbIK4yFfCzAGFkzRrwBcX3iOf1XMh+jEFSWvd78JzN18QGLc\nWoOxWNqmuDaUaIsmbGKAdV++d3A=\n' WHERE `id` = 6[0m
|
|
172
|
+
[4;35;1mSQL (0.4ms)[0m [0mCOMMIT[0m
|
|
173
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mBEGIN[0m
|
|
174
|
+
[4;35;1mUser Create (0.1ms)[0m [0mINSERT INTO `users` (`creditcard`, `type`, `password`, `login`) VALUES(NULL, NULL, NULL, 'john')[0m
|
|
175
|
+
[4;36;1mSQL (0.3ms)[0m [0;1mCOMMIT[0m
|
|
176
|
+
[4;35;1mSQL (0.1ms)[0m [0mBEGIN[0m
|
|
177
|
+
[4;36;1mSQL (0.1ms)[0m [0;1mCOMMIT[0m
|
|
178
|
+
[4;35;1mUser Load (0.1ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 2) [0m
|
|
179
|
+
[4;36;1mUser Load (0.1ms)[0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 2) [0m
|
|
180
|
+
[4;35;1mUser Load (0.1ms)[0m [0mSELECT * FROM `users` WHERE (`users`.`id` = 1) [0m
|
data/test/fixtures/user.rb
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
class User < ActiveRecord::Base
|
|
2
|
-
|
|
2
|
+
#define_read_methods
|
|
3
|
+
asymmetrically_encrypts :creditcard
|
|
3
4
|
|
|
4
|
-
def self.validates_password
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
end
|
|
5
|
+
#def self.validates_password
|
|
6
|
+
# validates_presence_of :password
|
|
7
|
+
# validates_presence_of :password, :on => :create
|
|
8
|
+
# validates_length_of :password, :in => 4..40
|
|
9
|
+
#end
|
|
9
10
|
end
|
|
10
11
|
|
|
11
|
-
class ShaUser < User
|
|
12
|
-
validates_password
|
|
13
|
-
validates_confirmation_of :password
|
|
14
|
-
generates_crypted :password # sha is used by default
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
class DangerousUser < User # no password confirmation
|
|
18
|
-
|
|
19
|
-
generates_crypted :password
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
class SymmetricUser < User
|
|
23
|
-
validates_password
|
|
24
|
-
generates_crypted :password, :mode => :symmetric
|
|
25
|
-
end
|
|
12
|
+
#class ShaUser < User
|
|
13
|
+
# validates_password
|
|
14
|
+
# validates_confirmation_of :password
|
|
15
|
+
# generates_crypted :password # sha is used by default
|
|
16
|
+
#end
|
|
17
|
+
#
|
|
18
|
+
#class DangerousUser < User # no password confirmation
|
|
19
|
+
## validates_password
|
|
20
|
+
# generates_crypted :password
|
|
21
|
+
#end
|
|
22
|
+
#
|
|
23
|
+
#class SymmetricUser < User
|
|
24
|
+
# validates_password
|
|
25
|
+
# generates_crypted :password, :mode => :symmetric
|
|
26
|
+
#end
|
data/test/fixtures/users.yml
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
user_1:
|
|
2
2
|
id: 1
|
|
3
3
|
login: bob
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type: SymmetricUser
|
|
4
|
+
password: "0XlmUuNpE2k=\n"
|
|
5
|
+
creditcard: "CBUI2TcYh/ATRB7fYpDBb0t1ifOWPb5jfpO2M8Zy9D/8Gua6/uA+ILHwKtGY\nOgrooPYSxwpBzEZoH18mXqJE7yk=\n" # "sentry" with 8 characters of prepadding
|
|
7
6
|
user_2:
|
|
8
7
|
id: 2
|
|
9
8
|
login: fred
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
creditcard: "CEUx1Ufxi7leQVp0xHhMWKqBcvrb0p3VvX5rqJBXSwddH+Alscs73TEX8Ctn\n9WnV5Ii8txpa20UfM3h5msLpm20=\n" # "sentry" with 8 different characters of prepadding
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'abstract_unit'
|
|
2
|
+
|
|
3
|
+
class RsaKeyTest < Test::Unit::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
@public_key = OpenSSL::PKey::RSA.new(File.open(File.dirname(__FILE__) + '/keys/encrypted_public') { |f| f.read })
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def test_can_find_max_encoded_length_for_key
|
|
9
|
+
assert_equal 53, @public_key.max_encryptable_length
|
|
10
|
+
end
|
|
11
|
+
end
|
data/test/schema.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
ActiveRecord::Schema.define(:version => 1) do
|
|
2
2
|
|
|
3
3
|
create_table "users", :force => true do |t|
|
|
4
|
-
t.column :
|
|
5
|
-
t.column :
|
|
4
|
+
t.column :password, :string, :limit => 255
|
|
5
|
+
t.column :creditcard, :string, :limit => 255
|
|
6
6
|
t.column :login, :string, :limit => 50
|
|
7
7
|
t.column :type, :string, :limit => 20
|
|
8
8
|
end
|
data/test/sha_sentry_test.rb
CHANGED
|
@@ -2,30 +2,34 @@ require 'abstract_unit'
|
|
|
2
2
|
require 'fixtures/user'
|
|
3
3
|
|
|
4
4
|
class ShaSentryTest < Test::Unit::TestCase
|
|
5
|
-
def
|
|
6
|
-
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def test_should_encrypt
|
|
10
|
-
assert_equal 'f438229716cab43569496f3a3630b3727524b81b', Sentry::ShaSentry.encrypt('test')
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def test_should_encrypt_with_salt
|
|
14
|
-
Sentry::ShaSentry.salt = 'different salt'
|
|
15
|
-
assert_equal '18e3256d71529db8fa65b2eef24a69ddad7070f3', Sentry::ShaSentry.encrypt('test')
|
|
5
|
+
def test_foo
|
|
6
|
+
assert true
|
|
16
7
|
end
|
|
17
8
|
|
|
18
|
-
def
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
9
|
+
#def setup
|
|
10
|
+
# Sentry::ShaSentry.salt = 'salt'
|
|
11
|
+
#end
|
|
12
|
+
#
|
|
13
|
+
#def test_should_encrypt
|
|
14
|
+
# assert_equal 'f438229716cab43569496f3a3630b3727524b81b', Sentry::ShaSentry.encrypt('test')
|
|
15
|
+
#end
|
|
16
|
+
#
|
|
17
|
+
#def test_should_encrypt_with_salt
|
|
18
|
+
# Sentry::ShaSentry.salt = 'different salt'
|
|
19
|
+
# assert_equal '18e3256d71529db8fa65b2eef24a69ddad7070f3', Sentry::ShaSentry.encrypt('test')
|
|
20
|
+
#end
|
|
21
|
+
#
|
|
22
|
+
#def test_should_encrypt_user_password
|
|
23
|
+
# u = ShaUser.new :login => 'bob'
|
|
24
|
+
# u.password = u.password_confirmation = 'test'
|
|
25
|
+
# assert u.save
|
|
26
|
+
# assert u.crypted_password = 'f438229716cab43569496f3a3630b3727524b81b'
|
|
27
|
+
#end
|
|
28
|
+
#
|
|
29
|
+
#def test_should_encrypt_user_password_without_confirmation
|
|
30
|
+
# u = DangerousUser.new :login => 'bob'
|
|
31
|
+
# u.password = 'test'
|
|
32
|
+
# assert u.save
|
|
33
|
+
# assert u.crypted_password = 'f438229716cab43569496f3a3630b3727524b81b'
|
|
34
|
+
#end
|
|
31
35
|
end
|
|
@@ -1,33 +1,38 @@
|
|
|
1
1
|
require 'abstract_unit'
|
|
2
2
|
require 'fixtures/user'
|
|
3
3
|
|
|
4
|
-
class SymmetricSentryCallbackTest <
|
|
5
|
-
fixtures :users
|
|
6
|
-
|
|
4
|
+
class SymmetricSentryCallbackTest < ActiveSupport::TestCase
|
|
5
|
+
#fixtures :users
|
|
6
|
+
#
|
|
7
7
|
def setup
|
|
8
|
+
super
|
|
8
9
|
@str = 'sentry'
|
|
9
10
|
Sentry::SymmetricSentry.default_key = @key = 'secret'
|
|
10
11
|
@encrypted = "0XlmUuNpE2k=\n"
|
|
11
12
|
end
|
|
12
|
-
|
|
13
|
-
def
|
|
14
|
-
|
|
15
|
-
u.password = @str
|
|
16
|
-
assert u.save
|
|
17
|
-
assert_equal @encrypted, u.crypted_password
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def test_should_decrypted_user_password
|
|
21
|
-
assert_equal @str, users(:user_1).password
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def test_should_return_nil_on_invalid_key
|
|
25
|
-
Sentry::SymmetricSentry.default_key = 'other secret'
|
|
26
|
-
assert_nil users(:user_1).password
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def test_should_raise_error_on_invalid_key
|
|
30
|
-
Sentry::SymmetricSentry.default_key = 'other secret'
|
|
31
|
-
assert_raises(OpenSSL::CipherError) { users(:user_1).password! }
|
|
13
|
+
|
|
14
|
+
def test_foo
|
|
15
|
+
assert true
|
|
32
16
|
end
|
|
17
|
+
#
|
|
18
|
+
#def test_should_encrypt_user_password
|
|
19
|
+
# u = SymmetricUser.new :login => 'bob'
|
|
20
|
+
# u.password = @str
|
|
21
|
+
# assert u.save
|
|
22
|
+
# assert_equal @encrypted, u.crypted_password
|
|
23
|
+
#end
|
|
24
|
+
#
|
|
25
|
+
#def test_should_decrypted_user_password
|
|
26
|
+
# assert_equal @str, users(:user_1).password
|
|
27
|
+
#end
|
|
28
|
+
#
|
|
29
|
+
#def test_should_return_nil_on_invalid_key
|
|
30
|
+
# Sentry::SymmetricSentry.default_key = 'other secret'
|
|
31
|
+
# assert_nil users(:user_1).password
|
|
32
|
+
#end
|
|
33
|
+
#
|
|
34
|
+
#def test_should_raise_error_on_invalid_key
|
|
35
|
+
# Sentry::SymmetricSentry.default_key = 'other secret'
|
|
36
|
+
# assert_raises(OpenSSL::CipherError) { users(:user_1).password! }
|
|
37
|
+
#end
|
|
33
38
|
end
|
metadata
CHANGED
|
@@ -1,68 +1,82 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
|
-
rubygems_version: 0.8.10
|
|
3
|
-
specification_version: 1
|
|
4
2
|
name: sentry
|
|
5
3
|
version: !ruby/object:Gem::Version
|
|
6
|
-
version: 0.3
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
- lib
|
|
11
|
-
email: technoweenie@gmail.com
|
|
12
|
-
homepage: http://techno-weenie.net
|
|
13
|
-
rubyforge_project:
|
|
14
|
-
description:
|
|
4
|
+
version: 0.5.3
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Rick Olson
|
|
15
8
|
autorequire: sentry
|
|
16
|
-
default_executable:
|
|
17
9
|
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-11-02 00:00:00 -08:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description:
|
|
17
|
+
email: technoweenie@gmail.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files: []
|
|
23
|
+
|
|
24
|
+
files:
|
|
25
|
+
- lib/active_record/sentry.rb
|
|
26
|
+
- lib/sentry/asymmetric_sentry.rb
|
|
27
|
+
- lib/sentry/asymmetric_sentry_callback.rb
|
|
28
|
+
- lib/sentry/sha_sentry.rb
|
|
29
|
+
- lib/sentry/symmetric_sentry.rb
|
|
30
|
+
- lib/sentry/symmetric_sentry_callback.rb
|
|
31
|
+
- lib/sentry.rb
|
|
32
|
+
- test/abstract_unit.rb
|
|
33
|
+
- test/asymmetric_sentry_callback_test.rb
|
|
34
|
+
- test/asymmetric_sentry_test.rb
|
|
35
|
+
- test/database.yml
|
|
36
|
+
- test/debug.log
|
|
37
|
+
- test/fixtures/user.rb
|
|
38
|
+
- test/fixtures/users.yml
|
|
39
|
+
- test/keys/encrypted_private
|
|
40
|
+
- test/keys/encrypted_public
|
|
41
|
+
- test/keys/private
|
|
42
|
+
- test/keys/public
|
|
43
|
+
- test/rsa_key_test.rb
|
|
44
|
+
- test/schema.rb
|
|
45
|
+
- test/sha_sentry_test.rb
|
|
46
|
+
- test/symmetric_sentry_callback_test.rb
|
|
47
|
+
- test/symmetric_sentry_test.rb
|
|
48
|
+
- test/tests.rb
|
|
49
|
+
- README
|
|
50
|
+
- MIT-LICENSE
|
|
51
|
+
- CHANGELOG
|
|
52
|
+
- RUNNING_UNIT_TESTS
|
|
18
53
|
has_rdoc: true
|
|
19
|
-
|
|
54
|
+
homepage: http://techno-weenie.net
|
|
55
|
+
licenses: []
|
|
56
|
+
|
|
57
|
+
post_install_message:
|
|
58
|
+
rdoc_options: []
|
|
59
|
+
|
|
60
|
+
require_paths:
|
|
61
|
+
- lib
|
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
20
63
|
requirements:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: "0"
|
|
67
|
+
version:
|
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
|
+
requirements:
|
|
70
|
+
- - ">="
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: "0"
|
|
25
73
|
version:
|
|
26
|
-
platform: ruby
|
|
27
|
-
authors:
|
|
28
|
-
- Rick Olson
|
|
29
|
-
files:
|
|
30
|
-
- lib/active_record
|
|
31
|
-
- lib/sentry
|
|
32
|
-
- lib/sentry.rb
|
|
33
|
-
- lib/active_record/sentry.rb
|
|
34
|
-
- lib/sentry/asymmetric_sentry.rb
|
|
35
|
-
- lib/sentry/asymmetric_sentry_callback.rb
|
|
36
|
-
- lib/sentry/sha_sentry.rb
|
|
37
|
-
- lib/sentry/symmetric_sentry.rb
|
|
38
|
-
- lib/sentry/symmetric_sentry_callback.rb
|
|
39
|
-
- test/abstract_unit.rb
|
|
40
|
-
- test/asymmetric_sentry_callback_test.rb
|
|
41
|
-
- test/asymmetric_sentry_test.rb
|
|
42
|
-
- test/database.yml
|
|
43
|
-
- test/debug.log
|
|
44
|
-
- test/fixtures
|
|
45
|
-
- test/keys
|
|
46
|
-
- test/schema.rb
|
|
47
|
-
- test/sha_sentry_test.rb
|
|
48
|
-
- test/symmetric_sentry_callback_test.rb
|
|
49
|
-
- test/symmetric_sentry_test.rb
|
|
50
|
-
- test/tests.rb
|
|
51
|
-
- test/fixtures/user.rb
|
|
52
|
-
- test/fixtures/users.yml
|
|
53
|
-
- test/keys/encrypted_private
|
|
54
|
-
- test/keys/encrypted_public
|
|
55
|
-
- test/keys/private
|
|
56
|
-
- test/keys/public
|
|
57
|
-
- README
|
|
58
|
-
- MIT-LICENSE
|
|
59
|
-
- CHANGELOG
|
|
60
|
-
- RUNNING_UNIT_TESTS
|
|
61
|
-
test_files:
|
|
62
|
-
- test/tests.rb
|
|
63
|
-
rdoc_options: []
|
|
64
|
-
extra_rdoc_files: []
|
|
65
|
-
executables: []
|
|
66
|
-
extensions: []
|
|
67
74
|
requirements: []
|
|
68
|
-
|
|
75
|
+
|
|
76
|
+
rubyforge_project:
|
|
77
|
+
rubygems_version: 1.3.5
|
|
78
|
+
signing_key:
|
|
79
|
+
specification_version: 3
|
|
80
|
+
summary: Sentry provides painless encryption services with a wrapper around some OpenSSL classes
|
|
81
|
+
test_files:
|
|
82
|
+
- test/tests.rb
|