sorcery 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sorcery might be problematic. Click here for more details.

Files changed (164) hide show
  1. data/Gemfile +2 -1
  2. data/Gemfile.lock +58 -51
  3. data/README.rdoc +19 -57
  4. data/Rakefile +27 -1
  5. data/VERSION +1 -1
  6. data/lib/generators/sorcery/USAGE +22 -0
  7. data/lib/generators/sorcery/install_generator.rb +71 -0
  8. data/lib/{sorcery/initializers → generators/sorcery/templates}/initializer.rb +4 -4
  9. data/lib/generators/sorcery/templates/migration/activity_logging.rb +17 -0
  10. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +11 -0
  11. data/lib/generators/{sorcery_migration/templates → sorcery/templates/migration}/core.rb +2 -2
  12. data/lib/generators/{sorcery_migration/templates → sorcery/templates/migration}/external.rb +1 -1
  13. data/lib/generators/sorcery/templates/migration/remember_me.rb +15 -0
  14. data/lib/generators/sorcery/templates/migration/reset_password.rb +17 -0
  15. data/lib/generators/sorcery/templates/migration/user_activation.rb +17 -0
  16. data/lib/sorcery.rb +5 -7
  17. data/lib/sorcery/controller.rb +40 -39
  18. data/lib/sorcery/controller/submodules/activity_logging.rb +7 -10
  19. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +23 -8
  20. data/lib/sorcery/controller/submodules/remember_me.rb +3 -2
  21. data/lib/sorcery/model.rb +21 -4
  22. data/lib/sorcery/model/adapters/mongo_mapper.rb +49 -0
  23. data/lib/sorcery/model/adapters/mongoid.rb +1 -1
  24. data/lib/sorcery/model/submodules/brute_force_protection.rb +8 -0
  25. data/lib/sorcery/model/submodules/remember_me.rb +8 -1
  26. data/lib/sorcery/model/submodules/reset_password.rb +10 -0
  27. data/lib/sorcery/model/submodules/user_activation.rb +12 -0
  28. data/sorcery.gemspec +86 -210
  29. data/spec/Gemfile +1 -1
  30. data/spec/Gemfile.lock +28 -15
  31. data/spec/README.md +6 -1
  32. data/spec/rails3/Gemfile +2 -2
  33. data/spec/rails3/Gemfile.lock +45 -50
  34. data/spec/rails3/spec/controller_oauth2_spec.rb +5 -3
  35. data/spec/rails3/spec/spec_helper.rb +1 -3
  36. data/spec/rails3_mongo_mapper/.gitignore +4 -0
  37. data/spec/rails3_mongo_mapper/.rspec +1 -0
  38. data/spec/{sinatra_modular → rails3_mongo_mapper}/Gemfile +5 -5
  39. data/spec/rails3_mongo_mapper/Gemfile.lock +159 -0
  40. data/spec/{sinatra → rails3_mongo_mapper}/Rakefile +3 -3
  41. data/spec/rails3_mongo_mapper/app/controllers/application_controller.rb +108 -0
  42. data/spec/rails3_mongo_mapper/app/helpers/application_helper.rb +2 -0
  43. data/spec/{sinatra → rails3_mongo_mapper/app/mailers}/sorcery_mailer.rb +0 -0
  44. data/spec/rails3_mongo_mapper/app/models/authentication.rb +6 -0
  45. data/spec/rails3_mongo_mapper/app/models/user.rb +5 -0
  46. data/spec/rails3_mongo_mapper/app/views/layouts/application.html.erb +14 -0
  47. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.html.erb +17 -0
  48. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.text.erb +9 -0
  49. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.html.erb +17 -0
  50. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.text.erb +9 -0
  51. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.html.erb +16 -0
  52. data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.text.erb +8 -0
  53. data/spec/rails3_mongo_mapper/config.ru +4 -0
  54. data/spec/rails3_mongo_mapper/config/application.rb +51 -0
  55. data/spec/rails3_mongo_mapper/config/boot.rb +13 -0
  56. data/spec/rails3_mongo_mapper/config/environment.rb +5 -0
  57. data/spec/rails3_mongo_mapper/config/environments/development.rb +30 -0
  58. data/spec/rails3_mongo_mapper/config/environments/in_memory.rb +0 -0
  59. data/spec/rails3_mongo_mapper/config/environments/production.rb +49 -0
  60. data/spec/rails3_mongo_mapper/config/environments/test.rb +35 -0
  61. data/spec/rails3_mongo_mapper/config/initializers/backtrace_silencers.rb +7 -0
  62. data/spec/rails3_mongo_mapper/config/initializers/inflections.rb +10 -0
  63. data/spec/rails3_mongo_mapper/config/initializers/mime_types.rb +5 -0
  64. data/spec/rails3_mongo_mapper/config/initializers/mongo.rb +2 -0
  65. data/spec/rails3_mongo_mapper/config/initializers/secret_token.rb +7 -0
  66. data/spec/rails3_mongo_mapper/config/initializers/session_store.rb +8 -0
  67. data/spec/rails3_mongo_mapper/config/locales/en.yml +5 -0
  68. data/spec/rails3_mongo_mapper/config/routes.rb +59 -0
  69. data/spec/rails3_mongo_mapper/db/schema.rb +23 -0
  70. data/spec/rails3_mongo_mapper/db/seeds.rb +7 -0
  71. data/spec/rails3_mongo_mapper/lib/tasks/.gitkeep +0 -0
  72. data/spec/rails3_mongo_mapper/public/404.html +26 -0
  73. data/spec/rails3_mongo_mapper/public/422.html +26 -0
  74. data/spec/rails3_mongo_mapper/public/500.html +26 -0
  75. data/spec/rails3_mongo_mapper/public/favicon.ico +0 -0
  76. data/spec/rails3_mongo_mapper/public/images/rails.png +0 -0
  77. data/spec/rails3_mongo_mapper/public/javascripts/application.js +2 -0
  78. data/spec/rails3_mongo_mapper/public/javascripts/controls.js +965 -0
  79. data/spec/rails3_mongo_mapper/public/javascripts/dragdrop.js +974 -0
  80. data/spec/rails3_mongo_mapper/public/javascripts/effects.js +1123 -0
  81. data/spec/rails3_mongo_mapper/public/javascripts/prototype.js +6001 -0
  82. data/spec/rails3_mongo_mapper/public/javascripts/rails.js +175 -0
  83. data/spec/rails3_mongo_mapper/public/robots.txt +5 -0
  84. data/spec/rails3_mongo_mapper/public/stylesheets/.gitkeep +0 -0
  85. data/spec/rails3_mongo_mapper/script/rails +6 -0
  86. data/spec/{sinatra → rails3_mongo_mapper}/spec/controller_spec.rb +45 -42
  87. data/spec/{sinatra → rails3_mongo_mapper}/spec/spec.opts +0 -0
  88. data/spec/rails3_mongo_mapper/spec/spec_helper.orig.rb +27 -0
  89. data/spec/rails3_mongo_mapper/spec/spec_helper.rb +55 -0
  90. data/spec/rails3_mongo_mapper/spec/user_activation_spec.rb +9 -0
  91. data/spec/rails3_mongo_mapper/spec/user_activity_logging_spec.rb +8 -0
  92. data/spec/rails3_mongo_mapper/spec/user_brute_force_protection_spec.rb +8 -0
  93. data/spec/rails3_mongo_mapper/spec/user_oauth_spec.rb +8 -0
  94. data/spec/rails3_mongo_mapper/spec/user_remember_me_spec.rb +8 -0
  95. data/spec/rails3_mongo_mapper/spec/user_reset_password_spec.rb +8 -0
  96. data/spec/rails3_mongo_mapper/spec/user_spec.rb +37 -0
  97. data/spec/rails3_mongo_mapper/vendor/plugins/.gitkeep +0 -0
  98. data/spec/rails3_mongoid/Gemfile +1 -1
  99. data/spec/rails3_mongoid/Gemfile.lock +44 -35
  100. data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +98 -0
  101. data/spec/rails3_mongoid/spec/user_spec.rb +1 -0
  102. data/spec/shared_examples/user_shared_examples.rb +29 -1
  103. metadata +124 -237
  104. data/lib/generators/sorcery_migration/sorcery_migration_generator.rb +0 -24
  105. data/lib/generators/sorcery_migration/templates/activity_logging.rb +0 -17
  106. data/lib/generators/sorcery_migration/templates/brute_force_protection.rb +0 -11
  107. data/lib/generators/sorcery_migration/templates/remember_me.rb +0 -15
  108. data/lib/generators/sorcery_migration/templates/reset_password.rb +0 -17
  109. data/lib/generators/sorcery_migration/templates/user_activation.rb +0 -17
  110. data/lib/sorcery/controller/adapters/sinatra.rb +0 -115
  111. data/lib/sorcery/sinatra.rb +0 -4
  112. data/lib/sorcery/test_helpers/internal/sinatra.rb +0 -74
  113. data/lib/sorcery/test_helpers/internal/sinatra_modular.rb +0 -74
  114. data/lib/sorcery/test_helpers/sinatra.rb +0 -88
  115. data/spec/rails3/Rakefile.unused +0 -7
  116. data/spec/sinatra/Gemfile +0 -15
  117. data/spec/sinatra/Gemfile.lock +0 -115
  118. data/spec/sinatra/authentication.rb +0 -3
  119. data/spec/sinatra/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
  120. data/spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -17
  121. data/spec/sinatra/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -11
  122. data/spec/sinatra/db/migrate/core/20101224223620_create_users.rb +0 -16
  123. data/spec/sinatra/db/migrate/external/20101224223628_create_authentications.rb +0 -14
  124. data/spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
  125. data/spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -13
  126. data/spec/sinatra/filters.rb +0 -27
  127. data/spec/sinatra/modular.rb +0 -157
  128. data/spec/sinatra/myapp.rb +0 -133
  129. data/spec/sinatra/spec/controller_activity_logging_spec.rb +0 -85
  130. data/spec/sinatra/spec/controller_brute_force_protection_spec.rb +0 -70
  131. data/spec/sinatra/spec/controller_http_basic_auth_spec.rb +0 -53
  132. data/spec/sinatra/spec/controller_oauth2_spec.rb +0 -96
  133. data/spec/sinatra/spec/controller_oauth_spec.rb +0 -100
  134. data/spec/sinatra/spec/controller_remember_me_spec.rb +0 -64
  135. data/spec/sinatra/spec/controller_session_timeout_spec.rb +0 -57
  136. data/spec/sinatra/spec/spec_helper.rb +0 -45
  137. data/spec/sinatra/user.rb +0 -6
  138. data/spec/sinatra/views/test_login.erb +0 -4
  139. data/spec/sinatra_modular/Gemfile.lock +0 -115
  140. data/spec/sinatra_modular/Rakefile +0 -11
  141. data/spec/sinatra_modular/authentication.rb +0 -3
  142. data/spec/sinatra_modular/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
  143. data/spec/sinatra_modular/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -17
  144. data/spec/sinatra_modular/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -11
  145. data/spec/sinatra_modular/db/migrate/core/20101224223620_create_users.rb +0 -16
  146. data/spec/sinatra_modular/db/migrate/external/20101224223628_create_authentications.rb +0 -14
  147. data/spec/sinatra_modular/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
  148. data/spec/sinatra_modular/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -13
  149. data/spec/sinatra_modular/filters.rb +0 -27
  150. data/spec/sinatra_modular/modular.rb +0 -157
  151. data/spec/sinatra_modular/myapp.rb +0 -133
  152. data/spec/sinatra_modular/sorcery_mailer.rb +0 -25
  153. data/spec/sinatra_modular/spec_modular/controller_activity_logging_spec.rb +0 -85
  154. data/spec/sinatra_modular/spec_modular/controller_brute_force_protection_spec.rb +0 -70
  155. data/spec/sinatra_modular/spec_modular/controller_http_basic_auth_spec.rb +0 -53
  156. data/spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb +0 -96
  157. data/spec/sinatra_modular/spec_modular/controller_oauth_spec.rb +0 -100
  158. data/spec/sinatra_modular/spec_modular/controller_remember_me_spec.rb +0 -64
  159. data/spec/sinatra_modular/spec_modular/controller_session_timeout_spec.rb +0 -57
  160. data/spec/sinatra_modular/spec_modular/controller_spec.rb +0 -116
  161. data/spec/sinatra_modular/spec_modular/spec.opts +0 -2
  162. data/spec/sinatra_modular/spec_modular/spec_helper.rb +0 -51
  163. data/spec/sinatra_modular/user.rb +0 -6
  164. data/spec/sinatra_modular/views/test_login.erb +0 -4
