ezcrypto 0.3 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -161,7 +161,7 @@ the generate and with_password methods. This is not yet 100% complete.
161
161
  returns the Base64 encoded key.
162
162
  =end
163
163
  def encode
164
- Base64.encode64 @raw
164
+ Base64.encode64(@raw).chop
165
165
  end
166
166
 
167
167
  =begin rdoc
@@ -200,9 +200,11 @@ Decrypts the data passed to it in binary format.
200
200
  decrypter("")
201
201
  @cipher.gulp(data)
202
202
  end
203
- rescue
204
- puts @algorithm
205
- throw $!
203
+ # rescue
204
+ # puts @algorithm
205
+ # puts self.encode
206
+ # puts data.size
207
+ # throw $!
206
208
  end
207
209
 
208
210
  =begin rdoc
@@ -211,7 +213,22 @@ Decrypts a Base64 formatted string
211
213
  def decrypt64(data)
212
214
  decrypt(Base64.decode64(data))
213
215
  end
214
-
216
+
217
+ =begin rdoc
218
+ Allows keys to be marshalled
219
+ =end
220
+ def marshal_dump
221
+ "#{self.algorithm}$$$#{self.encode}"
222
+ end
223
+
224
+ =begin rdoc
225
+ Allows keys to be unmarshalled
226
+ =end
227
+ def marshal_load(s)
228
+ a, r = s.split '$$$'
229
+ @algorithm = a
230
+ @raw = Base64.decode64(r)
231
+ end
215
232
 
216
233
  =begin rdoc
217
234
  Create a file with minimal permissions, and yield
@@ -459,6 +476,8 @@ Processes the entire data string using update and performs a final on it returni
459
476
  def gulp(data)
460
477
  update(data)
461
478
  final
479
+ # rescue
480
+ # breakpoint
462
481
  end
463
482
 
464
483
  =begin rdoc
data/rakefile CHANGED
@@ -8,7 +8,7 @@ require 'rake/contrib/rubyforgepublisher'
8
8
 
9
9
  PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
10
10
  PKG_NAME = 'ezcrypto'
11
- PKG_VERSION = '0.3' + PKG_BUILD
11
+ PKG_VERSION = '0.5' + PKG_BUILD
12
12
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
13
13
 
14
14
  RELEASE_NAME = "REL #{PKG_VERSION}"
@@ -59,8 +59,9 @@ spec = Gem::Specification.new do |s|
59
59
  s.require_path = 'lib'
60
60
 
61
61
  s.files = [ "rakefile", "README", "README_ACTIVE_CRYPTO", "MIT-LICENSE","CHANGELOG","init.rb" ]
62
- s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "CVS" )||item.include?("\.DS_Store")||item.include?("/\._") }
63
- s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.include?( "CVS" )||item.include?("\.DS_Store")||item.include?("/\._") }
62
+ ["lib","test"].each do |dir|
63
+ s.files = s.files + Dir.glob( "#{dir}/*" )
64
+ end
64
65
  end
65
66
 
66
67
  Rake::GemPackageTask.new(spec) do |p|
@@ -70,7 +71,7 @@ Rake::GemPackageTask.new(spec) do |p|
70
71
  end
71
72
 
72
73
 
73
- desc "Publish the API documentation"
74
+ desc "Publish the GEM"
74
75
  task :pgem => [:package] do
