spectator-attr_encrypted 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,52 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ DataMapper.setup(:default, "sqlite3::memory:")
4
+
5
+ class Client
6
+ include DataMapper::Resource
7
+
8
+ property :id, Serial
9
+ property :encrypted_email, String
10
+ property :encrypted_credentials, Text
11
+ property :salt, String
12
+
13
+ attr_encrypted :email, :key => 'a secret key'
14
+ attr_encrypted :credentials, :key => Proc.new { |client| Encryptor.encrypt(:value => client.salt, :key => 'some private key') }, :marshal => true
15
+
16
+ def initialize(attrs = {})
17
+ super attrs
18
+ self.salt ||= Digest::SHA1.hexdigest((Time.now.to_i * rand(5)).to_s)
19
+ self.credentials ||= { :username => 'example', :password => 'test' }
20
+ end
21
+ end
22
+
23
+ DataMapper.auto_migrate!
24
+
25
+ class DataMapperTest < Test::Unit::TestCase
26
+
27
+ def setup
28
+ Client.all.each(&:destroy)
29
+ end
30
+
31
+ def test_should_encrypt_email
32
+ @client = Client.new :email => 'test@example.com'
33
+ assert @client.save
34
+ assert_not_nil @client.encrypted_email
35
+ assert_not_equal @client.email, @client.encrypted_email
36
+ assert_equal @client.email, Client.first.email
37
+ end
38
+
39
+ def test_should_marshal_and_encrypt_credentials
40
+ @client = Client.new
41
+ assert @client.save
42
+ assert_not_nil @client.encrypted_credentials
43
+ assert_not_equal @client.credentials, @client.encrypted_credentials
44
+ assert_equal @client.credentials, Client.first.credentials
45
+ assert Client.first.credentials.is_a?(Hash)
46
+ end
47
+
48
+ def test_should_encode_by_default
49
+ assert Client.attr_encrypted_options[:encode]
50
+ end
51
+
52
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ DB = Sequel.sqlite
4
+
5
+ DB.create_table :humans do
6
+ primary_key :id
7
+ column :encrypted_email, :string
8
+ column :password, :string
9
+ column :encrypted_credentials, :string
10
+ column :salt, :string
11
+ end
12
+
13
+ class Human < Sequel::Model(:humans)
14
+ attr_encrypted :email, :key => 'a secret key'
15
+ attr_encrypted :credentials, :key => Proc.new { |human| Encryptor.encrypt(:value => human.salt, :key => 'some private key') }, :marshal => true
16
+
17
+ def after_initialize(attrs = {})
18
+ self.salt ||= Digest::SHA1.hexdigest((Time.now.to_i * rand(5)).to_s)
19
+ self.credentials ||= { :username => 'example', :password => 'test' }
20
+ end
21
+ end
22
+
23
+ class SequelTest < Test::Unit::TestCase
24
+
25
+ def setup
26
+ Human.all.each(&:destroy)
27
+ end
28
+
29
+ def test_should_encrypt_email
30
+ @human = Human.new :email => 'test@example.com'
31
+ assert @human.save
32
+ assert_not_nil @human.encrypted_email
33
+ assert_not_equal @human.email, @human.encrypted_email
34
+ assert_equal @human.email, Human.first.email
35
+ end
36
+
37
+ def test_should_marshal_and_encrypt_credentials
38
+ @human = Human.new
39
+ assert @human.save
40
+ assert_not_nil @human.encrypted_credentials
41
+ assert_not_equal @human.credentials, @human.encrypted_credentials
42
+ assert_equal @human.credentials, Human.first.credentials
43
+ assert Human.first.credentials.is_a?(Hash)
44
+ end
45
+
46
+ def test_should_encode_by_default
47
+ assert Human.attr_encrypted_options[:encode]
48
+ end
49
+
50
+ end
@@ -0,0 +1,10 @@
1
+ require 'test/unit'
2
+ require 'digest/sha2'
3
+
4
+ require 'rubygems'
5
+
6
+ require 'active_record'
7
+ require 'datamapper'
8
+ require 'sequel'
9
+
10
+ require File.expand_path('../../lib/attr_encrypted', __FILE__)
metadata ADDED
@@ -0,0 +1,242 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spectator-attr_encrypted
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 3
10
+ version: 1.1.3
11
+ platform: ruby
12
+ authors:
13
+ - Sean Huber
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-23 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: eigenclass
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 17
30
+ segments:
31
+ - 1
32
+ - 1
33
+ - 1
34
+ version: 1.1.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: encryptor
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 19
46
+ segments:
47
+ - 1
48
+ - 1
49
+ - 0
50
+ version: 1.1.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: appraisal
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ type: :development
80
+ version_requirements: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ name: mocha
83
+ prerelease: false
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ type: :development
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ name: rake
97
+ prerelease: false
98
+ requirement: &id006 !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ type: :development
108
+ version_requirements: *id006
109
+ - !ruby/object:Gem::Dependency
110
+ name: sequel
111
+ prerelease: false
112
+ requirement: &id007 !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ type: :development
122
+ version_requirements: *id007
123
+ - !ruby/object:Gem::Dependency
124
+ name: sqlite3-ruby
125
+ prerelease: false
126
+ requirement: &id008 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ hash: 3
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ type: :development
136
+ version_requirements: *id008
137
+ - !ruby/object:Gem::Dependency
138
+ name: datamapper
139
+ prerelease: false
140
+ requirement: &id009 !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ hash: 3
146
+ segments:
147
+ - 0
148
+ version: "0"
149
+ type: :development
150
+ version_requirements: *id009
151
+ - !ruby/object:Gem::Dependency
152
+ name: dm-sqlite-adapter
153
+ prerelease: false
154
+ requirement: &id010 !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ hash: 3
160
+ segments:
161
+ - 0
162
+ version: "0"
163
+ type: :development
164
+ version_requirements: *id010
165
+ - !ruby/object:Gem::Dependency
166
+ name: activerecord
167
+ prerelease: false
168
+ requirement: &id011 !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ hash: 3
174
+ segments:
175
+ - 0
176
+ version: "0"
177
+ type: :development
178
+ version_requirements: *id011
179
+ description: Generates attr_accessors that encrypt and decrypt attributes transparently. This fork is for Ruby 1.9 and Rails 3 compatibility.
180
+ email: shuber@huberry.com
181
+ executables: []
182
+
183
+ extensions: []
184
+
185
+ extra_rdoc_files: []
186
+
187
+ files:
188
+ - lib/attr_encrypted.rb
189
+ - lib/attr_encrypted/adapters/active_record.rb
190
+ - lib/attr_encrypted/adapters/data_mapper.rb
191
+ - lib/attr_encrypted/adapters/sequel.rb
192
+ - MIT-LICENSE
193
+ - Rakefile
194
+ - README.rdoc
195
+ - test/active_record_test.rb
196
+ - test/attr_encrypted_test.rb
197
+ - test/data_mapper_test.rb
198
+ - test/sequel_test.rb
199
+ - test/test_helper.rb
200
+ has_rdoc: true
201
+ homepage: http://github.com/shuber/attr_encrypted
202
+ licenses: []
203
+
204
+ post_install_message:
205
+ rdoc_options:
206
+ - --line-numbers
207
+ - --inline-source
208
+ - --main
209
+ - README.rdoc
210
+ require_paths:
211
+ - lib
212
+ required_ruby_version: !ruby/object:Gem::Requirement
213
+ none: false
214
+ requirements:
215
+ - - ">="
216
+ - !ruby/object:Gem::Version
217
+ hash: 3
218
+ segments:
219
+ - 0
220
+ version: "0"
221
+ required_rubygems_version: !ruby/object:Gem::Requirement
222
+ none: false
223
+ requirements:
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ hash: 3
227
+ segments:
228
+ - 0
229
+ version: "0"
230
+ requirements: []
231
+
232
+ rubyforge_project:
233
+ rubygems_version: 1.5.0
234
+ signing_key:
235
+ specification_version: 3
236
+ summary: Generates attr_accessors that encrypt and decrypt attributes transparently. This fork is for Ruby 1.9 and Rails 3 compatibility.
237
+ test_files:
238
+ - test/active_record_test.rb
239
+ - test/attr_encrypted_test.rb
240
+ - test/data_mapper_test.rb
241
+ - test/sequel_test.rb
242
+ - test/test_helper.rb