openid_mongodb_store 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -25,7 +25,8 @@ class OpenidMongodbStore::Store < OpenID::Store::Interface
25
25
  'secret' => secret,
26
26
  'issued' => association.issued,
27
27
  'lifetime' => association.lifetime,
28
- 'assoc_type' => association.assoc_type)
28
+ 'assoc_type' => association.assoc_type,
29
+ 'expire_at' => (association.issued + association.lifetime))
29
30
  end
30
31
 
31
32
  def get_association(server_url, handle=nil)
@@ -70,14 +71,13 @@ class OpenidMongodbStore::Store < OpenID::Store::Interface
70
71
 
71
72
  def cleanup_nonces
72
73
  now = Time.now.to_i
73
- nonces.remove({'timestamp' => {'$gt'=> (now + OpenID::Nonce.skew),
74
- '$lt'=> (now - OpenID::Nonce.skew)}})
74
+ nonces.remove({'timestamp' => {'$gt'=> (now + OpenID::Nonce.skew)}})
75
+ nonces.remove({'timestamp' => {'$lt'=> (now - OpenID::Nonce.skew)}})
75
76
  end
76
77
 
77
78
  def cleanup_associations
78
79
  now = Time.now.to_i
79
- # Association.delete_all(:expire_at => {'$gt' => now})
80
- associations.remove('expire_at' => {'$gt' => now})
80
+ associations.remove('expire_at' => {'$lt' => now})
81
81
  end
82
82
 
83
83
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{openid_mongodb_store}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sam Schenkman-Moore"]
12
- s.date = %q{2010-07-04}
12
+ s.date = %q{2010-09-27}
13
13
  s.description = %q{Like the ActiveRecord Store, but for Mongo.}
14
14
  s.email = %q{samsm@samsm.com}
15
15
  s.extra_rdoc_files = [
data/test/helper.rb CHANGED
@@ -1,9 +1,107 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
+ require 'mocha'
4
+ require 'ruby-debug'
3
5
 
4
6
  $LOAD_PATH.unshift(File.dirname(__FILE__))
5
7
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
8
  require 'openid_mongodb_store'
7
9
 
10
+ def test_database
11
+ Mongo::Connection.new('localhost').db('openid_store_test')
12
+ end
13
+
8
14
  class Test::Unit::TestCase
15
+
16
+ def setup
17
+ timestamp(true)
18
+ end
19
+
20
+ ##
21
+ ## Mongo-specific database test configuration here.
22
+ ##
23
+
24
+ def store
25
+ @store ||= OpenidMongodbStore::Store.new(test_database)
26
+ end
27
+
28
+ def insert_old_association
29
+ store.associations.insert('server_url' => server_url,
30
+ 'handle' => handle,
31
+ 'secret' => BSON::Binary.new(secret),
32
+ 'issued' => too_old_association_timestamp,
33
+ 'lifetime' => lifetime,
34
+ 'assoc_type' => assoc_type,
35
+ 'expire_at' => (too_old_association_timestamp + lifetime))
36
+
37
+ end
38
+
39
+ def find_old_association
40
+ store.associations.find_one({'issued' => too_old_association_timestamp})
41
+ end
42
+
43
+ def insert_old_nonce
44
+ store.nonces.insert({'server_url' => server_url, 'timestamp' => too_old_nonce_timestamp, 'salt' => salt})
45
+ end
46
+
47
+ def find_old_nonce
48
+ store.nonces.find_one({'server_url'=> server_url, 'timestamp' => too_old_nonce_timestamp, 'salt' => salt})
49
+ end
50
+
51
+ ##
52
+ ## End of Mongo-specific test config
53
+ ##
54
+
55
+ def too_old_nonce_timestamp
56
+ timestamp - (OpenID::Nonce.skew * 1.5).to_i
57
+ end
58
+
59
+ def too_old_association_timestamp
60
+ timestamp - (60*60*24*365) # year old
61
+ end
62
+
63
+ def store_association(opts = {})
64
+ association = OpenID::Association.new(handle, secret, timestamp, lifetime, assoc_type)
65
+ opts.each_pair {|k,v| association.send "#{k}=", v}
66
+ store.store_association(server_url,association)
67
+ end
68
+
69
+ def get_association(server_url = server_url, handle = handle)
70
+ store.get_association(server_url,handle)
71
+ end
72
+
73
+ def server_url
74
+ "http://localhost:98765/"
75
+ end
76
+
77
+ def handle
78
+ "{HMAC-SHA1}{4ca0a54b}{5Sx5CQ==}"
79
+ end
80
+
81
+ def secret
82
+ OpenID::Util.from_base64("5EoS1O4V+x7VkBNEekHsavgRjbk=")
83
+ end
84
+
85
+ def timestamp(refresh = false)
86
+ @timestamp = nil if refresh
87
+ @timestamp ||= (Time.now - 10).to_i # 10 seconds ago
88
+ end
89
+
90
+ def lifetime
91
+ 1209600 # two weeks in seconds
92
+ end
93
+
94
+ def assoc_type
95
+ "HMAC-SHA1"
96
+ end
97
+
98
+ def salt
99
+ "KuIaaq"
100
+ end
101
+
102
+ def teardown
103
+ test_database.drop_collection 'openid_mongo_store_associations'
104
+ test_database.drop_collection 'openid_mongo_store_nonces'
105
+ end
106
+
9
107
  end
@@ -1,7 +1,64 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestOpenidMongodbStore < Test::Unit::TestCase
4
- def test_something_for_real
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
4
+ def test_store_and_retrieve_association
5
+ # Make sure there isn't already an association in the database
6
+ assert !get_association
7
+
8
+ # Save an assocaition
9
+ assert store_association
10
+
11
+ # Retrieve the association
12
+ assert store.get_association(server_url, handle)
13
+ end
14
+
15
+ def test_remove_association
16
+ store_association
17
+
18
+ # Ensure an assocaition exists
19
+ assert get_association
20
+
21
+ # Remove a specific association
22
+ assert store.remove_association(server_url,handle)
23
+ # Confirm that the association is gone.
24
+ assert !get_association
25
+ end
26
+
27
+ def test_use_nonce
28
+ # If a timestamp is too old, use_nonce should return false
29
+ assert !store.use_nonce(server_url, too_old_nonce_timestamp, salt)
30
+
31
+ # When no nonces exist, this should return true and create a nonce record
32
+ assert store.use_nonce(server_url, timestamp, salt)
33
+
34
+ # After a nonce is created with a given salt/timestamp, use_nonce should return false
35
+ assert !store.use_nonce(server_url, timestamp, salt)
36
+ end
37
+
38
+ def test_cleanup_nonces
39
+ insert_old_nonce
40
+
41
+ # Verify nonce is inserted
42
+ assert find_old_nonce
43
+
44
+ # Cleanup nonces
45
+ assert store.cleanup_nonces
46
+
47
+ # Verify nonce was cleaned up
48
+ assert !find_old_nonce
49
+ end
50
+
51
+ def test_cleanup_associations
52
+ insert_old_association
53
+
54
+ # Ensure association was saved
55
+ assert find_old_association
56
+
57
+ # Cleanup associations
58
+ assert store.cleanup_associations
59
+
60
+ # Ensure association was removed
61
+ assert !find_old_association
62
+
6
63
  end
7
64
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openid_mongodb_store
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sam Schenkman-Moore
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-04 00:00:00 -04:00
18
+ date: 2010-09-27 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency