sorcery 0.2.1 → 0.4.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 +3 -2
- data/Gemfile.lock +13 -11
- data/README.rdoc +157 -61
- data/Rakefile +4 -4
- data/VERSION +1 -1
- data/lib/generators/sorcery_migration/sorcery_migration_generator.rb +24 -0
- data/lib/generators/sorcery_migration/templates/activity_logging.rb +17 -0
- data/lib/generators/sorcery_migration/templates/brute_force_protection.rb +11 -0
- data/lib/generators/sorcery_migration/templates/core.rb +16 -0
- data/lib/generators/sorcery_migration/templates/external.rb +14 -0
- data/lib/generators/sorcery_migration/templates/remember_me.rb +15 -0
- data/lib/generators/sorcery_migration/templates/reset_password.rb +13 -0
- data/lib/generators/sorcery_migration/templates/user_activation.rb +17 -0
- data/lib/sorcery/controller/adapters/sinatra.rb +97 -0
- data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +35 -0
- data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +26 -0
- data/lib/sorcery/controller/submodules/{oauth → external}/providers/facebook.rb +24 -6
- data/lib/sorcery/controller/submodules/{oauth → external}/providers/twitter.rb +31 -6
- data/lib/sorcery/controller/submodules/{oauth.rb → external.rb} +18 -27
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +11 -7
- data/lib/sorcery/controller.rb +21 -21
- data/lib/sorcery/crypto_providers/bcrypt.rb +1 -1
- data/lib/sorcery/crypto_providers/common.rb +35 -0
- data/lib/sorcery/crypto_providers/md5.rb +3 -23
- data/lib/sorcery/crypto_providers/sha1.rb +4 -16
- data/lib/sorcery/crypto_providers/sha256.rb +3 -23
- data/lib/sorcery/crypto_providers/sha512.rb +3 -23
- data/lib/sorcery/engine.rb +4 -0
- data/lib/sorcery/initializers/initializer.rb +86 -0
- data/lib/sorcery/model/submodules/activity_logging.rb +1 -1
- data/lib/sorcery/model/submodules/brute_force_protection.rb +0 -4
- data/lib/sorcery/model/submodules/{oauth.rb → external.rb} +3 -3
- data/lib/sorcery/model.rb +13 -8
- data/lib/sorcery/railties/tasks.rake +10 -0
- data/lib/sorcery/sinatra.rb +5 -0
- data/lib/sorcery/test_helpers/rails.rb +54 -0
- data/lib/sorcery/test_helpers/sinatra.rb +128 -0
- data/lib/sorcery/test_helpers.rb +20 -52
- data/lib/sorcery.rb +18 -7
- data/sorcery.gemspec +204 -137
- data/spec/Gemfile +2 -2
- data/spec/Gemfile.lock +10 -10
- data/spec/Rakefile +1 -0
- data/spec/rails3/.rspec +1 -1
- data/spec/rails3/{app_root/Gemfile → Gemfile} +5 -7
- data/spec/rails3/{app_root/Gemfile.lock → Gemfile.lock} +20 -23
- data/spec/rails3/{app_root/Rakefile → Rakefile} +1 -0
- data/spec/rails3/{app_root/app → app}/controllers/application_controller.rb +11 -11
- data/spec/rails3/config/database.yml +27 -0
- data/spec/rails3/{app_root/spec → spec}/controller_brute_force_protection_spec.rb +3 -2
- data/spec/rails3/{app_root/spec → spec}/controller_oauth2_spec.rb +25 -22
- data/spec/rails3/{app_root/spec → spec}/controller_oauth_spec.rb +23 -18
- data/spec/rails3/{app_root/spec → spec}/controller_session_timeout_spec.rb +10 -6
- data/spec/rails3/spec/spec.opts +2 -0
- data/spec/rails3/spec/spec_helper.rb +70 -0
- data/spec/rails3/{app_root/spec → spec}/user_activation_spec.rb +5 -1
- data/spec/rails3/{app_root/spec → spec}/user_oauth_spec.rb +7 -7
- data/spec/rails3/{app_root/spec → spec}/user_reset_password_spec.rb +7 -3
- data/spec/rails3/{app_root/spec → spec}/user_spec.rb +5 -11
- data/spec/sinatra/Gemfile +12 -0
- data/spec/sinatra/Gemfile.lock +134 -0
- data/spec/sinatra/Rakefile +11 -0
- data/spec/sinatra/authentication.rb +3 -0
- data/spec/sinatra/db/migrate/activation/20101224223622_add_activation_to_users.rb +17 -0
- data/spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +17 -0
- data/spec/sinatra/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +11 -0
- data/spec/sinatra/db/migrate/core/20101224223620_create_users.rb +16 -0
- data/spec/sinatra/db/migrate/external/20101224223628_create_authentications.rb +14 -0
- data/spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +15 -0
- data/spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +13 -0
- data/spec/sinatra/filters.rb +21 -0
- data/spec/sinatra/myapp.rb +133 -0
- data/spec/sinatra/sorcery_mailer.rb +25 -0
- data/spec/sinatra/spec/controller_activity_logging_spec.rb +85 -0
- data/spec/sinatra/spec/controller_brute_force_protection_spec.rb +70 -0
- data/spec/sinatra/spec/controller_http_basic_auth_spec.rb +53 -0
- data/spec/sinatra/spec/controller_oauth2_spec.rb +120 -0
- data/spec/sinatra/spec/controller_oauth_spec.rb +121 -0
- data/spec/sinatra/spec/controller_remember_me_spec.rb +64 -0
- data/spec/sinatra/spec/controller_session_timeout_spec.rb +56 -0
- data/spec/sinatra/spec/controller_spec.rb +120 -0
- data/spec/sinatra/spec/spec.opts +2 -0
- data/spec/sinatra/spec/spec_helper.rb +45 -0
- data/spec/sinatra/user.rb +6 -0
- data/spec/sinatra/views/test_login.erb +4 -0
- data/spec/sorcery_crypto_providers_spec.rb +5 -4
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +3 -4
- data/spec/untitled folder +18 -0
- metadata +214 -139
- data/lib/sorcery/controller/submodules/oauth/oauth1.rb +0 -26
- data/lib/sorcery/controller/submodules/oauth/oauth2.rb +0 -24
- data/spec/rails3/app_root/.rspec +0 -1
- data/spec/rails3/app_root/config/database.yml +0 -27
- data/spec/rails3/app_root/spec/spec_helper.rb +0 -61
- /data/spec/rails3/{app_root/.gitignore → .gitignore} +0 -0
- /data/spec/rails3/{app_root/README → README} +0 -0
- /data/spec/rails3/{app_root/Rakefile.unused → Rakefile.unused} +0 -0
- /data/spec/rails3/{app_root/app → app}/helpers/application_helper.rb +0 -0
- /data/spec/rails3/{app_root/app → app}/mailers/sorcery_mailer.rb +0 -0
- /data/spec/rails3/{app_root/app → app}/models/authentication.rb +0 -0
- /data/spec/rails3/{app_root/app → app}/models/user.rb +0 -0
- /data/spec/rails3/{app_root/app → app}/views/layouts/application.html.erb +0 -0
- /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_email.html.erb +0 -0
- /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_email.text.erb +0 -0
- /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_success_email.html.erb +0 -0
- /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/activation_success_email.text.erb +0 -0
- /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/reset_password_email.html.erb +0 -0
- /data/spec/rails3/{app_root/app → app}/views/sorcery_mailer/reset_password_email.text.erb +0 -0
- /data/spec/rails3/{app_root/config → config}/application.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/boot.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/environment.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/environments/development.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/environments/in_memory.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/environments/production.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/environments/test.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/initializers/backtrace_silencers.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/initializers/inflections.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/initializers/mime_types.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/initializers/secret_token.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/initializers/session_store.rb +0 -0
- /data/spec/rails3/{app_root/config → config}/locales/en.yml +0 -0
- /data/spec/rails3/{app_root/config → config}/routes.rb +0 -0
- /data/spec/rails3/{app_root/config.ru → config.ru} +0 -0
- /data/spec/rails3/{app_root/db → db}/migrate/activation/20101224223622_add_activation_to_users.rb +0 -0
- /data/spec/rails3/{app_root/db → db}/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -0
- /data/spec/rails3/{app_root/db → db}/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -0
- /data/spec/rails3/{app_root/db → db}/migrate/core/20101224223620_create_users.rb +0 -0
- /data/spec/rails3/{app_root/db/migrate/oauth → db/migrate/external}/20101224223628_create_authentications.rb +0 -0
- /data/spec/rails3/{app_root/db → db}/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -0
- /data/spec/rails3/{app_root/db → db}/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -0
- /data/spec/rails3/{app_root/db → db}/schema.rb +0 -0
- /data/spec/rails3/{app_root/db → db}/seeds.rb +0 -0
- /data/spec/rails3/{app_root/lib → lib}/tasks/.gitkeep +0 -0
- /data/spec/rails3/{app_root/public → public}/404.html +0 -0
- /data/spec/rails3/{app_root/public → public}/422.html +0 -0
- /data/spec/rails3/{app_root/public → public}/500.html +0 -0
- /data/spec/rails3/{app_root/public → public}/favicon.ico +0 -0
- /data/spec/rails3/{app_root/public → public}/images/rails.png +0 -0
- /data/spec/rails3/{app_root/public → public}/index.html +0 -0
- /data/spec/rails3/{app_root/public → public}/javascripts/application.js +0 -0
- /data/spec/rails3/{app_root/public → public}/javascripts/controls.js +0 -0
- /data/spec/rails3/{app_root/public → public}/javascripts/dragdrop.js +0 -0
- /data/spec/rails3/{app_root/public → public}/javascripts/effects.js +0 -0
- /data/spec/rails3/{app_root/public → public}/javascripts/prototype.js +0 -0
- /data/spec/rails3/{app_root/public → public}/javascripts/rails.js +0 -0
- /data/spec/rails3/{app_root/public → public}/robots.txt +0 -0
- /data/spec/rails3/{app_root/public → public}/stylesheets/.gitkeep +0 -0
- /data/spec/rails3/{app_root/script → script}/rails +0 -0
- /data/spec/rails3/{app_root/spec → spec}/controller_activity_logging_spec.rb +0 -0
- /data/spec/rails3/{app_root/spec → spec}/controller_http_basic_auth_spec.rb +0 -0
- /data/spec/rails3/{app_root/spec → spec}/controller_remember_me_spec.rb +0 -0
- /data/spec/rails3/{app_root/spec → spec}/controller_spec.rb +0 -0
- /data/spec/rails3/{app_root/spec → spec}/spec_helper.orig.rb +0 -0
- /data/spec/rails3/{app_root/spec → spec}/user_activity_logging_spec.rb +0 -0
- /data/spec/rails3/{app_root/spec → spec}/user_brute_force_protection_spec.rb +0 -0
- /data/spec/rails3/{app_root/spec → spec}/user_remember_me_spec.rb +0 -0
- /data/spec/rails3/{app_root/vendor → vendor}/plugins/.gitkeep +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
module Sorcery
|
|
2
2
|
module Model
|
|
3
3
|
module Submodules
|
|
4
|
-
# This submodule helps you login users from
|
|
4
|
+
# This submodule helps you login users from external providers such as Twitter.
|
|
5
5
|
# This is the model part which handles finding the user using access tokens.
|
|
6
|
-
# For the controller options see Sorcery::Controller::
|
|
6
|
+
# For the controller options see Sorcery::Controller::External.
|
|
7
7
|
#
|
|
8
8
|
# Socery assumes (read: requires) you will create external users in the same table where you keep your regular users,
|
|
9
9
|
# but that you will have a separate table for keeping their external authentication data,
|
|
@@ -11,7 +11,7 @@ module Sorcery
|
|
|
11
11
|
#
|
|
12
12
|
# External users will have a null crypted_password field, since we do not hold their password.
|
|
13
13
|
# They will not be sent activation emails on creation.
|
|
14
|
-
module
|
|
14
|
+
module External
|
|
15
15
|
def self.included(base)
|
|
16
16
|
base.sorcery_config.class_eval do
|
|
17
17
|
attr_accessor :authentications_class,
|
data/lib/sorcery/model.rb
CHANGED
|
@@ -9,11 +9,13 @@ module Sorcery
|
|
|
9
9
|
def self.included(klass)
|
|
10
10
|
klass.class_eval do
|
|
11
11
|
class << self
|
|
12
|
-
def
|
|
12
|
+
def authenticates_with_sorcery!
|
|
13
13
|
@sorcery_config = Config.new
|
|
14
14
|
self.class_eval do
|
|
15
15
|
extend ClassMethods # included here, before submodules, so they can be overriden by them.
|
|
16
16
|
include InstanceMethods
|
|
17
|
+
|
|
18
|
+
# set the user_class for the controller methods which call it
|
|
17
19
|
::Sorcery::Controller::Config.user_class = self
|
|
18
20
|
@sorcery_config.submodules = ::Sorcery::Controller::Config.submodules
|
|
19
21
|
@sorcery_config.submodules.each do |mod|
|
|
@@ -25,7 +27,7 @@ module Sorcery
|
|
|
25
27
|
end
|
|
26
28
|
end
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
::Sorcery::Controller::Config.user_config.tap{|blk| blk.call(@sorcery_config) if blk}
|
|
29
31
|
|
|
30
32
|
self.class_eval do
|
|
31
33
|
attr_accessor @sorcery_config.password_attribute_name
|
|
@@ -56,12 +58,6 @@ module Sorcery
|
|
|
56
58
|
user if user && @sorcery_config.before_authenticate.all? {|c| user.send(c)} && credentials_match?(user.send(@sorcery_config.crypted_password_attribute_name),credentials[1],_salt)
|
|
57
59
|
end
|
|
58
60
|
|
|
59
|
-
# Calls the configured encryption provider to compare the supplied password with the encrypted one.
|
|
60
|
-
def credentials_match?(crypted, *tokens)
|
|
61
|
-
return crypted == tokens.join if @sorcery_config.encryption_provider.nil?
|
|
62
|
-
@sorcery_config.encryption_provider.matches?(crypted, *tokens)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
61
|
# encrypt tokens using current encryption_provider.
|
|
66
62
|
def encrypt(*tokens)
|
|
67
63
|
return tokens.first if @sorcery_config.encryption_provider.nil?
|
|
@@ -71,6 +67,15 @@ module Sorcery
|
|
|
71
67
|
CryptoProviders::AES256.key = @sorcery_config.encryption_key if @sorcery_config.encryption_algorithm == :aes256
|
|
72
68
|
@sorcery_config.encryption_provider.encrypt(*tokens)
|
|
73
69
|
end
|
|
70
|
+
|
|
71
|
+
protected
|
|
72
|
+
|
|
73
|
+
# Calls the configured encryption provider to compare the supplied password with the encrypted one.
|
|
74
|
+
def credentials_match?(crypted, *tokens)
|
|
75
|
+
return crypted == tokens.join if @sorcery_config.encryption_provider.nil?
|
|
76
|
+
@sorcery_config.encryption_provider.matches?(crypted, *tokens)
|
|
77
|
+
end
|
|
78
|
+
|
|
74
79
|
end
|
|
75
80
|
|
|
76
81
|
module InstanceMethods
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'fileutils'
|
|
2
|
+
|
|
3
|
+
namespace :sorcery do
|
|
4
|
+
desc "Adds sorcery's initializer file"
|
|
5
|
+
task :bootstrap do
|
|
6
|
+
src = File.join(File.dirname(__FILE__), '..', 'initializers', 'initializer.rb')
|
|
7
|
+
target = File.join(Rails.root, "config", "initializers", "sorcery.rb")
|
|
8
|
+
FileUtils.cp(src, target)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
module Sorcery
|
|
2
|
+
module TestHelpers
|
|
3
|
+
module Rails
|
|
4
|
+
SUBMODUELS_AUTO_ADDED_CONTROLLER_FILTERS = [:register_last_activity_time_to_db, :deny_banned_user, :validate_session]
|
|
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
|
+
|
|
39
|
+
def login_user(user = nil)
|
|
40
|
+
user ||= @user
|
|
41
|
+
subject.send(:login_user,user)
|
|
42
|
+
subject.send(:after_login!,user,[user.username,'secret'])
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def logout_user
|
|
46
|
+
subject.send(:logout)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def clear_user_without_logout
|
|
50
|
+
subject.instance_variable_set(:@current_user,nil)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
module Sorcery
|
|
2
|
+
module TestHelpers
|
|
3
|
+
module Sinatra
|
|
4
|
+
|
|
5
|
+
class MyApp
|
|
6
|
+
class << self
|
|
7
|
+
def new
|
|
8
|
+
return this
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class ::Sinatra::Application
|
|
14
|
+
class << self
|
|
15
|
+
attr_accessor :sorcery_vars
|
|
16
|
+
end
|
|
17
|
+
@sorcery_vars = {}
|
|
18
|
+
|
|
19
|
+
# NOTE: see before and after test filters in filters.rb
|
|
20
|
+
|
|
21
|
+
def save_instance_vars
|
|
22
|
+
instance_variables.each do |var|
|
|
23
|
+
self.class.sorcery_vars[:"#{var.to_s.delete("@")}"] = instance_variable_get(var)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
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
|
+
|
|
51
|
+
def clear_user_without_logout
|
|
52
|
+
get_sinatra_app(subject).instance_variable_set(:@current_user,nil)
|
|
53
|
+
end
|
|
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 = {}
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def [](key)
|
|
72
|
+
@data[key]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def []=(key, value)
|
|
76
|
+
@data[key] = value
|
|
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
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def session
|
|
85
|
+
SessionData.new(rack_test_session.instance_variable_get(:@rack_mock_session).cookie_jar)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def cookies
|
|
89
|
+
rack_test_session.instance_variable_get(:@rack_mock_session).cookie_jar
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def sorcery_reload!(submodules = [], options = {})
|
|
93
|
+
reload_user_class
|
|
94
|
+
|
|
95
|
+
# return to no-module configuration
|
|
96
|
+
::Sorcery::Controller::Config.init!
|
|
97
|
+
::Sorcery::Controller::Config.reset!
|
|
98
|
+
|
|
99
|
+
# clear all filters
|
|
100
|
+
::Sinatra::Application.instance_variable_set(:@filters,{:before => [],:after => []})
|
|
101
|
+
::Sinatra::Application.class_eval do
|
|
102
|
+
load File.join(File.dirname(__FILE__),'..','..','..','spec','sinatra','filters.rb')
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# configure
|
|
106
|
+
::Sorcery::Controller::Config.submodules = submodules
|
|
107
|
+
::Sorcery::Controller::Config.user_class = nil
|
|
108
|
+
::Sinatra::Application.send(:include, Sorcery::Controller::Adapters::Sinatra)
|
|
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)
|
|
114
|
+
end
|
|
115
|
+
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
|
+
|
|
123
|
+
def sorcery_controller_external_property_set(provider, property, value)
|
|
124
|
+
::Sorcery::Controller::Config.send(provider).send(:"#{property}=", value)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
data/lib/sorcery/test_helpers.rb
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
module Sorcery
|
|
2
|
+
# This file will be included in the spec_helper file.
|
|
2
3
|
module TestHelpers
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
|
|
5
23
|
def create_new_user(attributes_hash = nil)
|
|
6
24
|
user_attributes_hash = attributes_hash || {:username => 'gizmo', :email => "bla@bla.com", :password => 'secret'}
|
|
7
25
|
@user = User.new(user_attributes_hash)
|
|
@@ -16,62 +34,12 @@ module Sorcery
|
|
|
16
34
|
@user
|
|
17
35
|
end
|
|
18
36
|
|
|
19
|
-
def login_user(user = nil)
|
|
20
|
-
user ||= @user
|
|
21
|
-
subject.send(:login_user,user)
|
|
22
|
-
subject.send(:after_login!,user,[user.username,'secret'])
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def logout_user
|
|
26
|
-
subject.send(:logout)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def clear_user_without_logout
|
|
30
|
-
subject.instance_variable_set(:@current_user,nil)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def sorcery_reload!(submodules = [], options = {})
|
|
34
|
-
reload_user_class
|
|
35
|
-
|
|
36
|
-
# return to no-module configuration
|
|
37
|
-
::Sorcery::Controller::Config.init!
|
|
38
|
-
::Sorcery::Controller::Config.reset!
|
|
39
|
-
|
|
40
|
-
# remove all plugin before_filters so they won't fail other tests.
|
|
41
|
-
# I don't like this way, but I didn't find another.
|
|
42
|
-
# hopefully it won't break until Rails 4.
|
|
43
|
-
ApplicationController._process_action_callbacks.delete_if {|c| SUBMODUELS_AUTO_ADDED_CONTROLLER_FILTERS.include?(c.filter) }
|
|
44
|
-
|
|
45
|
-
# configure
|
|
46
|
-
::Sorcery::Controller::Config.submodules = submodules
|
|
47
|
-
::Sorcery::Controller::Config.user_class = nil
|
|
48
|
-
ActionController::Base.send(:include,::Sorcery::Controller)
|
|
49
|
-
|
|
50
|
-
User.activate_sorcery! do |config|
|
|
51
|
-
options.each do |property,value|
|
|
52
|
-
config.send(:"#{property}=", value)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
37
|
def sorcery_model_property_set(property, *values)
|
|
58
38
|
User.class_eval do
|
|
59
39
|
sorcery_config.send(:"#{property}=", *values)
|
|
60
40
|
end
|
|
61
41
|
end
|
|
62
|
-
|
|
63
|
-
def sorcery_controller_property_set(property, value)
|
|
64
|
-
ApplicationController.activate_sorcery! do |config|
|
|
65
|
-
config.send(:"#{property}=", value)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
42
|
|
|
69
|
-
def sorcery_controller_oauth_property_set(provider, property, value)
|
|
70
|
-
ApplicationController.activate_sorcery! do |config|
|
|
71
|
-
config.send(provider).send(:"#{property}=", value)
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
43
|
private
|
|
76
44
|
|
|
77
45
|
# reload user class between specs
|
data/lib/sorcery.rb
CHANGED
|
@@ -8,7 +8,7 @@ module Sorcery
|
|
|
8
8
|
autoload :RememberMe, 'sorcery/model/submodules/remember_me'
|
|
9
9
|
autoload :ActivityLogging, 'sorcery/model/submodules/activity_logging'
|
|
10
10
|
autoload :BruteForceProtection, 'sorcery/model/submodules/brute_force_protection'
|
|
11
|
-
autoload :
|
|
11
|
+
autoload :External, 'sorcery/model/submodules/external'
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
autoload :Controller, 'sorcery/controller'
|
|
@@ -19,18 +19,24 @@ module Sorcery
|
|
|
19
19
|
autoload :BruteForceProtection, 'sorcery/controller/submodules/brute_force_protection'
|
|
20
20
|
autoload :HttpBasicAuth, 'sorcery/controller/submodules/http_basic_auth'
|
|
21
21
|
autoload :ActivityLogging, 'sorcery/controller/submodules/activity_logging'
|
|
22
|
-
autoload :
|
|
23
|
-
module
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
autoload :External, 'sorcery/controller/submodules/external'
|
|
23
|
+
module External
|
|
24
|
+
module Protocols
|
|
25
|
+
autoload :Oauth1, 'sorcery/controller/submodules/external/protocols/oauth1'
|
|
26
|
+
autoload :Oauth2, 'sorcery/controller/submodules/external/protocols/oauth2'
|
|
27
|
+
end
|
|
26
28
|
module Providers
|
|
27
|
-
autoload :Twitter, 'sorcery/controller/submodules/
|
|
28
|
-
autoload :Facebook, 'sorcery/controller/submodules/
|
|
29
|
+
autoload :Twitter, 'sorcery/controller/submodules/external/providers/twitter'
|
|
30
|
+
autoload :Facebook, 'sorcery/controller/submodules/external/providers/facebook'
|
|
29
31
|
end
|
|
30
32
|
end
|
|
31
33
|
end
|
|
34
|
+
module Adapters
|
|
35
|
+
autoload :Sinatra, 'sorcery/controller/adapters/sinatra'
|
|
36
|
+
end
|
|
32
37
|
end
|
|
33
38
|
module CryptoProviders
|
|
39
|
+
autoload :Common, 'sorcery/crypto_providers/common'
|
|
34
40
|
autoload :AES256, 'sorcery/crypto_providers/aes256'
|
|
35
41
|
autoload :BCrypt, 'sorcery/crypto_providers/bcrypt'
|
|
36
42
|
autoload :MD5, 'sorcery/crypto_providers/md5'
|
|
@@ -39,6 +45,11 @@ module Sorcery
|
|
|
39
45
|
autoload :SHA512, 'sorcery/crypto_providers/sha512'
|
|
40
46
|
end
|
|
41
47
|
autoload :TestHelpers, 'sorcery/test_helpers'
|
|
48
|
+
module TestHelpers
|
|
49
|
+
autoload :Rails, 'sorcery/test_helpers/rails'
|
|
50
|
+
autoload :Sinatra, 'sorcery/test_helpers/sinatra'
|
|
51
|
+
end
|
|
42
52
|
|
|
43
53
|
require 'sorcery/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
|
54
|
+
require 'sorcery/sinatra' if defined?(Sinatra)
|
|
44
55
|
end
|