@@ -1,24 +0,0 @@
1
- require 'rails/generators'
2
- require 'rails/generators/migration'
3
-
4
- class SorceryMigrationGenerator < Rails::Generators::Base
5
- include Rails::Generators::Migration
6
-
7
- source_root File.join(File.dirname(__FILE__), 'templates')
8
- argument :submodules, :type => :array, :required => true
9
-
10
- def self.next_migration_number(dirname)
11
- if ActiveRecord::Base.timestamped_migrations
12
- Time.new.utc.strftime("%Y%m%d%H%M%S")
13
- else
14
- "%.3d" % (current_migration_number(dirname) + 1)
15
- end
16
- end
17
-
18
- def create_migration_file
19
- self.submodules.each do |submodule|
20
- migration_template "#{submodule}.rb", "db/migrate/sorcery_#{submodule}.rb"
21
- sleep 1 # for the timestamp to change
22
- end
23
- end
24
- end
@@ -1,17 +0,0 @@
1
- class SorceryActivityLogging < ActiveRecord::Migration
2
- def self.up
3
- add_column :users, :last_login_at, :datetime, :default => nil
4
- add_column :users, :last_logout_at, :datetime, :default => nil
5
- add_column :users, :last_activity_at, :datetime, :default => nil
6
-
7
- add_index :users, [:last_logout_at, :last_activity_at]
8
- end
9
-
10
- def self.down
11
- remove_index :users, [:last_logout_at, :last_activity_at]
12
-
13
- remove_column :users, :last_activity_at
14
- remove_column :users, :last_logout_at
15
- remove_column :users, :last_login_at
16
- end
17
- end
@@ -1,11 +0,0 @@
1
- class SorceryBruteForceProtection < ActiveRecord::Migration
2
- def self.up
3
- add_column :users, :failed_logins_count, :integer, :default => 0
4
- add_column :users, :lock_expires_at, :datetime, :default => nil
5
- end
6
-
7
- def self.down
8
- remove_column :users, :lock_expires_at
9
- remove_column :users, :failed_logins_count
10
- end
11
- end
@@ -1,15 +0,0 @@
1
- class SorceryRememberMe < ActiveRecord::Migration
2
- def self.up
3
- add_column :users, :remember_me_token, :string, :default => nil
4
- add_column :users, :remember_me_token_expires_at, :datetime, :default => nil
5
-
6
- add_index :users, :remember_me_token
7
- end
8
-
9
- def self.down
10
- remove_index :users, :remember_me_token
11
-
12
- remove_column :users, :remember_me_token_expires_at
13
- remove_column :users, :remember_me_token
14
- end
15
- end
@@ -1,17 +0,0 @@
1
- class SorceryResetPassword < ActiveRecord::Migration
2
- def self.up
3
- add_column :users, :reset_password_token, :string, :default => nil
4
- add_column :users, :reset_password_token_expires_at, :datetime, :default => nil
5
- add_column :users, :reset_password_email_sent_at, :datetime, :default => nil
6
-
7
- add_index :users, :reset_password_token
8
- end
9
-
10
- def self.down
11
- remove_index :users, :reset_password_token
12
-
13
- remove_column :users, :reset_password_email_sent_at
14
- remove_column :users, :reset_password_token_expires_at
15
- remove_column :users, :reset_password_token
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- class SorceryUserActivation < ActiveRecord::Migration
2
- def self.up
3
- add_column :users, :activation_state, :string, :default => nil
4
- add_column :users, :activation_token, :string, :default => nil
5
- add_column :users, :activation_token_expires_at, :datetime, :default => nil
6
-
7
- add_index :users, :activation_token
8
- end
9
-
10
- def self.down
11
- remove_index :users, :activation_token
12
-
13
- remove_column :users, :activation_token_expires_at
14
- remove_column :users, :activation_token
15
- remove_column :users, :activation_state
16
- end
17
- end
@@ -1,115 +0,0 @@
1
- module Sorcery
2
- module Controller
3
- module Adapters
4
- # This module does the magic of translating Rails commands to Sinatra.
5
- # This way the Rails code doesn't change, but it actually now calls Sinatra calls.
6
- module Sinatra
7
- def self.included(base)
8
- base.class_eval do
9
- class << self
10
- # prepend a filter
11
- def prepend_filter(type, path = nil, options = {}, &block)
12
- return filters[type].unshift block unless path
13
- path, options = //, path if path.respond_to?(:each_pair)
14
- block, *arguments = compile!(type, path, block, options)
15
- prepend_filter(type) do
16
- process_route(*arguments) { instance_eval(&block) }
17
- end
18
- end
19
-
20
- def after_filter(filter)
21
- after do
22
- send(filter)
23
- end
24
- end
25
- end
26
- end
27
-
28
- ::Sinatra::Request.class_eval do
29
- def authorization
30
- env['HTTP_AUTHORIZATION'] ||
31
- env['X-HTTP_AUTHORIZATION'] ||
32
- env['X_HTTP_AUTHORIZATION'] ||
33
- env['REDIRECT_X_HTTP_AUTHORIZATION'] || nil
34
- end
35
- end
36
-
37
- base.send(:include, SorceryHelpers)
38
- base.send(:include, InstanceMethods)
39
- base.extend(ClassMethods)
40
- end
41
-
42
- module SorceryHelpers
43
-
44
- def request_http_basic_authentication(realm)
45
- response.header['WWW-Authenticate'] = %(Basic realm="#{realm}")
46
- response.status = 401
47
- end
48
-
49
- def authenticate_with_http_basic(&blk)
50
- @auth ||= Rack::Auth::Basic::Request.new(request.env)
51
- yield @auth.credentials if (@auth.provided? && @auth.basic? && @auth.credentials)
52
- end
53
-
54
- end
55
-
56
- module InstanceMethods
57
- def reset_session
58
- session.clear
59
- end
60
-
61
- def redirect_to(*args)
62
- args.pop if args.last.is_a?(Hash)
63
- redirect(*args)
64
- end
65
-
66
- def root_path
67
- '/'
68
- end
69
-
70
- ::Sinatra.helpers do
71
- include SorceryHelpers
72
- end
73
-
74
- def cookies
75
- @cookie_proxy ||= CookieProxy.new(request, response)
76
- end
77
- end
78
-
79
- class CookieProxy
80
- def initialize(request, response)
81
- @request = request
82
- @response = response
83
- @secure = false
84
- end
85
-
86
- def [](key)
87
- value = @request.cookies[key.to_s]
88
- end
89
-
90
- def []=(key, value)
91
- if @secure
92
- value.merge(:secret => Config.sinatra_cookie_secret)
93
- @secure = false
94
- end
95
- @response.set_cookie(key, value)
96
- end
97
-
98
- # mark cookie as signed, which will light a flag, which will cause the next set_cookie to be encrypted.
99
- def signed
100
- @secure = true
101
- self
102
- end
103
- end
104
-
105
- module ClassMethods
106
- def prepend_before_filter(filter)
107
- prepend_filter(:before) do
108
- send(filter)
109
- end
110
- end
111
- end
112
- end
113
- end
114
- end
115
- end
@@ -1,4 +0,0 @@
1
- if defined?(Sinatra::Base)
2
- Sinatra::Base.send(:include, Sorcery::Controller::Adapters::Sinatra)
3
- Sinatra::Base.send(:include, Sorcery::Controller)
4
- end
@@ -1,74 +0,0 @@
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
- load File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec', 'sinatra', 'filters.rb')
47
- ::Sinatra::Application.send(:include, ::Filters)
48
-
49
- # configure
50
- ::Sorcery::Controller::Config.submodules = submodules
51
- ::Sorcery::Controller::Config.user_class = nil
52
- ::Sinatra::Application.send(:include, Sorcery::Controller::Adapters::Sinatra)
53
- ::Sinatra::Application.send(:include, Sorcery::Controller)
54
- ::Sorcery::Controller::Config.user_class = "User"
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
@@ -1,74 +0,0 @@
1
- module Sorcery
2
- module TestHelpers
3
- module Internal
4
- module SinatraModular
5
- include ::Sorcery::TestHelpers::Sinatra::CookieSessionMethods
6
- include ::Sorcery::TestHelpers::Sinatra::InstanceMethods
7
-
8
- class ::Modular
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
- ::Modular.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::Base.instance_variable_set(:@filters, {:before => [], :after => []})
46
- require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec', 'sinatra', 'filters')
47
- ::Sinatra::Base.send(:include, ::Filters)
48
-
49
- # configure
50
- ::Sorcery::Controller::Config.submodules = submodules
51
- ::Sorcery::Controller::Config.user_class = nil
52
- ::Sinatra::Base.send(:include, Sorcery::Controller::Adapters::Sinatra)
53
- ::Sinatra::Base.send(:include, Sorcery::Controller)
54
- ::Sorcery::Controller::Config.user_class = "User"
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
@@ -1,88 +0,0 @@
1
- module Sorcery
2
- module TestHelpers
3
- module Sinatra
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
10
- end
11
-
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
25
- end
26
- end
27
- end
28
-
29
- module InstanceMethods
30
- def get_sinatra_app(app)
31
- while !app.kind_of? ::Sinatra::Base do
32
- app = app.instance_variable_get(:@app)
33
- end
34
- app
35
- end
36
-
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_names.first), 'secret'])
41
- end
42
-
43
- def logout_user
44
- get_sinatra_app(app).send(:logout)
45
- end
46
- end
47
-
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
60
-
61
- def [](key)
62
- @data[key]
63
- end
64
-
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 = {}
75
- end
76
- end
77
-
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
85
- end
86
- end
87
- end
88
- end