Class: ActiveCryptoTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/extensions/ezcrypto/ext/test/active_crypto_test.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



102
103
# File 'lib/extensions/ezcrypto/ext/test/active_crypto_test.rb', line 102

def setup
end

#test_capsObject



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/extensions/ezcrypto/ext/test/active_crypto_test.rb', line 183

def test_caps
  key=Asset.create("title","[email protected]")
  assert_not_nil key
  cap=Cap.find_by_key key
  assert_not_nil cap
  assert_not_nil cap.asset
  
  assert_equal "title",cap.asset.title
  assert_equal "title",cap.asset["title"]
  assert_equal "[email protected]",cap.email
  assert_equal "[email protected]",cap["email"]
  
  # Non decrypting version
  raw=AssetRaw.find cap.asset.id
  assert_not_equal "title",raw.title
  assert_not_equal "title",raw["title"]
  
  bob_key=cap.asset.share("[email protected]")
  bob_cap=Cap.find_by_key bob_key
  
  assert_not_equal key,bob_key
  assert_not_nil bob_cap
  assert_not_nil bob_cap.asset
  assert_equal "title",bob_cap.asset.title
  assert_equal "[email protected]",bob_cap.email
end

#test_encrypted_childObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/extensions/ezcrypto/ext/test/active_crypto_test.rb', line 118

def test_encrypted_child
  user=User.new
  user.save
  assert_nil user.session_key
	user.enter_password "shhcccc"
	assert_not_nil user.session_key
	assert user.kind_of?(ActiveCrypto::KeyHolder)
	assert user.kind_of?(ActiveRecord::Base)
	assert user.kind_of?(User)
	
	jill=user.secrets.create
	
	assert_not_nil jill
	assert jill.kind_of?(ActiveCrypto::AssociationKeyHolder)
	assert jill.kind_of?(ActiveCrypto::KeyHolder)
	assert jill.kind_of?(ActiveCrypto::Encrypted)
	assert jill.kind_of?(ActiveRecord::Base)
	assert jill.kind_of?(Secret)
	
	assert jill.respond_to?(:session_key)
	
  assert_not_nil jill.user
  assert_not_nil jill.user.session_key
	
	
  assert_not_nil jill.session_key
  assert_equal user.session_key,jill.session_key

  jill.name="jill"
  jill.save


  assert_equal "jill",jill.name
  
  jill=user.secrets.first
  assert_not_nil jill.session_key
  assert_equal user.session_key,jill.session_key
  assert_equal "jill",jill.name
  
  child=jill.children.create
  child.email="[email protected]"
  child.save

  assert_not_nil child.secret
  assert_not_nil child.secret.session_key


  assert_not_nil child.session_key
  assert_equal user.session_key,child.session_key

  assert_equal "[email protected]",child.email

  child=jill.children.first

  assert_not_nil child.secret
  assert_not_nil child.secret.session_key


  assert_not_nil child.session_key
  assert_equal user.session_key,child.session_key

  assert_equal "[email protected]",child.email

end

#test_key_holder_in_recordObject



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/extensions/ezcrypto/ext/test/active_crypto_test.rb', line 105

def test_key_holder_in_record
  user=User.new
  user.name="bob"
  user.save
	assert user.kind_of?(ActiveCrypto::KeyHolder)
	assert user.kind_of?(ActiveRecord::Base)
	assert user.kind_of?(User)
  assert_nil user.session_key
	user.enter_password "shhcccc"
	assert_not_nil user.session_key
	assert_not_nil user.session_key.encrypt("test")    
end