75
76
  Rake::SshFilePublisher.new("pelleb@rubyforge.org", "/var/www/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
76
77
  end
@@ -81,8 +82,8 @@ task :pdoc => [:rdoc] do
81
82
  end
82
83
 
83
84
  desc "Publish the release files to RubyForge."
84
- task :release => [:package] do
85
- files = ["gem", "tgz", "zip"].map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" }
85
+ task :rubyforge_upload => :package do
86
+ files = %w(gem tgz zip).map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" }
86
87
 
87
88
  if RUBY_FORGE_PROJECT then
88
89
  require 'net/http'
@@ -144,7 +145,7 @@ task :release => [:package] do
144
145
  {
145
146
  "group_id" => group_id,
146
147
  "package_id" => package_id,
147
- "release_name" => RELEASE_NAME,
148
+ "release_name" => PKG_FILE_NAME,
148
149
  "release_date" => release_date,
149
150
  "type_id" => type,
150
151
  "processor_id" => "8000", # Any
@@ -3,6 +3,7 @@ require File.join(File.dirname(__FILE__), 'test_helper')
3
3
  require 'test/unit'
4
4
  require 'active_crypto'
5
5
 
6
+
6
7
  class User < ActiveRecord::Base
7
8
  has_many :secrets
8
9
  has_many :groups
@@ -41,6 +42,10 @@ class Asset<ActiveRecord::Base
41
42
 
42
43
  end
43
44
 
45
+ class AssetRaw<ActiveRecord::Base
46
+ set_table_name "assets"
47
+ end
48
+
44
49
  class Cap < ActiveRecord::Base
45
50
  belongs_to :asset
46
51
  encrypt :shared_key
@@ -93,15 +98,15 @@ class GroupSecret < ActiveRecord::Base
93
98
  end
94
99
 
95
100
  class ActiveCryptoTest < Test::Unit::TestCase
96
-
101
+
97
102
  def setup
98
103
  end
99
-
100
- def test_key_holder
104
+
105
+ def test_key_holder_in_record
101
106
  user=User.new
102
107
  user.name="bob"
103
108
  user.save
104
- assert user.kind_of?(ActiveRecord::Crypto::KeyHolder)
109
+ assert user.kind_of?(ActiveCrypto::KeyHolder)
105
110
  assert user.kind_of?(ActiveRecord::Base)
106
111
  assert user.kind_of?(User)
107
112
  assert_nil user.session_key
@@ -116,16 +121,16 @@ class ActiveCryptoTest < Test::Unit::TestCase
116
121
  assert_nil user.session_key
117
122
  user.enter_password "shhcccc"
118
123
  assert_not_nil user.session_key
119
- assert user.kind_of?(ActiveRecord::Crypto::KeyHolder)
124
+ assert user.kind_of?(ActiveCrypto::KeyHolder)
120
125
  assert user.kind_of?(ActiveRecord::Base)
121
126
  assert user.kind_of?(User)
122
127
 
123
128
  jill=user.secrets.create
124
129
 
125
130
  assert_not_nil jill
126
- assert jill.kind_of?(ActiveRecord::Crypto::AssociationKeyHolder)
127
- assert jill.kind_of?(ActiveRecord::Crypto::KeyHolder)
128
- assert jill.kind_of?(ActiveRecord::Crypto::Encrypted)
131
+ assert jill.kind_of?(ActiveCrypto::AssociationKeyHolder)
132
+ assert jill.kind_of?(ActiveCrypto::KeyHolder)
133
+ assert jill.kind_of?(ActiveCrypto::Encrypted)
129
134
  assert jill.kind_of?(ActiveRecord::Base)
130
135
  assert jill.kind_of?(Secret)
131
136
 
@@ -181,8 +186,16 @@ class ActiveCryptoTest < Test::Unit::TestCase
181
186
  cap=Cap.find_by_key key
182
187
  assert_not_nil cap
183
188
  assert_not_nil cap.asset
189
+
184
190
  assert_equal "title",cap.asset.title
191
+ assert_equal "title",cap.asset["title"]
185
192
  assert_equal "pelle@neubia.com",cap.email
193
+ assert_equal "pelle@neubia.com",cap["email"]
194
+
195
+ # Non decrypting version
196
+ raw=AssetRaw.find cap.asset.id
197
+ assert_not_equal "title",raw.title
198
+ assert_not_equal "title",raw["title"]
186
199
 
187
200
  bob_key=cap.asset.share("bob@bob.com")
188
201
  bob_cap=Cap.find_by_key bob_key
@@ -195,3 +208,4 @@ class ActiveCryptoTest < Test::Unit::TestCase
195
208
  end
196
209
  end
197
210
 
211
+
@@ -0,0 +1,38 @@
1
+ require 'key_holder_test'
2
+
3
+ class User < ActiveRecord::Base
4
+ keyholder
5
+ end
6
+
7
+ class AssociationKeyHolderTest < KeyHolderTest
8
+ def setup
9
+ @key_holder=User.create
10
+ end
11
+
12
+ def test_should_retain_session_key_on_reload
13
+ key=EzCrypto::Key.generate
14
+ key_holder.set_session_key key
15
+ assert_not_nil key_holder.session_key
16
+ assert_equal key.raw,key_holder.session_key.raw
17
+
18
+ reloaded=User.find key_holder.id
19
+ assert_not_nil reloaded.session_key
20
+ assert_equal key.raw,reloaded.session_key.raw
21
+ end
22
+
23
+ def test_should_retain_session_key_on_reload_for_record_with_key_set_before_create
24
+ key=EzCrypto::Key.generate
25
+ key_holder=User.new
26
+ assert_nil key_holder.session_key
27
+
28
+ key_holder.set_session_key key
29
+ assert_not_nil key_holder.session_key
30
+
31
+ assert_equal key.raw,key_holder.session_key.raw
32
+ key_holder.save
33
+
34
+ reloaded=User.find key_holder.id
35
+ assert_not_nil reloaded.session_key
36
+ assert_equal key.raw,reloaded.session_key.raw
37
+ end
38
+ end
@@ -0,0 +1,203 @@
1
+ # Logfile created on Mon Jun 26 23:08:41 CEST 2006 by logger.rb/1.5.2.7
2
+ Asset Columns (0.008388) SHOW FIELDS FROM assets
3
+ SQL (0.007744) BEGIN
4
+ SQL (0.001147) INSERT INTO assets (`updated_at`, `title`, `created_at`) VALUES('2006-06-26 23:08:42', x'9e98fee657d4d507013994fabe456bd5', '2006-06-26 23:08:42')
5
+ SQL (0.000677) COMMIT
6
+ Cap Columns (0.016698) SHOW FIELDS FROM caps
7
+ SQL (0.001026) BEGIN
8
+ SQL (0.001033) INSERT INTO caps (`updated_at`, `key_hash`, `shared_key`, `key`, `asset_id`, `created_at`, `email`) VALUES('2006-06-26 23:08:42', NULL, NULL, NULL, 67, '2006-06-26 23:08:42', 'pelle@neubia.com')
9
+ SQL (0.000552) COMMIT
10
+ SQL (0.000506) BEGIN
11
+ Cap Update (0.001911) UPDATE caps SET `created_at` = '2006-06-26 23:08:42', `key_hash` = '1568bd30ba9bd654d7afd8948304dde6b2caa7fd', `key` = NULL, `asset_id` = 67, `email` = 'pelle@neubia.com', `shared_key` = x'8bbdc3964a7cbe937101ca8cf774f7fe403a3e243d0c68f2042b7d48dac8e4ed', `updated_at` = '2006-06-26 23:08:42' WHERE id = 87
12
+ SQL (0.000556) COMMIT
13
+ Cap Load (0.002457) SELECT * FROM caps WHERE (caps.`key_hash` = '1568bd30ba9bd654d7afd8948304dde6b2caa7fd' ) LIMIT 1
14
+ Asset Load (0.001748) SELECT * FROM assets WHERE (assets.id = 67) LIMIT 1
15
+ AssetRaw Load (0.002112) SELECT * FROM assets WHERE (assets.id = 67) LIMIT 1
16
+ AssetRaw Columns (0.014849) SHOW FIELDS FROM assets
17
+ SQL (0.000775) BEGIN
18
+ SQL (0.001160) INSERT INTO caps (`updated_at`, `key_hash`, `shared_key`, `key`, `asset_id`, `created_at`, `email`) VALUES('2006-06-26 23:08:42', NULL, NULL, NULL, 67, '2006-06-26 23:08:42', 'bob@bob.com')
19
+ SQL (0.000532) COMMIT
20
+ SQL (0.000631) BEGIN
21
+ Cap Update (0.001192) UPDATE caps SET `created_at` = '2006-06-26 23:08:42', `key_hash` = 'a80ad191c09d4c2b673461436d3d184e42789b92', `key` = NULL, `asset_id` = 67, `email` = 'bob@bob.com', `shared_key` = x'82f7ba06662e9c4a8d69e8663f685a2de34b1ba7bf319e14e3ccbc06840db9ed', `updated_at` = '2006-06-26 23:08:42' WHERE id = 88
22
+ SQL (0.000567) COMMIT
23
+ Cap Load (0.003083) SELECT * FROM caps WHERE (caps.`key_hash` = 'a80ad191c09d4c2b673461436d3d184e42789b92' ) LIMIT 1
24
+ Asset Load (0.001744) SELECT * FROM assets WHERE (assets.id = 67) LIMIT 1
25
+ User Columns (0.014334) SHOW FIELDS FROM users
26
+ SQL (0.000734) BEGIN
27
+ SQL (0.001297) INSERT INTO users (`name`) VALUES(NULL)
28
+ SQL (0.000589) COMMIT
29
+ Secret Load (0.001915) SELECT * FROM secrets WHERE (secrets.user_id = 544) 
30
+ Secret Columns (0.032563) SHOW FIELDS FROM secrets
31
+ SQL (0.000623) BEGIN
32
+ SQL (0.001278) INSERT INTO secrets (`name`, `user_id`, `email`) VALUES(NULL, 544, NULL)
33
+ SQL (0.000528) COMMIT
34
+ User Load (0.001913) SELECT * FROM users WHERE (users.id = 544) LIMIT 1
35
+ SQL (0.069614) BEGIN
36
+ Secret Update (0.057050) UPDATE secrets SET `user_id` = 544, `email` = NULL, `name` = x'c42d49cb44c44d9e9288b5d94c6dda6b' WHERE id = 75
37
+ SQL (0.000469) COMMIT
38
+ Child Load (0.001575) SELECT * FROM children WHERE (children.secret_id = 75) 
39
+ Child Columns (0.007993) SHOW FIELDS FROM children
40
+ SQL (0.007694) BEGIN
41
+ SQL (0.000757) INSERT INTO children (`secret_id`, `email`) VALUES(75, NULL)
42
+ SQL (0.000372) COMMIT
43
+ SQL (0.000347) BEGIN
44
+ Secret Load (0.001658) SELECT * FROM secrets WHERE (secrets.id = 75) LIMIT 1
45
+ User Load (0.001475) SELECT * FROM users WHERE (users.id = 544) LIMIT 1
46
+ Child Update (0.001034) UPDATE children SET `secret_id` = 75, `email` = '�PI36ZՖt;&��(|nF/�o�x8�A�a��' WHERE id = 60
47
+ SQL (0.000413) COMMIT
48
+ SQL (0.000335) BEGIN
49
+ SQL (0.000778) INSERT INTO users (`name`) VALUES('bob')
50
+ SQL (0.000501) COMMIT
51
+ SQL (0.000452) BEGIN
52
+ SQL (0.072586) INSERT INTO users (`name`) VALUES(NULL)
53
+ SQL (0.000446) COMMIT
54
+ SQL (0.000440) BEGIN
55
+ SQL (0.000991) INSERT INTO users (`name`) VALUES(NULL)
56
+ SQL (0.000503) COMMIT
57
+ SQL (0.000475) BEGIN
58
+ SQL (0.000843) INSERT INTO users (`name`) VALUES(NULL)
59
+ SQL (0.000511) COMMIT
60
+ SQL (0.000485) BEGIN
61
+ SQL (0.000775) INSERT INTO users (`name`) VALUES(NULL)
62
+ SQL (0.000505) COMMIT
63
+ SQL (0.011066) BEGIN
64
+ SQL (0.000752) INSERT INTO users (`name`) VALUES(NULL)
65
+ SQL (0.000398) COMMIT
66
+ User Load (0.005141) SELECT * FROM users WHERE (users.id = 550) LIMIT 1
67
+ SQL (0.074907) BEGIN
68
+ SQL (0.000738) INSERT INTO users (`name`) VALUES(NULL)
69
+ SQL (0.000395) COMMIT
70
+ SQL (0.000370) BEGIN
71
+ SQL (0.000676) INSERT INTO users (`name`) VALUES(NULL)
72
+ SQL (0.000403) COMMIT
73
+ User Load (0.001184) SELECT * FROM users WHERE (users.id = 552) LIMIT 1
74
+ EncUser Columns (0.012070) SHOW FIELDS FROM users
75
+ SQL (0.022249) BEGIN
76
+ SQL (0.000759) INSERT INTO users (`name`) VALUES(NULL)
77
+ SQL (0.000368) COMMIT
78
+ SQL (0.000429) BEGIN
79
+ SQL (0.001092) INSERT INTO users (`name`) VALUES(NULL)
80
+ SQL (0.000379) COMMIT
81
+ SQL (0.000458) BEGIN
82
+ SQL (0.000688) INSERT INTO users (`name`) VALUES(NULL)
83
+ SQL (0.000370) COMMIT
84
+ SQL (0.003594) BEGIN
85
+ SQL (0.001030) INSERT INTO users (`name`) VALUES(NULL)
86
+ SQL (0.000381) COMMIT
87
+ SQL (0.000461) BEGIN
88
+ SQL (0.003250) INSERT INTO users (`name`) VALUES(NULL)
89
+ SQL (0.000713) COMMIT
90
+ SQL (0.000383) BEGIN
91
+ EncUser Update (0.000966) UPDATE users SET `name` = '�O�Ŭ�h�3)�4/�' WHERE id = 557
92
+ SQL (0.000389) COMMIT
93
+ EncUser Load (0.001402) SELECT * FROM users WHERE (users.id = 557) LIMIT 1
94
+ RawUser Load (0.001419) SELECT * FROM users WHERE (users.id = 557) LIMIT 1
95
+ RawUser Columns (0.008253) SHOW FIELDS FROM users
96
+ SQL (0.011267) BEGIN
97
+ SQL (0.000794) INSERT INTO users (`name`) VALUES(NULL)
98
+ SQL (0.000768) COMMIT
99
+ SQL (0.000475) BEGIN
100
+ SQL (0.000713) INSERT INTO users (`name`) VALUES(NULL)
101
+ SQL (0.000394) COMMIT
102
+ User Load (0.001529) SELECT * FROM users WHERE (users.id = 559) LIMIT 1
103
+ Asset Columns (0.122398) SHOW FIELDS FROM assets
104
+ SQL (0.003768) BEGIN
105
+ SQL (0.165869) INSERT INTO assets (`updated_at`, `title`, `created_at`) VALUES('2006-07-19 14:30:06', x'ea321f769bbedb5de9c9d936c4cb12d6', '2006-07-19 14:30:06')
106
+ SQL (0.000456) COMMIT
107
+ Cap Columns (0.042072) SHOW FIELDS FROM caps
108
+ SQL (0.007241) BEGIN
109
+ SQL (0.008618) INSERT INTO caps (`updated_at`, `key_hash`, `shared_key`, `key`, `asset_id`, `created_at`, `email`) VALUES('2006-07-19 14:30:06', NULL, NULL, NULL, 68, '2006-07-19 14:30:06', 'pelle@neubia.com')
110
+ SQL (0.000436) COMMIT
111
+ SQL (0.000527) BEGIN
112
+ Cap Update (0.001584) UPDATE caps SET `created_at` = '2006-07-19 14:30:06', `key_hash` = 'f9c991d31301531437c441bcd8f414348d03a079', `key` = NULL, `asset_id` = 68, `email` = 'pelle@neubia.com', `shared_key` = x'41d489f5f8ef1737ffb847ed14c2b79d3af7cbfced92fdb4a26342e70ef8ccfc', `updated_at` = '2006-07-19 14:30:06' WHERE id = 89
113
+ SQL (0.000427) COMMIT
114
+ Cap Load (0.019398) SELECT * FROM caps WHERE (caps.`key_hash` = 'f9c991d31301531437c441bcd8f414348d03a079' ) LIMIT 1
115
+ Asset Load (0.001687) SELECT * FROM assets WHERE (assets.id = 68) LIMIT 1
116
+ AssetRaw Load (0.001928) SELECT * FROM assets WHERE (assets.id = 68) LIMIT 1
117
+ AssetRaw Columns (0.008303) SHOW FIELDS FROM assets
118
+ SQL (0.006758) BEGIN
119
+ SQL (0.001291) INSERT INTO caps (`updated_at`, `key_hash`, `shared_key`, `key`, `asset_id`, `created_at`, `email`) VALUES('2006-07-19 14:30:06', NULL, NULL, NULL, 68, '2006-07-19 14:30:06', 'bob@bob.com')
120
+ SQL (0.000415) COMMIT
121
+ SQL (0.000360) BEGIN
122
+ Cap Update (0.002074) UPDATE caps SET `created_at` = '2006-07-19 14:30:06', `key_hash` = '65cbaf99de40013ee08780c1823e5cc7e9427b34', `key` = NULL, `asset_id` = 68, `email` = 'bob@bob.com', `shared_key` = x'99b58f82b5f4e021f143d800c8aee6e523498bc4260bdcd51d226b275062dfcc', `updated_at` = '2006-07-19 14:30:06' WHERE id = 90
123
+ SQL (0.000428) COMMIT
124
+ Cap Load (0.002402) SELECT * FROM caps WHERE (caps.`key_hash` = '65cbaf99de40013ee08780c1823e5cc7e9427b34' ) LIMIT 1
125
+ Asset Load (0.001505) SELECT * FROM assets WHERE (assets.id = 68) LIMIT 1
126
+ User Columns (0.176279) SHOW FIELDS FROM users
127
+ SQL (0.006658) BEGIN
128
+ SQL (0.013928) INSERT INTO users (`name`) VALUES(NULL)
129
+ SQL (0.000436) COMMIT
130
+ Secret Load (0.006232) SELECT * FROM secrets WHERE (secrets.user_id = 560) 
131
+ Secret Columns (0.008093) SHOW FIELDS FROM secrets
132
+ SQL (0.007102) BEGIN
133
+ SQL (0.000961) INSERT INTO secrets (`name`, `user_id`, `email`) VALUES(NULL, 560, NULL)
134
+ SQL (0.000410) COMMIT
135
+ User Load (0.001519) SELECT * FROM users WHERE (users.id = 560) LIMIT 1
136
+ SQL (0.000480) BEGIN
137
+ Secret Update (0.001119) UPDATE secrets SET `user_id` = 560, `email` = NULL, `name` = x'c42d49cb44c44d9e9288b5d94c6dda6b' WHERE id = 76
138
+ SQL (0.000436) COMMIT
139
+ Child Load (0.034930) SELECT * FROM children WHERE (children.secret_id = 76) 
140
+ Child Columns (0.008565) SHOW FIELDS FROM children
141
+ SQL (0.006693) BEGIN
142
+ SQL (0.000800) INSERT INTO children (`secret_id`, `email`) VALUES(76, NULL)
143
+ SQL (0.000688) COMMIT
144
+ SQL (0.000379) BEGIN
145
+ Secret Load (0.002081) SELECT * FROM secrets WHERE (secrets.id = 76) LIMIT 1
146
+ User Load (0.001388) SELECT * FROM users WHERE (users.id = 560) LIMIT 1
147
+ Child Update (0.000956) UPDATE children SET `secret_id` = 76, `email` = '�PI36ZՖt;&��(|nF/�o�x8�A�a��' WHERE id = 61
148
+ SQL (0.000427) COMMIT
149
+ SQL (0.000325) BEGIN
150
+ SQL (0.000715) INSERT INTO users (`name`) VALUES('bob')
151
+ SQL (0.000502) COMMIT
152
+ SQL (0.000795) BEGIN
153
+ SQL (0.001039) INSERT INTO users (`name`) VALUES(NULL)
154
+ SQL (0.000419) COMMIT
155
+ SQL (0.000437) BEGIN
156
+ SQL (0.000712) INSERT INTO users (`name`) VALUES(NULL)
157
+ SQL (0.000494) COMMIT
158
+ SQL (0.000428) BEGIN
159
+ SQL (0.001013) INSERT INTO users (`name`) VALUES(NULL)
160
+ SQL (0.000397) COMMIT
161
+ SQL (0.000451) BEGIN
162
+ SQL (0.003872) INSERT INTO users (`name`) VALUES(NULL)
163
+ SQL (0.000425) COMMIT
164
+ SQL (0.000437) BEGIN
165
+ SQL (0.000697) INSERT INTO users (`name`) VALUES(NULL)
166
+ SQL (0.000749) COMMIT
167
+ User Load (0.001268) SELECT * FROM users WHERE (users.id = 566) LIMIT 1
168
+ SQL (0.000484) BEGIN
169
+ SQL (0.001166) INSERT INTO users (`name`) VALUES(NULL)
170
+ SQL (0.000403) COMMIT
171
+ SQL (0.000367) BEGIN
172
+ SQL (0.000917) INSERT INTO users (`name`) VALUES(NULL)
173
+ SQL (0.000540) COMMIT
174
+ User Load (0.001214) SELECT * FROM users WHERE (users.id = 568) LIMIT 1
175
+ EncUser Columns (0.011722) SHOW FIELDS FROM users
176
+ SQL (0.006778) BEGIN
177
+ SQL (0.003122) INSERT INTO users (`name`) VALUES(NULL)
178
+ SQL (0.000419) COMMIT
179
+ SQL (0.000433) BEGIN
180
+ SQL (0.001564) INSERT INTO users (`name`) VALUES(NULL)
181
+ SQL (0.000474) COMMIT
182
+ SQL (0.009263) BEGIN
183
+ SQL (0.000999) INSERT INTO users (`name`) VALUES(NULL)
184
+ SQL (0.000428) COMMIT
185
+ SQL (0.000530) BEGIN
186
+ SQL (0.000821) INSERT INTO users (`name`) VALUES(NULL)
187
+ SQL (0.000385) COMMIT
188
+ SQL (0.000466) BEGIN
189
+ SQL (0.000737) INSERT INTO users (`name`) VALUES(NULL)
190
+ SQL (0.000368) COMMIT
191
+ SQL (0.000596) BEGIN
192
+ EncUser Update (0.001114) UPDATE users SET `name` = '�T�n��O%` ��' WHERE id = 573
193
+ SQL (0.000407) COMMIT
194
+ EncUser Load (0.001269) SELECT * FROM users WHERE (users.id = 573) LIMIT 1
195
+ RawUser Load (0.003733) SELECT * FROM users WHERE (users.id = 573) LIMIT 1
196
+ RawUser Columns (0.013586) SHOW FIELDS FROM users
197
+ SQL (0.000795) BEGIN
198
+ SQL (0.000916) INSERT INTO users (`name`) VALUES(NULL)
199
+ SQL (0.000386) COMMIT
200
+ SQL (0.000395) BEGIN
201
+ SQL (0.001061) INSERT INTO users (`name`) VALUES(NULL)
202
+ SQL (0.000410) COMMIT
203
+ User Load (0.001295) SELECT * FROM users WHERE (users.id = 575) LIMIT 1
@@ -0,0 +1,37 @@
1
+ require 'association_key_holder_test'
2
+
3
+ class EncUser < ActiveRecord::Base
4
+ set_table_name "users"
5
+ encrypt :name
6
+ end
7
+
8
+ class RawUser < ActiveRecord::Base
9
+ set_table_name "users"
10
+ end
11
+
12
+ class EncryptTest < AssociationKeyHolderTest
13
+ def setup
14
+ @key_holder=EncUser.create
15
+ end
16
+
17
+ def test_should_retain_session_key_on_reload
18
+ key=EzCrypto::Key.generate
19
+ key_holder.set_session_key key
20
+ assert_not_nil key_holder.session_key
21
+ assert_equal key.raw,key_holder.session_key.raw
22
+
23
+ key_holder.name="bob"
24
+ key_holder.save
25
+
26
+ assert_equal "bob",key_holder.name
27
+
28
+ found=EncUser.find key_holder.id
29
+ assert_equal key_holder.name,found.name
30
+
31
+ raw=RawUser.find key_holder.id
32
+ assert_not_nil raw.name
33
+ assert_not_equal key_holder.name,raw.name
34
+
35
+ end
36
+
37
+ end