sorcery 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +5 -2
- data/Gemfile.lock +12 -0
- data/README.rdoc +12 -7
- data/VERSION +1 -1
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +1 -1
- data/lib/sorcery/crypto_providers/bcrypt.rb +2 -4
- data/lib/sorcery/crypto_providers/common.rb +2 -2
- data/lib/sorcery/engine.rb +0 -4
- data/lib/sorcery/initializers/initializer.rb +2 -0
- data/lib/sorcery/model/adapters/active_record.rb +28 -0
- data/lib/sorcery/model/adapters/mongoid.rb +59 -0
- data/lib/sorcery/model/submodules/activity_logging.rb +12 -3
- data/lib/sorcery/model/submodules/brute_force_protection.rb +6 -1
- data/lib/sorcery/model/submodules/external.rb +1 -0
- data/lib/sorcery/model/submodules/remember_me.rb +15 -1
- data/lib/sorcery/model/submodules/reset_password.rb +10 -3
- data/lib/sorcery/model/submodules/user_activation.rb +11 -1
- data/lib/sorcery/model/temporary_token.rb +1 -1
- data/lib/sorcery/model.rb +34 -6
- data/lib/sorcery/sinatra.rb +0 -1
- data/lib/sorcery/test_helpers/internal/rails.rb +52 -0
- data/lib/sorcery/test_helpers/internal/sinatra.rb +74 -0
- data/lib/sorcery/test_helpers/internal.rb +56 -0
- data/lib/sorcery/test_helpers/rails.rb +5 -43
- data/lib/sorcery/test_helpers/sinatra.rb +62 -102
- data/lib/sorcery/test_helpers.rb +0 -47
- data/lib/sorcery.rb +29 -1
- data/sorcery.gemspec +110 -10
- data/spec/Gemfile +1 -1
- data/spec/Gemfile.lock +12 -4
- data/spec/rails3/Gemfile +1 -1
- data/spec/rails3/Gemfile.lock +6 -6
- data/spec/rails3/spec/controller_activity_logging_spec.rb +2 -4
- data/spec/rails3/spec/controller_oauth_spec.rb +3 -3
- data/spec/rails3/spec/controller_session_timeout_spec.rb +20 -19
- data/spec/rails3/spec/controller_spec.rb +6 -16
- data/spec/rails3/spec/spec_helper.rb +2 -2
- data/spec/rails3/spec/user_activation_spec.rb +2 -12
- data/spec/rails3/spec/user_brute_force_protection_spec.rb +2 -30
- data/spec/rails3/spec/user_remember_me_spec.rb +3 -11
- data/spec/rails3/spec/user_reset_password_spec.rb +14 -15
- data/spec/rails3/spec/user_spec.rb +18 -3
- data/spec/rails3_mongoid/.gitignore +4 -0
- data/spec/rails3_mongoid/.rspec +1 -0
- data/spec/rails3_mongoid/Gemfile +14 -0
- data/spec/rails3_mongoid/Gemfile.lock +146 -0
- data/spec/rails3_mongoid/Rakefile +11 -0
- data/spec/rails3_mongoid/app/controllers/application_controller.rb +108 -0
- data/spec/rails3_mongoid/app/helpers/application_helper.rb +2 -0
- data/spec/rails3_mongoid/app/mailers/sorcery_mailer.rb +25 -0
- data/spec/rails3_mongoid/app/models/authentication.rb +7 -0
- data/spec/rails3_mongoid/app/models/user.rb +5 -0
- data/spec/rails3_mongoid/app/views/layouts/application.html.erb +14 -0
- data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_email.html.erb +17 -0
- data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_email.text.erb +9 -0
- data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_success_email.html.erb +17 -0
- data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_success_email.text.erb +9 -0
- data/spec/rails3_mongoid/app/views/sorcery_mailer/reset_password_email.html.erb +16 -0
- data/spec/rails3_mongoid/app/views/sorcery_mailer/reset_password_email.text.erb +8 -0
- data/spec/rails3_mongoid/config/application.rb +51 -0
- data/spec/rails3_mongoid/config/boot.rb +13 -0
- data/spec/rails3_mongoid/config/environment.rb +5 -0
- data/spec/rails3_mongoid/config/environments/development.rb +26 -0
- data/spec/rails3_mongoid/config/environments/in_memory.rb +0 -0
- data/spec/rails3_mongoid/config/environments/production.rb +49 -0
- data/spec/rails3_mongoid/config/environments/test.rb +35 -0
- data/spec/rails3_mongoid/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails3_mongoid/config/initializers/inflections.rb +10 -0
- data/spec/rails3_mongoid/config/initializers/mime_types.rb +5 -0
- data/spec/rails3_mongoid/config/initializers/secret_token.rb +7 -0
- data/spec/rails3_mongoid/config/initializers/session_store.rb +8 -0
- data/spec/rails3_mongoid/config/locales/en.yml +5 -0
- data/spec/rails3_mongoid/config/mongoid.yml +7 -0
- data/spec/rails3_mongoid/config/routes.rb +59 -0
- data/spec/rails3_mongoid/config.ru +4 -0
- data/spec/rails3_mongoid/db/schema.rb +23 -0
- data/spec/rails3_mongoid/db/seeds.rb +7 -0
- data/spec/rails3_mongoid/lib/tasks/.gitkeep +0 -0
- data/spec/rails3_mongoid/public/404.html +26 -0
- data/spec/rails3_mongoid/public/422.html +26 -0
- data/spec/rails3_mongoid/public/500.html +26 -0
- data/spec/rails3_mongoid/public/favicon.ico +0 -0
- data/spec/rails3_mongoid/public/images/rails.png +0 -0
- data/spec/rails3_mongoid/public/javascripts/application.js +2 -0
- data/spec/rails3_mongoid/public/javascripts/controls.js +965 -0
- data/spec/rails3_mongoid/public/javascripts/dragdrop.js +974 -0
- data/spec/rails3_mongoid/public/javascripts/effects.js +1123 -0
- data/spec/rails3_mongoid/public/javascripts/prototype.js +6001 -0
- data/spec/rails3_mongoid/public/javascripts/rails.js +175 -0
- data/spec/rails3_mongoid/public/robots.txt +5 -0
- data/spec/rails3_mongoid/public/stylesheets/.gitkeep +0 -0
- data/spec/rails3_mongoid/script/rails +6 -0
- data/spec/rails3_mongoid/spec/spec.opts +2 -0
- data/spec/rails3_mongoid/spec/spec_helper.orig.rb +27 -0
- data/spec/rails3_mongoid/spec/spec_helper.rb +55 -0
- data/spec/rails3_mongoid/spec/user_activation_spec.rb +178 -0
- data/spec/rails3_mongoid/spec/user_activity_logging_spec.rb +31 -0
- data/spec/rails3_mongoid/spec/user_brute_force_protection_spec.rb +41 -0
- data/spec/rails3_mongoid/spec/user_oauth_spec.rb +34 -0
- data/spec/rails3_mongoid/spec/user_remember_me_spec.rb +51 -0
- data/spec/rails3_mongoid/spec/user_reset_password_spec.rb +174 -0
- data/spec/rails3_mongoid/spec/user_spec.rb +329 -0
- data/spec/rails3_mongoid/vendor/plugins/.gitkeep +0 -0
- data/spec/sinatra/Gemfile +1 -1
- data/spec/sinatra/Gemfile.lock +6 -6
- data/spec/sinatra/spec/controller_session_timeout_spec.rb +23 -22
- data/spec/sinatra/spec/spec_helper.rb +2 -2
- metadata +153 -37
- data/spec/untitled folder +0 -18
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module Sorcery
|
|
2
|
+
module TestHelpers
|
|
3
|
+
module Internal
|
|
4
|
+
module Sinatra
|
|
5
|
+
include ::Sorcery::TestHelpers::Sinatra::CookieSessionMethods
|
|
6
|
+
include ::Sorcery::TestHelpers::Sinatra::InstanceMethods
|
|
7
|
+
|
|
8
|
+
class ::Sinatra::Application
|
|
9
|
+
class << self
|
|
10
|
+
attr_accessor :sorcery_vars
|
|
11
|
+
end
|
|
12
|
+
@sorcery_vars = {}
|
|
13
|
+
|
|
14
|
+
# NOTE: see before and after test filters in filters.rb
|
|
15
|
+
|
|
16
|
+
def save_instance_vars
|
|
17
|
+
instance_variables.each do |var|
|
|
18
|
+
self.class.sorcery_vars[:"#{var.to_s.delete("@")}"] = instance_variable_get(var)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
::RSpec::Matchers.define :redirect_to do |expected|
|
|
24
|
+
match do |actual|
|
|
25
|
+
actual.status == 302 && actual.location == expected
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def clear_user_without_logout
|
|
30
|
+
get_sinatra_app(subject).instance_variable_set(:@current_user, nil)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def assigns
|
|
34
|
+
::Sinatra::Application.sorcery_vars
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def sorcery_reload!(submodules = [], options = {})
|
|
38
|
+
reload_user_class
|
|
39
|
+
|
|
40
|
+
# return to no-module configuration
|
|
41
|
+
::Sorcery::Controller::Config.init!
|
|
42
|
+
::Sorcery::Controller::Config.reset!
|
|
43
|
+
|
|
44
|
+
# clear all filters
|
|
45
|
+
::Sinatra::Application.instance_variable_set(:@filters, {:before => [], :after => []})
|
|
46
|
+
::Sinatra::Application.class_eval do
|
|
47
|
+
load File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec', 'sinatra', 'filters.rb')
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# configure
|
|
51
|
+
::Sorcery::Controller::Config.submodules = submodules
|
|
52
|
+
::Sorcery::Controller::Config.user_class = nil
|
|
53
|
+
::Sinatra::Application.send(:include, Sorcery::Controller::Adapters::Sinatra)
|
|
54
|
+
::Sinatra::Application.send(:include, Sorcery::Controller)
|
|
55
|
+
|
|
56
|
+
::Sorcery::Controller::Config.user_config do |user|
|
|
57
|
+
options.each do |property, value|
|
|
58
|
+
user.send(:"#{property}=", value)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
User.authenticates_with_sorcery!
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def sorcery_controller_property_set(property, value)
|
|
65
|
+
::Sorcery::Controller::Config.send(:"#{property}=", value)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def sorcery_controller_external_property_set(provider, property, value)
|
|
69
|
+
::Sorcery::Controller::Config.send(provider).send(:"#{property}=", value)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module Sorcery
|
|
2
|
+
module TestHelpers
|
|
3
|
+
# Internal TestHelpers are used to test the gem, internally, and should not be used to test apps *using* sorcery.
|
|
4
|
+
# This file will be included in the spec_helper file.
|
|
5
|
+
module Internal
|
|
6
|
+
def self.included(base)
|
|
7
|
+
# reducing default cost for specs speed
|
|
8
|
+
CryptoProviders::BCrypt.class_eval do
|
|
9
|
+
class << self
|
|
10
|
+
def cost
|
|
11
|
+
1
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# a patch to fix a bug in testing that happens when you 'destroy' a session twice.
|
|
18
|
+
# After the first destroy, the session is an ordinary hash, and then when destroy is called again there's an exception.
|
|
19
|
+
class ::Hash
|
|
20
|
+
def destroy
|
|
21
|
+
clear
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def create_new_user(attributes_hash = nil)
|
|
26
|
+
user_attributes_hash = attributes_hash || {:username => 'gizmo', :email => "bla@bla.com", :password => 'secret'}
|
|
27
|
+
@user = User.new(user_attributes_hash)
|
|
28
|
+
@user.save!
|
|
29
|
+
@user
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def create_new_external_user(provider, attributes_hash = nil)
|
|
33
|
+
user_attributes_hash = attributes_hash || {:username => 'gizmo'}
|
|
34
|
+
@user = User.new(user_attributes_hash)
|
|
35
|
+
@user.save!
|
|
36
|
+
@user.authentications.create!({:provider => provider, :uid => 123})
|
|
37
|
+
@user
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def sorcery_model_property_set(property, *values)
|
|
41
|
+
User.class_eval do
|
|
42
|
+
sorcery_config.send(:"#{property}=", *values)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
# reload user class between specs
|
|
49
|
+
# so it will be possible to test the different submodules in isolation
|
|
50
|
+
def reload_user_class
|
|
51
|
+
Object.send(:remove_const,:User)
|
|
52
|
+
load 'user.rb'
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -1,54 +1,16 @@
|
|
|
1
1
|
module Sorcery
|
|
2
2
|
module TestHelpers
|
|
3
3
|
module Rails
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def sorcery_reload!(submodules = [], options = {})
|
|
7
|
-
reload_user_class
|
|
8
|
-
|
|
9
|
-
# return to no-module configuration
|
|
10
|
-
::Sorcery::Controller::Config.init!
|
|
11
|
-
::Sorcery::Controller::Config.reset!
|
|
12
|
-
|
|
13
|
-
# remove all plugin before_filters so they won't fail other tests.
|
|
14
|
-
# I don't like this way, but I didn't find another.
|
|
15
|
-
# hopefully it won't break until Rails 4.
|
|
16
|
-
ApplicationController._process_action_callbacks.delete_if {|c| SUBMODUELS_AUTO_ADDED_CONTROLLER_FILTERS.include?(c.filter) }
|
|
17
|
-
|
|
18
|
-
# configure
|
|
19
|
-
::Sorcery::Controller::Config.submodules = submodules
|
|
20
|
-
::Sorcery::Controller::Config.user_class = nil
|
|
21
|
-
ActionController::Base.send(:include,::Sorcery::Controller)
|
|
22
|
-
|
|
23
|
-
::Sorcery::Controller::Config.user_config do |user|
|
|
24
|
-
options.each do |property,value|
|
|
25
|
-
user.send(:"#{property}=", value)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
User.authenticates_with_sorcery!
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def sorcery_controller_property_set(property, value)
|
|
32
|
-
::Sorcery::Controller::Config.send(:"#{property}=", value)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def sorcery_controller_external_property_set(provider, property, value)
|
|
36
|
-
::Sorcery::Controller::Config.send(provider).send(:"#{property}=", value)
|
|
37
|
-
end
|
|
38
|
-
|
|
4
|
+
# logins a user and calls all callbacks
|
|
39
5
|
def login_user(user = nil)
|
|
40
6
|
user ||= @user
|
|
41
|
-
|
|
42
|
-
|
|
7
|
+
@controller.send(:login_user,user)
|
|
8
|
+
@controller.send(:after_login!,user,[user.send(user.sorcery_config.username_attribute_name),'secret'])
|
|
43
9
|
end
|
|
44
10
|
|
|
45
11
|
def logout_user
|
|
46
|
-
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def clear_user_without_logout
|
|
50
|
-
subject.instance_variable_set(:@current_user,nil)
|
|
12
|
+
@controller.send(:logout)
|
|
51
13
|
end
|
|
52
14
|
end
|
|
53
15
|
end
|
|
54
|
-
end
|
|
16
|
+
end
|
|
@@ -1,127 +1,87 @@
|
|
|
1
1
|
module Sorcery
|
|
2
2
|
module TestHelpers
|
|
3
3
|
module Sinatra
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
def self.included(base)
|
|
5
|
+
base.send(:include, InstanceMethods)
|
|
6
|
+
base.send(:include, CookieSessionMethods)
|
|
7
|
+
::Sinatra::Base.class_eval do
|
|
8
|
+
class << self
|
|
9
|
+
attr_accessor :rack_test_session
|
|
9
10
|
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
class ::Sinatra::Application
|
|
14
|
-
class << self
|
|
15
|
-
attr_accessor :sorcery_vars
|
|
16
|
-
end
|
|
17
|
-
@sorcery_vars = {}
|
|
18
11
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
def self.inherited(subclass)
|
|
13
|
+
super
|
|
14
|
+
subclass.class_eval do
|
|
15
|
+
class << self
|
|
16
|
+
attr_accessor :rack_test_session
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
include CookieSessionMethods
|
|
22
|
+
|
|
23
|
+
def rack_test_session
|
|
24
|
+
self.class.rack_test_session
|
|
24
25
|
end
|
|
25
26
|
end
|
|
26
27
|
end
|
|
27
|
-
|
|
28
|
-
::RSpec::Matchers.define :redirect_to do |expected|
|
|
29
|
-
match do |actual|
|
|
30
|
-
actual.status == 302 && actual.location == expected
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def get_sinatra_app(app)
|
|
35
|
-
while app.class != ::Sinatra::Application do
|
|
36
|
-
app = app.instance_variable_get(:@app)
|
|
37
|
-
end
|
|
38
|
-
app
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def login_user(user=nil)
|
|
42
|
-
user ||= @user
|
|
43
|
-
get_sinatra_app(subject).send(:login_user,user)
|
|
44
|
-
get_sinatra_app(subject).send(:after_login!,user,[user.username,'secret'])
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def logout_user
|
|
48
|
-
get_sinatra_app(subject).send(:logout)
|
|
49
|
-
end
|
|
50
28
|
|
|
51
|
-
|
|
52
|
-
get_sinatra_app(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def assigns
|
|
56
|
-
::Sinatra::Application.sorcery_vars
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
class SessionData
|
|
60
|
-
def initialize(cookies)
|
|
61
|
-
@cookies = cookies
|
|
62
|
-
@data = cookies['rack.session']
|
|
63
|
-
if @data
|
|
64
|
-
@data = @data.unpack("m*").first
|
|
65
|
-
@data = Marshal.load(@data)
|
|
66
|
-
else
|
|
67
|
-
@data = {}
|
|
29
|
+
module InstanceMethods
|
|
30
|
+
def get_sinatra_app(app)
|
|
31
|
+
while !app.kind_of? ::Sinatra::Base do
|
|
32
|
+
app = app.instance_variable_get(:@app)
|
|
68
33
|
end
|
|
34
|
+
app
|
|
69
35
|
end
|
|
70
36
|
|
|
71
|
-
def
|
|
72
|
-
@
|
|
37
|
+
def login_user(user=nil)
|
|
38
|
+
user ||= @user
|
|
39
|
+
get_sinatra_app(app).send(:login_user, user)
|
|
40
|
+
get_sinatra_app(app).send(:after_login!, user, [user.send(user.sorcery_config.username_attribute_name), 'secret'])
|
|
73
41
|
end
|
|
74
42
|
|
|
75
|
-
def
|
|
76
|
-
|
|
77
|
-
session_data = Marshal.dump(@data)
|
|
78
|
-
session_data = [session_data].pack("m*")
|
|
79
|
-
@cookies.merge("rack.session=#{Rack::Utils.escape(session_data)}", URI.parse("//example.org//"))
|
|
80
|
-
raise "session variable not set" unless @cookies['rack.session'] == session_data
|
|
43
|
+
def logout_user
|
|
44
|
+
get_sinatra_app(app).send(:logout)
|
|
81
45
|
end
|
|
82
46
|
end
|
|
83
47
|
|
|
84
|
-
|
|
85
|
-
SessionData
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
48
|
+
module CookieSessionMethods
|
|
49
|
+
class SessionData
|
|
50
|
+
def initialize(cookies)
|
|
51
|
+
@cookies = cookies
|
|
52
|
+
@data = cookies['rack.session']
|
|
53
|
+
if @data
|
|
54
|
+
@data = @data.unpack("m*").first
|
|
55
|
+
@data = Marshal.load(@data)
|
|
56
|
+
else
|
|
57
|
+
@data = {}
|
|
58
|
+
end
|
|
59
|
+
end
|
|
94
60
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
61
|
+
def [](key)
|
|
62
|
+
@data[key]
|
|
63
|
+
end
|
|
98
64
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
::Sinatra::Application.send(:include, Sorcery::Controller)
|
|
110
|
-
|
|
111
|
-
::Sorcery::Controller::Config.user_config do |user|
|
|
112
|
-
options.each do |property,value|
|
|
113
|
-
user.send(:"#{property}=", value)
|
|
65
|
+
def []=(key, value)
|
|
66
|
+
@data[key] = value
|
|
67
|
+
session_data = Marshal.dump(@data)
|
|
68
|
+
session_data = [session_data].pack("m*")
|
|
69
|
+
@cookies.merge("rack.session=#{Rack::Utils.escape(session_data)}", URI.parse("//example.org//"))
|
|
70
|
+
raise "session variable not set" unless @cookies['rack.session'] == session_data
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def clear
|
|
74
|
+
@data = {}
|
|
114
75
|
end
|
|
115
76
|
end
|
|
116
|
-
User.authenticates_with_sorcery!
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def sorcery_controller_property_set(property, value)
|
|
120
|
-
::Sorcery::Controller::Config.send(:"#{property}=", value)
|
|
121
|
-
end
|
|
122
77
|
|
|
123
|
-
|
|
124
|
-
|
|
78
|
+
def session
|
|
79
|
+
SessionData.new(cookies)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def cookies
|
|
83
|
+
rack_test_session.instance_variable_get(:@rack_mock_session).cookie_jar
|
|
84
|
+
end
|
|
125
85
|
end
|
|
126
86
|
end
|
|
127
87
|
end
|
data/lib/sorcery/test_helpers.rb
CHANGED
|
@@ -1,52 +1,5 @@
|
|
|
1
1
|
module Sorcery
|
|
2
|
-
# This file will be included in the spec_helper file.
|
|
3
2
|
module TestHelpers
|
|
4
|
-
def self.included(base)
|
|
5
|
-
# reducing default cost for specs speed
|
|
6
|
-
CryptoProviders::BCrypt.class_eval do
|
|
7
|
-
class << self
|
|
8
|
-
def cost
|
|
9
|
-
1
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
# a patch to fix a bug in testing that happens when you 'destroy' a session twice.
|
|
16
|
-
# After the first destroy, the session is an ordinary hash, and then when destroy is called again there's an exception.
|
|
17
|
-
class ::Hash
|
|
18
|
-
def destroy
|
|
19
|
-
clear
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def create_new_user(attributes_hash = nil)
|
|
24
|
-
user_attributes_hash = attributes_hash || {:username => 'gizmo', :email => "bla@bla.com", :password => 'secret'}
|
|
25
|
-
@user = User.new(user_attributes_hash)
|
|
26
|
-
@user.save!
|
|
27
|
-
@user
|
|
28
|
-
end
|
|
29
3
|
|
|
30
|
-
def create_new_external_user(provider, attributes_hash = nil)
|
|
31
|
-
user_attributes_hash = attributes_hash || {:username => 'gizmo', :authentications_attributes => [{:provider => provider, :uid => 123}]}
|
|
32
|
-
@user = User.new(user_attributes_hash)
|
|
33
|
-
@user.save!
|
|
34
|
-
@user
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def sorcery_model_property_set(property, *values)
|
|
38
|
-
User.class_eval do
|
|
39
|
-
sorcery_config.send(:"#{property}=", *values)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
private
|
|
44
|
-
|
|
45
|
-
# reload user class between specs
|
|
46
|
-
# so it will be possible to test the different submodules in isolation
|
|
47
|
-
def reload_user_class
|
|
48
|
-
Object.send(:remove_const,:User)
|
|
49
|
-
load 'user.rb'
|
|
50
|
-
end
|
|
51
4
|
end
|
|
52
5
|
end
|
data/lib/sorcery.rb
CHANGED
|
@@ -2,6 +2,10 @@ module Sorcery
|
|
|
2
2
|
autoload :Model, 'sorcery/model'
|
|
3
3
|
module Model
|
|
4
4
|
autoload :TemporaryToken, 'sorcery/model/temporary_token'
|
|
5
|
+
module Adapters
|
|
6
|
+
autoload :ActiveRecord, 'sorcery/model/adapters/active_record'
|
|
7
|
+
autoload :Mongoid, 'sorcery/model/adapters/mongoid'
|
|
8
|
+
end
|
|
5
9
|
module Submodules
|
|
6
10
|
autoload :UserActivation, 'sorcery/model/submodules/user_activation'
|
|
7
11
|
autoload :ResetPassword, 'sorcery/model/submodules/reset_password'
|
|
@@ -48,8 +52,32 @@ module Sorcery
|
|
|
48
52
|
module TestHelpers
|
|
49
53
|
autoload :Rails, 'sorcery/test_helpers/rails'
|
|
50
54
|
autoload :Sinatra, 'sorcery/test_helpers/sinatra'
|
|
55
|
+
autoload :Internal, 'sorcery/test_helpers/internal'
|
|
56
|
+
module Internal
|
|
57
|
+
autoload :Rails, 'sorcery/test_helpers/internal/rails'
|
|
58
|
+
autoload :Sinatra, 'sorcery/test_helpers/internal/sinatra'
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
if defined?(ActiveRecord)
|
|
64
|
+
ActiveRecord::Base.send(:include, Sorcery::Model)
|
|
65
|
+
ActiveRecord::Base.send(:include, ::Sorcery::Model::Adapters::ActiveRecord)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
if defined?(Mongoid)
|
|
69
|
+
Mongoid::Document.module_eval do
|
|
70
|
+
included do
|
|
71
|
+
attr_reader :new_record
|
|
72
|
+
include Sorcery::Model::Adapters::Mongoid
|
|
73
|
+
include Sorcery::Model
|
|
74
|
+
end
|
|
75
|
+
end
|
|
51
76
|
end
|
|
52
|
-
|
|
77
|
+
|
|
53
78
|
require 'sorcery/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
|
54
79
|
require 'sorcery/sinatra' if defined?(Sinatra)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
55
83
|
end
|
data/sorcery.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{sorcery}
|
|
8
|
-
s.version = "0.
|
|
8
|
+
s.version = "0.5.0"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Noam Ben Ari"]
|
|
12
|
-
s.date = %q{2011-
|
|
12
|
+
s.date = %q{2011-05-10}
|
|
13
13
|
s.description = %q{Provides common authentication needs such as signing in/out, activating by email and resetting password.}
|
|
14
14
|
s.email = %q{nbenari@gmail.com}
|
|
15
15
|
s.extra_rdoc_files = [
|
|
@@ -56,6 +56,8 @@ Gem::Specification.new do |s|
|
|
|
56
56
|
"lib/sorcery/engine.rb",
|
|
57
57
|
"lib/sorcery/initializers/initializer.rb",
|
|
58
58
|
"lib/sorcery/model.rb",
|
|
59
|
+
"lib/sorcery/model/adapters/active_record.rb",
|
|
60
|
+
"lib/sorcery/model/adapters/mongoid.rb",
|
|
59
61
|
"lib/sorcery/model/submodules/activity_logging.rb",
|
|
60
62
|
"lib/sorcery/model/submodules/brute_force_protection.rb",
|
|
61
63
|
"lib/sorcery/model/submodules/external.rb",
|
|
@@ -66,6 +68,9 @@ Gem::Specification.new do |s|
|
|
|
66
68
|
"lib/sorcery/railties/tasks.rake",
|
|
67
69
|
"lib/sorcery/sinatra.rb",
|
|
68
70
|
"lib/sorcery/test_helpers.rb",
|
|
71
|
+
"lib/sorcery/test_helpers/internal.rb",
|
|
72
|
+
"lib/sorcery/test_helpers/internal/rails.rb",
|
|
73
|
+
"lib/sorcery/test_helpers/internal/sinatra.rb",
|
|
69
74
|
"lib/sorcery/test_helpers/rails.rb",
|
|
70
75
|
"lib/sorcery/test_helpers/sinatra.rb",
|
|
71
76
|
"sorcery.gemspec",
|
|
@@ -151,6 +156,67 @@ Gem::Specification.new do |s|
|
|
|
151
156
|
"spec/rails3/spec/user_reset_password_spec.rb",
|
|
152
157
|
"spec/rails3/spec/user_spec.rb",
|
|
153
158
|
"spec/rails3/vendor/plugins/.gitkeep",
|
|
159
|
+
"spec/rails3_mongoid/.gitignore",
|
|
160
|
+
"spec/rails3_mongoid/.rspec",
|
|
161
|
+
"spec/rails3_mongoid/Gemfile",
|
|
162
|
+
"spec/rails3_mongoid/Gemfile.lock",
|
|
163
|
+
"spec/rails3_mongoid/Rakefile",
|
|
164
|
+
"spec/rails3_mongoid/app/controllers/application_controller.rb",
|
|
165
|
+
"spec/rails3_mongoid/app/helpers/application_helper.rb",
|
|
166
|
+
"spec/rails3_mongoid/app/mailers/sorcery_mailer.rb",
|
|
167
|
+
"spec/rails3_mongoid/app/models/authentication.rb",
|
|
168
|
+
"spec/rails3_mongoid/app/models/user.rb",
|
|
169
|
+
"spec/rails3_mongoid/app/views/layouts/application.html.erb",
|
|
170
|
+
"spec/rails3_mongoid/app/views/sorcery_mailer/activation_email.html.erb",
|
|
171
|
+
"spec/rails3_mongoid/app/views/sorcery_mailer/activation_email.text.erb",
|
|
172
|
+
"spec/rails3_mongoid/app/views/sorcery_mailer/activation_success_email.html.erb",
|
|
173
|
+
"spec/rails3_mongoid/app/views/sorcery_mailer/activation_success_email.text.erb",
|
|
174
|
+
"spec/rails3_mongoid/app/views/sorcery_mailer/reset_password_email.html.erb",
|
|
175
|
+
"spec/rails3_mongoid/app/views/sorcery_mailer/reset_password_email.text.erb",
|
|
176
|
+
"spec/rails3_mongoid/config.ru",
|
|
177
|
+
"spec/rails3_mongoid/config/application.rb",
|
|
178
|
+
"spec/rails3_mongoid/config/boot.rb",
|
|
179
|
+
"spec/rails3_mongoid/config/environment.rb",
|
|
180
|
+
"spec/rails3_mongoid/config/environments/development.rb",
|
|
181
|
+
"spec/rails3_mongoid/config/environments/in_memory.rb",
|
|
182
|
+
"spec/rails3_mongoid/config/environments/production.rb",
|
|
183
|
+
"spec/rails3_mongoid/config/environments/test.rb",
|
|
184
|
+
"spec/rails3_mongoid/config/initializers/backtrace_silencers.rb",
|
|
185
|
+
"spec/rails3_mongoid/config/initializers/inflections.rb",
|
|
186
|
+
"spec/rails3_mongoid/config/initializers/mime_types.rb",
|
|
187
|
+
"spec/rails3_mongoid/config/initializers/secret_token.rb",
|
|
188
|
+
"spec/rails3_mongoid/config/initializers/session_store.rb",
|
|
189
|
+
"spec/rails3_mongoid/config/locales/en.yml",
|
|
190
|
+
"spec/rails3_mongoid/config/mongoid.yml",
|
|
191
|
+
"spec/rails3_mongoid/config/routes.rb",
|
|
192
|
+
"spec/rails3_mongoid/db/schema.rb",
|
|
193
|
+
"spec/rails3_mongoid/db/seeds.rb",
|
|
194
|
+
"spec/rails3_mongoid/lib/tasks/.gitkeep",
|
|
195
|
+
"spec/rails3_mongoid/public/404.html",
|
|
196
|
+
"spec/rails3_mongoid/public/422.html",
|
|
197
|
+
"spec/rails3_mongoid/public/500.html",
|
|
198
|
+
"spec/rails3_mongoid/public/favicon.ico",
|
|
199
|
+
"spec/rails3_mongoid/public/images/rails.png",
|
|
200
|
+
"spec/rails3_mongoid/public/javascripts/application.js",
|
|
201
|
+
"spec/rails3_mongoid/public/javascripts/controls.js",
|
|
202
|
+
"spec/rails3_mongoid/public/javascripts/dragdrop.js",
|
|
203
|
+
"spec/rails3_mongoid/public/javascripts/effects.js",
|
|
204
|
+
"spec/rails3_mongoid/public/javascripts/prototype.js",
|
|
205
|
+
"spec/rails3_mongoid/public/javascripts/rails.js",
|
|
206
|
+
"spec/rails3_mongoid/public/robots.txt",
|
|
207
|
+
"spec/rails3_mongoid/public/stylesheets/.gitkeep",
|
|
208
|
+
"spec/rails3_mongoid/script/rails",
|
|
209
|
+
"spec/rails3_mongoid/spec/spec.opts",
|
|
210
|
+
"spec/rails3_mongoid/spec/spec_helper.orig.rb",
|
|
211
|
+
"spec/rails3_mongoid/spec/spec_helper.rb",
|
|
212
|
+
"spec/rails3_mongoid/spec/user_activation_spec.rb",
|
|
213
|
+
"spec/rails3_mongoid/spec/user_activity_logging_spec.rb",
|
|
214
|
+
"spec/rails3_mongoid/spec/user_brute_force_protection_spec.rb",
|
|
215
|
+
"spec/rails3_mongoid/spec/user_oauth_spec.rb",
|
|
216
|
+
"spec/rails3_mongoid/spec/user_remember_me_spec.rb",
|
|
217
|
+
"spec/rails3_mongoid/spec/user_reset_password_spec.rb",
|
|
218
|
+
"spec/rails3_mongoid/spec/user_spec.rb",
|
|
219
|
+
"spec/rails3_mongoid/vendor/plugins/.gitkeep",
|
|
154
220
|
"spec/sinatra/Gemfile",
|
|
155
221
|
"spec/sinatra/Gemfile.lock",
|
|
156
222
|
"spec/sinatra/Rakefile",
|
|
@@ -179,8 +245,7 @@ Gem::Specification.new do |s|
|
|
|
179
245
|
"spec/sinatra/views/test_login.erb",
|
|
180
246
|
"spec/sorcery_crypto_providers_spec.rb",
|
|
181
247
|
"spec/spec.opts",
|
|
182
|
-
"spec/spec_helper.rb"
|
|
183
|
-
"spec/untitled folder"
|
|
248
|
+
"spec/spec_helper.rb"
|
|
184
249
|
]
|
|
185
250
|
s.homepage = %q{http://github.com/NoamB/sorcery}
|
|
186
251
|
s.licenses = ["MIT"]
|
|
@@ -232,6 +297,35 @@ Gem::Specification.new do |s|
|
|
|
232
297
|
"spec/rails3/spec/user_remember_me_spec.rb",
|
|
233
298
|
"spec/rails3/spec/user_reset_password_spec.rb",
|
|
234
299
|
"spec/rails3/spec/user_spec.rb",
|
|
300
|
+
"spec/rails3_mongoid/app/controllers/application_controller.rb",
|
|
301
|
+
"spec/rails3_mongoid/app/helpers/application_helper.rb",
|
|
302
|
+
"spec/rails3_mongoid/app/mailers/sorcery_mailer.rb",
|
|
303
|
+
"spec/rails3_mongoid/app/models/authentication.rb",
|
|
304
|
+
"spec/rails3_mongoid/app/models/user.rb",
|
|
305
|
+
"spec/rails3_mongoid/config/application.rb",
|
|
306
|
+
"spec/rails3_mongoid/config/boot.rb",
|
|
307
|
+
"spec/rails3_mongoid/config/environment.rb",
|
|
308
|
+
"spec/rails3_mongoid/config/environments/development.rb",
|
|
309
|
+
"spec/rails3_mongoid/config/environments/in_memory.rb",
|
|
310
|
+
"spec/rails3_mongoid/config/environments/production.rb",
|
|
311
|
+
"spec/rails3_mongoid/config/environments/test.rb",
|
|
312
|
+
"spec/rails3_mongoid/config/initializers/backtrace_silencers.rb",
|
|
313
|
+
"spec/rails3_mongoid/config/initializers/inflections.rb",
|
|
314
|
+
"spec/rails3_mongoid/config/initializers/mime_types.rb",
|
|
315
|
+
"spec/rails3_mongoid/config/initializers/secret_token.rb",
|
|
316
|
+
"spec/rails3_mongoid/config/initializers/session_store.rb",
|
|
317
|
+
"spec/rails3_mongoid/config/routes.rb",
|
|
318
|
+
"spec/rails3_mongoid/db/schema.rb",
|
|
319
|
+
"spec/rails3_mongoid/db/seeds.rb",
|
|
320
|
+
"spec/rails3_mongoid/spec/spec_helper.orig.rb",
|
|
321
|
+
"spec/rails3_mongoid/spec/spec_helper.rb",
|
|
322
|
+
"spec/rails3_mongoid/spec/user_activation_spec.rb",
|
|
323
|
+
"spec/rails3_mongoid/spec/user_activity_logging_spec.rb",
|
|
324
|
+
"spec/rails3_mongoid/spec/user_brute_force_protection_spec.rb",
|
|
325
|
+
"spec/rails3_mongoid/spec/user_oauth_spec.rb",
|
|
326
|
+
"spec/rails3_mongoid/spec/user_remember_me_spec.rb",
|
|
327
|
+
"spec/rails3_mongoid/spec/user_reset_password_spec.rb",
|
|
328
|
+
"spec/rails3_mongoid/spec/user_spec.rb",
|
|
235
329
|
"spec/sinatra/authentication.rb",
|
|
236
330
|
"spec/sinatra/db/migrate/activation/20101224223622_add_activation_to_users.rb",
|
|
237
331
|
"spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb",
|
|
@@ -261,10 +355,12 @@ Gem::Specification.new do |s|
|
|
|
261
355
|
s.specification_version = 3
|
|
262
356
|
|
|
263
357
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
264
|
-
s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
|
|
265
|
-
s.add_runtime_dependency(%q<json>, [">= 1.5.1"])
|
|
266
358
|
s.add_runtime_dependency(%q<oauth>, [">= 0.4.4"])
|
|
267
359
|
s.add_runtime_dependency(%q<oauth2>, [">= 0.1.1"])
|
|
360
|
+
s.add_development_dependency(%q<rails>, [">= 3.0.0"])
|
|
361
|
+
s.add_development_dependency(%q<json>, [">= 1.5.1"])
|
|
362
|
+
s.add_development_dependency(%q<mongoid>, ["~> 2.0"])
|
|
363
|
+
s.add_development_dependency(%q<bson_ext>, ["~> 1.3"])
|
|
268
364
|
s.add_development_dependency(%q<rspec>, ["~> 2.5.0"])
|
|
269
365
|
s.add_development_dependency(%q<rspec-rails>, ["~> 2.5.0"])
|
|
270
366
|
s.add_development_dependency(%q<ruby-debug19>, [">= 0"])
|
|
@@ -278,10 +374,12 @@ Gem::Specification.new do |s|
|
|
|
278
374
|
s.add_runtime_dependency(%q<oauth>, [">= 0.4.4"])
|
|
279
375
|
s.add_runtime_dependency(%q<oauth2>, [">= 0.1.1"])
|
|
280
376
|
else
|
|
281
|
-
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
|
282
|
-
s.add_dependency(%q<json>, [">= 1.5.1"])
|
|
283
377
|
s.add_dependency(%q<oauth>, [">= 0.4.4"])
|
|
284
378
|
s.add_dependency(%q<oauth2>, [">= 0.1.1"])
|
|
379
|
+
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
|
380
|
+
s.add_dependency(%q<json>, [">= 1.5.1"])
|
|
381
|
+
s.add_dependency(%q<mongoid>, ["~> 2.0"])
|
|
382
|
+
s.add_dependency(%q<bson_ext>, ["~> 1.3"])
|
|
285
383
|
s.add_dependency(%q<rspec>, ["~> 2.5.0"])
|
|
286
384
|
s.add_dependency(%q<rspec-rails>, ["~> 2.5.0"])
|
|
287
385
|
s.add_dependency(%q<ruby-debug19>, [">= 0"])
|
|
@@ -296,10 +394,12 @@ Gem::Specification.new do |s|
|
|
|
296
394
|
s.add_dependency(%q<oauth2>, [">= 0.1.1"])
|
|
297
395
|
end
|
|
298
396
|
else
|
|
299
|
-
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
|
300
|
-
s.add_dependency(%q<json>, [">= 1.5.1"])
|
|
301
397
|
s.add_dependency(%q<oauth>, [">= 0.4.4"])
|
|
302
398
|
s.add_dependency(%q<oauth2>, [">= 0.1.1"])
|
|
399
|
+
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
|
400
|
+
s.add_dependency(%q<json>, [">= 1.5.1"])
|
|
401
|
+
s.add_dependency(%q<mongoid>, ["~> 2.0"])
|
|
402
|
+
s.add_dependency(%q<bson_ext>, ["~> 1.3"])
|
|
303
403
|
s.add_dependency(%q<rspec>, ["~> 2.5.0"])
|
|
304
404
|
s.add_dependency(%q<rspec-rails>, ["~> 2.5.0"])
|
|
305
405
|
s.add_dependency(%q<ruby-debug19>, [">= 0"])
|