openid-store-mongoid 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +60 -0
- data/LICENSE.txt +20 -0
- data/README.md +47 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/openid/store/models/association.rb +13 -0
- data/lib/openid/store/models/nonce.rb +8 -0
- data/lib/openid/store/mongoid_store.rb +82 -0
- data/lib/openid-store-mongoid.rb +1 -0
- data/openid-store-mongoid.gemspec +72 -0
- data/spec/openid-store-mongoid_spec.rb +183 -0
- data/spec/spec_helper.rb +12 -0
- metadata +177 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
ruby '1.9.3'
|
7
|
+
|
8
|
+
gem 'sinatra', '~>1.3'
|
9
|
+
gem 'mongoid', '~>3.1'
|
10
|
+
gem 'ruby-openid', '~>2.2.3'
|
11
|
+
|
12
|
+
# Add dependencies to develop your gem here.
|
13
|
+
# Include everything needed to run rake, tests, features, etc.
|
14
|
+
group :development do
|
15
|
+
gem "rspec", "~> 2.8"
|
16
|
+
gem "rdoc", "~> 3.12"
|
17
|
+
gem "bundler", "~> 1.0"
|
18
|
+
gem "jeweler", "~> 1.8.4"
|
19
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.2.12)
|
5
|
+
activesupport (= 3.2.12)
|
6
|
+
builder (~> 3.0.0)
|
7
|
+
activesupport (3.2.12)
|
8
|
+
i18n (~> 0.6)
|
9
|
+
multi_json (~> 1.0)
|
10
|
+
builder (3.0.4)
|
11
|
+
diff-lcs (1.1.3)
|
12
|
+
git (1.2.5)
|
13
|
+
i18n (0.6.1)
|
14
|
+
jeweler (1.8.4)
|
15
|
+
bundler (~> 1.0)
|
16
|
+
git (>= 1.2.5)
|
17
|
+
rake
|
18
|
+
rdoc
|
19
|
+
json (1.7.7)
|
20
|
+
mongoid (3.1.0)
|
21
|
+
activemodel (~> 3.2)
|
22
|
+
moped (~> 1.4.2)
|
23
|
+
origin (~> 1.0)
|
24
|
+
tzinfo (~> 0.3.22)
|
25
|
+
moped (1.4.2)
|
26
|
+
multi_json (1.6.1)
|
27
|
+
origin (1.0.11)
|
28
|
+
rack (1.5.2)
|
29
|
+
rack-protection (1.3.2)
|
30
|
+
rack
|
31
|
+
rake (10.0.3)
|
32
|
+
rdoc (3.12.1)
|
33
|
+
json (~> 1.4)
|
34
|
+
rspec (2.12.0)
|
35
|
+
rspec-core (~> 2.12.0)
|
36
|
+
rspec-expectations (~> 2.12.0)
|
37
|
+
rspec-mocks (~> 2.12.0)
|
38
|
+
rspec-core (2.12.2)
|
39
|
+
rspec-expectations (2.12.1)
|
40
|
+
diff-lcs (~> 1.1.3)
|
41
|
+
rspec-mocks (2.12.2)
|
42
|
+
ruby-openid (2.2.3)
|
43
|
+
sinatra (1.3.4)
|
44
|
+
rack (~> 1.4)
|
45
|
+
rack-protection (~> 1.3)
|
46
|
+
tilt (~> 1.3, >= 1.3.3)
|
47
|
+
tilt (1.3.3)
|
48
|
+
tzinfo (0.3.35)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
bundler (~> 1.0)
|
55
|
+
jeweler (~> 1.8.4)
|
56
|
+
mongoid (~> 3.1)
|
57
|
+
rdoc (~> 3.12)
|
58
|
+
rspec (~> 2.8)
|
59
|
+
ruby-openid (~> 2.2.3)
|
60
|
+
sinatra (~> 1.3)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Larry Price
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#openid-store-mongoid
|
2
|
+
|
3
|
+
Author: Larry Price ([larryprice.github.com](http://larryprice.github.com))
|
4
|
+
Contact: larry.price.dev@gmail.com
|
5
|
+
Repository Location: https://github.com/larryprice/openid-store-mongoid
|
6
|
+
|
7
|
+
##Description
|
8
|
+
|
9
|
+
OpenID Store using Mongoid. Concept originally from [Alex Young's blog](http://alexyoung.org/2010/09/28/openid-japan/).
|
10
|
+
|
11
|
+
##Usage
|
12
|
+
|
13
|
+
You should use `require 'openid-store-mongoid'` to use this gem.
|
14
|
+
|
15
|
+
To create an OpenID consumer:
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
OpenID::Consumer.new(session, OpenID::Store::MongoidStore.new)
|
19
|
+
```
|
20
|
+
|
21
|
+
To use with OmniAuth:
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
use OmniAuth::Builder do
|
25
|
+
provider :open_id, :store => OpenID::Store::MongoidStore.new
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
You can cleanup any expired Nonce and Association documents from your database:
|
30
|
+
|
31
|
+
``` ruby
|
32
|
+
OpenID::Store::MongoidStore.cleanup
|
33
|
+
```
|
34
|
+
|
35
|
+
##Contributing to openid-store-mongoid
|
36
|
+
|
37
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
38
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
39
|
+
* Fork the project.
|
40
|
+
* Start a feature/bugfix branch.
|
41
|
+
* Commit and push until you are happy with your contribution.
|
42
|
+
* Make sure to add tests for it. No pull requests will be accepted unless new features have been tested and all previous code is still tested.
|
43
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
44
|
+
|
45
|
+
##Copyright
|
46
|
+
|
47
|
+
Copyright (c) 2013 Larry Price. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "openid-store-mongoid"
|
18
|
+
gem.homepage = "http://github.com/larryprice/openid-store-mongoid"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{OpenID Store using Mongoid.}
|
21
|
+
gem.description = %Q{Use a Mongoid database to store OpenID consumer data.}
|
22
|
+
gem.email = "larry.price.dev@gmail.com"
|
23
|
+
gem.authors = ["Larry Price"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
task :default => :spec
|
35
|
+
|
36
|
+
task :test => :spec
|
37
|
+
|
38
|
+
require 'rdoc/task'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "temp #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'mongoid'
|
2
|
+
require 'openid/association'
|
3
|
+
|
4
|
+
module OpenID::Store
|
5
|
+
class Association
|
6
|
+
include Mongoid::Document
|
7
|
+
field :secret, :type => Moped::BSON::Binary
|
8
|
+
|
9
|
+
def from_record
|
10
|
+
OpenID::Association.new(handle, secret.to_s, Time.at(issued), lifetime, assoc_type)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'openid/store/interface'
|
2
|
+
require 'openid/store/nonce'
|
3
|
+
require 'moped/bson/binary'
|
4
|
+
|
5
|
+
require 'openid/store/models/nonce'
|
6
|
+
require 'openid/store/models/association'
|
7
|
+
|
8
|
+
module OpenID::Store
|
9
|
+
class MongoidStore < OpenID::Store::Interface
|
10
|
+
def self.cleanup
|
11
|
+
cleanup_nonces
|
12
|
+
cleanup_associations
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_association(server_url, handle = nil)
|
16
|
+
assns = query_associations(server_url, handle)
|
17
|
+
|
18
|
+
assns.reverse.each do |assn|
|
19
|
+
a = assn.from_record
|
20
|
+
if a.expires_in == 0
|
21
|
+
assn.destroy
|
22
|
+
else
|
23
|
+
return a
|
24
|
+
end
|
25
|
+
end if assns.any?
|
26
|
+
|
27
|
+
return nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def store_association(server_url, assoc)
|
31
|
+
remove_association(server_url, assoc.handle)
|
32
|
+
|
33
|
+
# BSON::Binary is used because secrets raise an exception
|
34
|
+
# due to character encoding
|
35
|
+
Association.create(:server_url => server_url,
|
36
|
+
:handle => assoc.handle,
|
37
|
+
:secret => Moped::BSON::Binary.new(:generic, assoc.secret),
|
38
|
+
:issued => assoc.issued.to_i,
|
39
|
+
:lifetime => assoc.lifetime,
|
40
|
+
:assoc_type => assoc.assoc_type)
|
41
|
+
end
|
42
|
+
|
43
|
+
def use_nonce(server_url, timestamp, salt)
|
44
|
+
return false if any_nonces?(server_url, timestamp, salt) || delta_beyond_skew?(timestamp)
|
45
|
+
Nonce.create(:server_url => server_url, :timestamp => timestamp, :salt => salt)
|
46
|
+
return true
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def query_associations(server_url, handle)
|
52
|
+
if handle.blank?
|
53
|
+
Association.where(:server_url => server_url)
|
54
|
+
else
|
55
|
+
Association.where(:server_url => server_url, :handle => handle)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def remove_association(server_url, handle)
|
60
|
+
Association.where(:server_url => server_url, :handle => handle).each do |assoc|
|
61
|
+
assoc.destroy!
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def any_nonces?(server_url, timestamp, salt)
|
66
|
+
Nonce.where(:server_url => server_url, :timestamp => timestamp, :salt => salt).any?
|
67
|
+
end
|
68
|
+
|
69
|
+
def delta_beyond_skew?(timestamp)
|
70
|
+
(timestamp.to_i - Time.now.to_i).abs > OpenID::Nonce.skew
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.cleanup_nonces
|
74
|
+
now = Time.now.to_i
|
75
|
+
Nonce.any_of({:timestamp.gt => now + OpenID::Nonce.skew}, {:timestamp.lt => now - OpenID::Nonce.skew}).delete
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.cleanup_associations
|
79
|
+
Association.for_js("(this.issued + this.lifetime) > ti", ti: Time.now.to_i).delete
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'openid/store/mongoid_store'
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "openid-store-mongoid"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Larry Price"]
|
12
|
+
s.date = "2013-02-23"
|
13
|
+
s.description = "Use a Mongoid database to store OpenID consumer data."
|
14
|
+
s.email = "larry.price.dev@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/openid-store-mongoid.rb",
|
29
|
+
"lib/openid/store/models/association.rb",
|
30
|
+
"lib/openid/store/models/nonce.rb",
|
31
|
+
"lib/openid/store/mongoid_store.rb",
|
32
|
+
"openid-store-mongoid.gemspec",
|
33
|
+
"spec/openid-store-mongoid_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = "http://github.com/larryprice/openid-store-mongoid"
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = "1.8.23"
|
40
|
+
s.summary = "OpenID Store using Mongoid."
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<sinatra>, ["~> 1.3"])
|
47
|
+
s.add_runtime_dependency(%q<mongoid>, ["~> 3.1"])
|
48
|
+
s.add_runtime_dependency(%q<ruby-openid>, ["~> 2.2.3"])
|
49
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8"])
|
50
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
51
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<sinatra>, ["~> 1.3"])
|
55
|
+
s.add_dependency(%q<mongoid>, ["~> 3.1"])
|
56
|
+
s.add_dependency(%q<ruby-openid>, ["~> 2.2.3"])
|
57
|
+
s.add_dependency(%q<rspec>, ["~> 2.8"])
|
58
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
59
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
60
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<sinatra>, ["~> 1.3"])
|
64
|
+
s.add_dependency(%q<mongoid>, ["~> 3.1"])
|
65
|
+
s.add_dependency(%q<ruby-openid>, ["~> 2.2.3"])
|
66
|
+
s.add_dependency(%q<rspec>, ["~> 2.8"])
|
67
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
68
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
69
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
module OpenID::Store
|
4
|
+
describe MongoidStore do
|
5
|
+
before :all do
|
6
|
+
@store = MongoidStore.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#new' do
|
10
|
+
it 'has type OpenID::Store::Interface' do
|
11
|
+
@store.should be_kind_of OpenID::Store::Interface
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#get_association' do
|
16
|
+
it 'returns nil if no associations found and no handle given' do
|
17
|
+
server_url = 'test/url'
|
18
|
+
Association.should_receive(:where).with({:server_url => server_url}).once.and_return(Array.new)
|
19
|
+
|
20
|
+
@store.get_association(server_url).should be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns nil if no associations found and handle given' do
|
24
|
+
server_url = 'test/url'
|
25
|
+
handle = 'test/handle'
|
26
|
+
Association.should_receive(:where).with({:server_url => server_url, :handle => handle}).once.and_return(Array.new)
|
27
|
+
|
28
|
+
@store.get_association(server_url, handle).should be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns nil if all associations have expired' do
|
32
|
+
openid_assn1 = double("OpenID::Association")
|
33
|
+
openid_assn1.should_receive(:expires_in).once.and_return(0)
|
34
|
+
openid_assn2 = double("OpenID::Association")
|
35
|
+
openid_assn2.should_receive(:expires_in).once.and_return(0)
|
36
|
+
|
37
|
+
assn1 = double("Association")
|
38
|
+
assn1.should_receive(:from_record).once.and_return(openid_assn1)
|
39
|
+
assn1.should_receive(:destroy).once
|
40
|
+
assn2 = double("Association")
|
41
|
+
assn2.should_receive(:from_record).once.and_return(openid_assn2)
|
42
|
+
assn2.should_receive(:destroy).once
|
43
|
+
|
44
|
+
server_url = 'test/url'
|
45
|
+
Association.should_receive(:where).with({:server_url => server_url}).once.and_return([assn1, assn2])
|
46
|
+
|
47
|
+
@store.get_association(server_url).should be_nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns first unexpired association' do
|
51
|
+
openid_assn1 = double("OpenID::Association")
|
52
|
+
openid_assn1.should_receive(:expires_in).once.and_return(1)
|
53
|
+
openid_assn2 = double("OpenID::Association")
|
54
|
+
openid_assn2.should_receive(:expires_in).once.and_return(0)
|
55
|
+
|
56
|
+
assn1 = double("Association")
|
57
|
+
assn1.should_receive(:from_record).once.and_return(openid_assn1)
|
58
|
+
assn1.should_receive(:destroy).never
|
59
|
+
assn2 = double("Association")
|
60
|
+
assn2.should_receive(:from_record).once.and_return(openid_assn2)
|
61
|
+
assn2.should_receive(:destroy).once
|
62
|
+
|
63
|
+
server_url = 'test/url'
|
64
|
+
Association.should_receive(:where).with({:server_url => server_url}).once.and_return([assn1, assn2])
|
65
|
+
|
66
|
+
@store.get_association(server_url).should eql openid_assn1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#store_association' do
|
71
|
+
it 'removes no associations and creates new association when no match' do
|
72
|
+
server_url = 'server/url'
|
73
|
+
|
74
|
+
openid_assn = OpenID::Association.new('/some/handle', 'secret', Time.now, 10, 'some/type')
|
75
|
+
|
76
|
+
Association.any_instance.should_receive(:destroy).never
|
77
|
+
Association.should_receive(:where).with({:server_url => server_url, :handle => openid_assn.handle})
|
78
|
+
.once.and_return(Array.new)
|
79
|
+
Association.should_receive(:create)
|
80
|
+
.with(:server_url => server_url, :handle => openid_assn.handle,
|
81
|
+
:secret => Moped::BSON::Binary.new(:generic, openid_assn.secret),
|
82
|
+
:issued => openid_assn.issued.to_i, :lifetime => openid_assn.lifetime,
|
83
|
+
:assoc_type => openid_assn.assoc_type)
|
84
|
+
.once
|
85
|
+
|
86
|
+
@store.store_association(server_url, openid_assn)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'removes any matching associations and creates new association' do
|
90
|
+
server_url = 'server/url'
|
91
|
+
|
92
|
+
assn1 = double("Association")
|
93
|
+
assn1.should_receive(:destroy!).once
|
94
|
+
assn2 = double("Association")
|
95
|
+
assn2.should_receive(:destroy!).never
|
96
|
+
assn3 = double("Association")
|
97
|
+
assn3.should_receive(:destroy!).once
|
98
|
+
|
99
|
+
openid_assn = OpenID::Association.new('/some/handle', 'secret', Time.now, 10, 'some/type')
|
100
|
+
|
101
|
+
Association.any_instance.should_receive(:destroy).never
|
102
|
+
Association.should_receive(:where).with({:server_url => server_url, :handle => openid_assn.handle})
|
103
|
+
.once.and_return([assn1, assn3])
|
104
|
+
Association.should_receive(:create)
|
105
|
+
.with(:server_url => server_url, :handle => openid_assn.handle,
|
106
|
+
:secret => Moped::BSON::Binary.new(:generic, openid_assn.secret),
|
107
|
+
:issued => openid_assn.issued.to_i, :lifetime => openid_assn.lifetime,
|
108
|
+
:assoc_type => openid_assn.assoc_type)
|
109
|
+
.once
|
110
|
+
|
111
|
+
@store.store_association(server_url, openid_assn)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#use_nonce' do
|
116
|
+
it 'returns false if any matching nonces found' do
|
117
|
+
server_url = 'some/url'
|
118
|
+
timestamp = Time.now
|
119
|
+
salt = 'qwerty12345'
|
120
|
+
|
121
|
+
Nonce.should_receive(:where).with(:server_url => server_url, :timestamp => timestamp, :salt => salt)
|
122
|
+
.once.and_return([double("Association")])
|
123
|
+
|
124
|
+
@store.use_nonce(server_url, timestamp, salt).should be_false
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'returns false if time is beyond skew and no matching nonces found' do
|
128
|
+
now = Time.now
|
129
|
+
timestamp = now + OpenID::Nonce.skew + 1
|
130
|
+
|
131
|
+
server_url = 'some/url'
|
132
|
+
salt = 'qwerty12345'
|
133
|
+
|
134
|
+
Nonce.should_receive(:where).with(:server_url => server_url, :timestamp => timestamp, :salt => salt)
|
135
|
+
.once.and_return(Array.new)
|
136
|
+
Time.should_receive(:now).once.and_return(now)
|
137
|
+
|
138
|
+
@store.use_nonce(server_url, timestamp, salt).should be_false
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'returns true and creates nonce if no matching nonces and time within skew' do
|
142
|
+
now = Time.now
|
143
|
+
timestamp = now + OpenID::Nonce.skew - 1
|
144
|
+
|
145
|
+
server_url = 'some/url'
|
146
|
+
salt = 'qwerty12345'
|
147
|
+
|
148
|
+
Nonce.should_receive(:where).with(:server_url => server_url, :timestamp => timestamp, :salt => salt)
|
149
|
+
.once.and_return(Array.new)
|
150
|
+
Nonce.should_receive(:create).with(:server_url => server_url, :timestamp => timestamp, :salt => salt).once
|
151
|
+
Time.should_receive(:now).once.and_return(now)
|
152
|
+
|
153
|
+
@store.use_nonce(server_url, timestamp, salt).should be_true
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe '#cleanup' do
|
158
|
+
it 'cleans up any expried nonces and associations' do
|
159
|
+
now = Time.now
|
160
|
+
Time.should_receive(:now).exactly(2).and_return(now)
|
161
|
+
now_in_seconds = now.to_i
|
162
|
+
|
163
|
+
nonce_crit = double("Mongoid::Criteria")
|
164
|
+
nonce_crit.should_receive(:delete)
|
165
|
+
|
166
|
+
Nonce.should_receive(:any_of)
|
167
|
+
.with({:timestamp.gt => now_in_seconds + OpenID::Nonce.skew},
|
168
|
+
{:timestamp.lt => now_in_seconds - OpenID::Nonce.skew})
|
169
|
+
.and_return(nonce_crit)
|
170
|
+
|
171
|
+
assn_crit = double("Mongoid::Criteria")
|
172
|
+
assn_crit.should_receive(:delete)
|
173
|
+
|
174
|
+
Association.should_receive(:for_js)
|
175
|
+
.with("(this.issued + this.lifetime) > ti", ti: now_in_seconds)
|
176
|
+
.and_return(assn_crit)
|
177
|
+
|
178
|
+
MongoidStore.cleanup
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'openid-store-mongoid'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openid-store-mongoid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Larry Price
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mongoid
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.1'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.1'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: ruby-openid
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.2.3
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.2.3
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '2.8'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.8'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rdoc
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '3.12'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '3.12'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: bundler
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '1.0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: jeweler
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.8.4
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 1.8.4
|
126
|
+
description: Use a Mongoid database to store OpenID consumer data.
|
127
|
+
email: larry.price.dev@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files:
|
131
|
+
- LICENSE.txt
|
132
|
+
- README.md
|
133
|
+
files:
|
134
|
+
- .document
|
135
|
+
- .rspec
|
136
|
+
- Gemfile
|
137
|
+
- Gemfile.lock
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.md
|
140
|
+
- Rakefile
|
141
|
+
- VERSION
|
142
|
+
- lib/openid-store-mongoid.rb
|
143
|
+
- lib/openid/store/models/association.rb
|
144
|
+
- lib/openid/store/models/nonce.rb
|
145
|
+
- lib/openid/store/mongoid_store.rb
|
146
|
+
- openid-store-mongoid.gemspec
|
147
|
+
- spec/openid-store-mongoid_spec.rb
|
148
|
+
- spec/spec_helper.rb
|
149
|
+
homepage: http://github.com/larryprice/openid-store-mongoid
|
150
|
+
licenses:
|
151
|
+
- MIT
|
152
|
+
post_install_message:
|
153
|
+
rdoc_options: []
|
154
|
+
require_paths:
|
155
|
+
- lib
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
+
none: false
|
158
|
+
requirements:
|
159
|
+
- - ! '>='
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
segments:
|
163
|
+
- 0
|
164
|
+
hash: 1531852465558218679
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
none: false
|
167
|
+
requirements:
|
168
|
+
- - ! '>='
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project:
|
173
|
+
rubygems_version: 1.8.23
|
174
|
+
signing_key:
|
175
|
+
specification_version: 3
|
176
|
+
summary: OpenID Store using Mongoid.
|
177
|
+
test_files: []
|