encrypted_attributes 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/Rakefile +2 -2
- data/lib/encrypted_attributes.rb +6 -6
- data/test/factory.rb +5 -1
- data/test/test_helper.rb +1 -1
- data/test/unit/encrypted_attributes_test.rb +4 -4
- data/test/unit/sha_encryptor_test.rb +2 -2
- metadata +4 -7
- data/test/app_root/script/console +0 -8
- data/test/app_root/script/rails_framework_root.rb +0 -1
data/CHANGELOG.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -5,11 +5,11 @@ require 'rake/contrib/sshpublisher'
|
|
5
5
|
|
6
6
|
spec = Gem::Specification.new do |s|
|
7
7
|
s.name = 'encrypted_attributes'
|
8
|
-
s.version = '0.1.
|
8
|
+
s.version = '0.1.3'
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.summary = 'Adds support for automatically encrypting ActiveRecord attributes'
|
11
11
|
|
12
|
-
s.files = FileList['{lib,test}/**/*']
|
12
|
+
s.files = FileList['{lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}']
|
13
13
|
s.require_path = 'lib'
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.test_files = Dir['test/**/*_test.rb']
|
data/lib/encrypted_attributes.rb
CHANGED
@@ -3,10 +3,6 @@ require 'encrypted_attributes/sha_encryptor'
|
|
3
3
|
|
4
4
|
module PluginAWeek #:nodoc:
|
5
5
|
module EncryptedAttributes
|
6
|
-
def self.included(base) #:nodoc:
|
7
|
-
base.extend(MacroMethods)
|
8
|
-
end
|
9
|
-
|
10
6
|
module MacroMethods
|
11
7
|
# Encrypts the specified attribute.
|
12
8
|
#
|
@@ -127,7 +123,11 @@ module PluginAWeek #:nodoc:
|
|
127
123
|
value = read_attribute(to_attr_name)
|
128
124
|
|
129
125
|
# Make sure we set the encryptor for equality comparison when reading
|
130
|
-
# from the database
|
126
|
+
# from the database. This should only be done if the value is *not*
|
127
|
+
# blank, is *not* encrypted, and hasn't changed since it was read from
|
128
|
+
# the database. The dirty checking is important when the encypted value
|
129
|
+
# is written to the same attribute as the unencrypted value (i.e. you
|
130
|
+
# don't want to encrypt when a new value has been set)
|
131
131
|
unless value.blank? || value.encrypted? || attribute_changed?(to_attr_name)
|
132
132
|
# Create the encryptor configured for this attribute
|
133
133
|
value.encryptor = create_encryptor(encryptor_class, options, :read, value)
|
@@ -151,5 +151,5 @@ module PluginAWeek #:nodoc:
|
|
151
151
|
end
|
152
152
|
|
153
153
|
ActiveRecord::Base.class_eval do
|
154
|
-
|
154
|
+
extend PluginAWeek::EncryptedAttributes::MacroMethods
|
155
155
|
end
|
data/test/factory.rb
CHANGED
@@ -13,12 +13,16 @@ module Factory
|
|
13
13
|
def valid_attributes_for(model, attributes = {})
|
14
14
|
name = model.to_s.underscore
|
15
15
|
send("#{name}_attributes", attributes)
|
16
|
+
attributes.stringify_keys!
|
16
17
|
attributes
|
17
18
|
end
|
18
19
|
|
19
20
|
# Build an unsaved record
|
20
21
|
def new_record(model, *args)
|
21
|
-
|
22
|
+
attributes = valid_attributes_for(model, *args)
|
23
|
+
record = model.new(attributes)
|
24
|
+
attributes.each {|attr, value| record.send("#{attr}=", value) if model.accessible_attributes && !model.accessible_attributes.include?(attr) || model.protected_attributes && model.protected_attributes.include?(attr)}
|
25
|
+
record
|
22
26
|
end
|
23
27
|
|
24
28
|
# Build and save/reload a record
|
data/test/test_helper.rb
CHANGED
@@ -115,25 +115,25 @@ end
|
|
115
115
|
|
116
116
|
class EncryptedAttributesWithConditionalsTest < Test::Unit::TestCase
|
117
117
|
def test_should_not_encrypt_if_if_conditional_is_false
|
118
|
-
User.encrypts :password, :if =>
|
118
|
+
User.encrypts :password, :if => lambda {false}
|
119
119
|
user = create_user(:login => 'admin', :password => 'secret')
|
120
120
|
assert_equal 'secret', user.password
|
121
121
|
end
|
122
122
|
|
123
123
|
def test_should_encrypt_if_if_conditional_is_true
|
124
|
-
User.encrypts :password, :if =>
|
124
|
+
User.encrypts :password, :if => lambda {true}
|
125
125
|
user = create_user(:login => 'admin', :password => 'secret')
|
126
126
|
assert_equal '8152bc582f58c854f580cb101d3182813dec4afe', "#{user.password}"
|
127
127
|
end
|
128
128
|
|
129
129
|
def test_should_not_encrypt_if_unless_conditional_is_true
|
130
|
-
User.encrypts :password, :unless =>
|
130
|
+
User.encrypts :password, :unless => lambda {true}
|
131
131
|
user = create_user(:login => 'admin', :password => 'secret')
|
132
132
|
assert_equal 'secret', user.password
|
133
133
|
end
|
134
134
|
|
135
135
|
def test_should_encrypt_if_unless_conditional_is_false
|
136
|
-
User.encrypts :password, :unless =>
|
136
|
+
User.encrypts :password, :unless => lambda {false}
|
137
137
|
user = create_user(:login => 'admin', :password => 'secret')
|
138
138
|
assert_equal '8152bc582f58c854f580cb101d3182813dec4afe', "#{user.password}"
|
139
139
|
end
|
@@ -16,13 +16,13 @@ class ShaEncryptorOnWriteTest < Test::Unit::TestCase
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_should_allow_block_salt
|
19
|
-
dynamic_salt =
|
19
|
+
dynamic_salt = lambda {|user| user.login}
|
20
20
|
encryptor = PluginAWeek::EncryptedAttributes::ShaEncryptor.new(@user, 'password', :write, :salt => dynamic_salt)
|
21
21
|
assert_equal 'admin', encryptor.salt
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_should_allow_dynamic_nil_salt
|
25
|
-
dynamic_salt =
|
25
|
+
dynamic_salt = lambda {|user| nil}
|
26
26
|
encryptor = PluginAWeek::EncryptedAttributes::ShaEncryptor.new(@user, 'password', :write, :salt => dynamic_salt)
|
27
27
|
assert_equal '', encryptor.salt
|
28
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: encrypted_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Pfeifer
|
@@ -9,11 +9,12 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-10-26 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: encrypted_strings
|
17
|
+
type: :runtime
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
@@ -37,15 +38,11 @@ files:
|
|
37
38
|
- test/app_root/app
|
38
39
|
- test/app_root/app/models
|
39
40
|
- test/app_root/app/models/user.rb
|
40
|
-
- test/app_root/script
|
41
|
-
- test/app_root/script/rails_framework_root.rb
|
42
|
-
- test/app_root/script/console
|
43
41
|
- test/app_root/config
|
44
42
|
- test/app_root/config/environment.rb
|
45
43
|
- test/app_root/db
|
46
44
|
- test/app_root/db/migrate
|
47
45
|
- test/app_root/db/migrate/001_create_users.rb
|
48
|
-
- test/app_root/log
|
49
46
|
- test/keys
|
50
47
|
- test/keys/private
|
51
48
|
- test/keys/public
|
@@ -81,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
78
|
requirements: []
|
82
79
|
|
83
80
|
rubyforge_project: pluginaweek
|
84
|
-
rubygems_version: 1.
|
81
|
+
rubygems_version: 1.2.0
|
85
82
|
signing_key:
|
86
83
|
specification_version: 2
|
87
84
|
summary: Adds support for automatically encrypting ActiveRecord attributes
|
@@ -1,8 +0,0 @@
|
|
1
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
2
|
-
libs = " -r irb/completion"
|
3
|
-
libs << " -r test/app_root/script/rails_framework_root"
|
4
|
-
libs << " -r test/test_helper"
|
5
|
-
libs << " -r plugin_test_helper/console_with_fixtures"
|
6
|
-
libs << " -r console_app"
|
7
|
-
libs << " -r console_with_helpers"
|
8
|
-
exec "#{irb} #{libs} --simple-prompt"
|
@@ -1 +0,0 @@
|
|
1
|
-
RAILS_FRAMEWORK_ROOT = '/home/aaron/Projects/Vendor/rails'
|