sorcery 0.5.1 → 0.6.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/README.rdoc +9 -1
- data/VERSION +1 -1
- data/lib/sorcery/controller/adapters/sinatra.rb +35 -28
- data/lib/sorcery/controller/submodules/activity_logging.rb +11 -7
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +8 -5
- data/lib/sorcery/controller/submodules/external.rb +11 -6
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +12 -7
- data/lib/sorcery/controller/submodules/remember_me.rb +14 -5
- data/lib/sorcery/controller/submodules/session_timeout.rb +3 -1
- data/lib/sorcery/controller.rb +12 -9
- data/lib/sorcery/crypto_providers/aes256.rb +8 -5
- data/lib/sorcery/crypto_providers/bcrypt.rb +12 -6
- data/lib/sorcery/crypto_providers/sha256.rb +2 -1
- data/lib/sorcery/crypto_providers/sha512.rb +2 -1
- data/lib/sorcery/engine.rb +0 -7
- data/lib/sorcery/initializers/initializer.rb +127 -36
- data/lib/sorcery/model/adapters/active_record.rb +2 -2
- data/lib/sorcery/model/adapters/mongoid.rb +4 -4
- data/lib/sorcery/model/submodules/activity_logging.rb +7 -6
- data/lib/sorcery/model/submodules/brute_force_protection.rb +10 -6
- data/lib/sorcery/model/submodules/external.rb +4 -2
- data/lib/sorcery/model/submodules/remember_me.rb +4 -3
- data/lib/sorcery/model/submodules/reset_password.rb +16 -8
- data/lib/sorcery/model/submodules/user_activation.rb +23 -10
- data/lib/sorcery/model/temporary_token.rb +3 -2
- data/lib/sorcery/model.rb +59 -28
- data/lib/sorcery/test_helpers/internal/rails.rb +6 -1
- data/lib/sorcery/test_helpers/internal/sinatra.rb +3 -3
- data/lib/sorcery/test_helpers/internal/sinatra_modular.rb +74 -0
- data/lib/sorcery/test_helpers/internal.rb +2 -1
- data/lib/sorcery.rb +3 -5
- data/sorcery.gemspec +72 -2
- data/spec/Gemfile.lock +1 -1
- data/spec/rails3/Gemfile.lock +1 -1
- data/spec/rails3/spec/controller_oauth2_spec.rb +3 -24
- data/spec/rails3/spec/controller_oauth_spec.rb +3 -24
- data/spec/rails3/spec/controller_spec.rb +2 -2
- data/spec/rails3/spec/user_activation_spec.rb +2 -168
- data/spec/rails3/spec/user_activity_logging_spec.rb +2 -30
- data/spec/rails3/spec/user_brute_force_protection_spec.rb +2 -35
- data/spec/rails3/spec/user_oauth_spec.rb +2 -26
- data/spec/rails3/spec/user_remember_me_spec.rb +2 -45
- data/spec/rails3/spec/user_reset_password_spec.rb +3 -168
- data/spec/rails3/spec/user_spec.rb +3 -293
- data/spec/rails3_mongoid/Gemfile.lock +1 -1
- data/spec/rails3_mongoid/app/models/authentication.rb +3 -3
- data/spec/rails3_mongoid/spec/user_activation_spec.rb +2 -171
- data/spec/rails3_mongoid/spec/user_activity_logging_spec.rb +2 -25
- data/spec/rails3_mongoid/spec/user_brute_force_protection_spec.rb +2 -35
- data/spec/rails3_mongoid/spec/user_oauth_spec.rb +2 -28
- data/spec/rails3_mongoid/spec/user_remember_me_spec.rb +2 -45
- data/spec/rails3_mongoid/spec/user_reset_password_spec.rb +2 -176
- data/spec/rails3_mongoid/spec/user_spec.rb +3 -295
- data/spec/shared_examples/controller_oauth2_shared_examples.rb +37 -0
- data/spec/shared_examples/controller_oauth_shared_examples.rb +37 -0
- data/spec/shared_examples/user_activation_shared_examples.rb +173 -0
- data/spec/shared_examples/user_activity_logging_shared_examples.rb +27 -0
- data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +37 -0
- data/spec/shared_examples/user_oauth_shared_examples.rb +31 -0
- data/spec/shared_examples/user_remember_me_shared_examples.rb +47 -0
- data/spec/shared_examples/user_reset_password_shared_examples.rb +177 -0
- data/spec/shared_examples/user_shared_examples.rb +292 -0
- data/spec/sinatra/Gemfile.lock +1 -1
- data/spec/sinatra/Rakefile +1 -1
- data/spec/sinatra/filters.rb +20 -14
- data/spec/sinatra/modular.rb +157 -0
- data/spec/sinatra/spec/controller_oauth2_spec.rb +3 -24
- data/spec/sinatra/spec/controller_oauth_spec.rb +3 -24
- data/spec/sinatra/spec/controller_spec.rb +2 -2
- data/spec/sinatra_modular/Gemfile +15 -0
- data/spec/sinatra_modular/Gemfile.lock +117 -0
- data/spec/sinatra_modular/Rakefile +11 -0
- data/spec/sinatra_modular/authentication.rb +3 -0
- data/spec/sinatra_modular/db/migrate/activation/20101224223622_add_activation_to_users.rb +17 -0
- data/spec/sinatra_modular/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +17 -0
- data/spec/sinatra_modular/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +11 -0
- data/spec/sinatra_modular/db/migrate/core/20101224223620_create_users.rb +16 -0
- data/spec/sinatra_modular/db/migrate/external/20101224223628_create_authentications.rb +14 -0
- data/spec/sinatra_modular/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +15 -0
- data/spec/sinatra_modular/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +13 -0
- data/spec/sinatra_modular/filters.rb +27 -0
- data/spec/sinatra_modular/modular.rb +157 -0
- data/spec/sinatra_modular/myapp.rb +133 -0
- data/spec/sinatra_modular/sorcery_mailer.rb +25 -0
- data/spec/sinatra_modular/spec_modular/controller_activity_logging_spec.rb +85 -0
- data/spec/sinatra_modular/spec_modular/controller_brute_force_protection_spec.rb +70 -0
- data/spec/sinatra_modular/spec_modular/controller_http_basic_auth_spec.rb +53 -0
- data/spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb +99 -0
- data/spec/sinatra_modular/spec_modular/controller_oauth_spec.rb +100 -0
- data/spec/sinatra_modular/spec_modular/controller_remember_me_spec.rb +64 -0
- data/spec/sinatra_modular/spec_modular/controller_session_timeout_spec.rb +57 -0
- data/spec/sinatra_modular/spec_modular/controller_spec.rb +116 -0
- data/spec/sinatra_modular/spec_modular/spec.opts +2 -0
- data/spec/sinatra_modular/spec_modular/spec_helper.rb +51 -0
- data/spec/sinatra_modular/user.rb +6 -0
- data/spec/sinatra_modular/views/test_login.erb +4 -0
- metadata +72 -2
|
@@ -4,7 +4,11 @@ module Sorcery
|
|
|
4
4
|
module Rails
|
|
5
5
|
include ::Sorcery::TestHelpers::Rails
|
|
6
6
|
|
|
7
|
-
SUBMODUELS_AUTO_ADDED_CONTROLLER_FILTERS = [
|
|
7
|
+
SUBMODUELS_AUTO_ADDED_CONTROLLER_FILTERS = [
|
|
8
|
+
:register_last_activity_time_to_db,
|
|
9
|
+
:deny_banned_user,
|
|
10
|
+
:validate_session
|
|
11
|
+
]
|
|
8
12
|
|
|
9
13
|
def sorcery_reload!(submodules = [], options = {})
|
|
10
14
|
reload_user_class
|
|
@@ -22,6 +26,7 @@ module Sorcery
|
|
|
22
26
|
::Sorcery::Controller::Config.submodules = submodules
|
|
23
27
|
::Sorcery::Controller::Config.user_class = nil
|
|
24
28
|
ActionController::Base.send(:include,::Sorcery::Controller)
|
|
29
|
+
::Sorcery::Controller::Config.user_class = "User"
|
|
25
30
|
|
|
26
31
|
::Sorcery::Controller::Config.user_config do |user|
|
|
27
32
|
options.each do |property,value|
|
|
@@ -43,15 +43,15 @@ module Sorcery
|
|
|
43
43
|
|
|
44
44
|
# clear all filters
|
|
45
45
|
::Sinatra::Application.instance_variable_set(:@filters, {:before => [], :after => []})
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
end
|
|
46
|
+
load File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec', 'sinatra', 'filters.rb')
|
|
47
|
+
::Sinatra::Application.send(:include, ::Filters)
|
|
49
48
|
|
|
50
49
|
# configure
|
|
51
50
|
::Sorcery::Controller::Config.submodules = submodules
|
|
52
51
|
::Sorcery::Controller::Config.user_class = nil
|
|
53
52
|
::Sinatra::Application.send(:include, Sorcery::Controller::Adapters::Sinatra)
|
|
54
53
|
::Sinatra::Application.send(:include, Sorcery::Controller)
|
|
54
|
+
::Sorcery::Controller::Config.user_class = "User"
|
|
55
55
|
|
|
56
56
|
::Sorcery::Controller::Config.user_config do |user|
|
|
57
57
|
options.each do |property, value|
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
|
@@ -15,7 +15,8 @@ module Sorcery
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
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
|
|
18
|
+
# After the first destroy, the session is an ordinary hash, and then when destroy
|
|
19
|
+
# is called again there's an exception.
|
|
19
20
|
class ::Hash
|
|
20
21
|
def destroy
|
|
21
22
|
clear
|
data/lib/sorcery.rb
CHANGED
|
@@ -56,28 +56,26 @@ module Sorcery
|
|
|
56
56
|
module Internal
|
|
57
57
|
autoload :Rails, 'sorcery/test_helpers/internal/rails'
|
|
58
58
|
autoload :Sinatra, 'sorcery/test_helpers/internal/sinatra'
|
|
59
|
+
autoload :SinatraModular, 'sorcery/test_helpers/internal/sinatra_modular'
|
|
59
60
|
end
|
|
60
61
|
|
|
61
62
|
end
|
|
62
63
|
|
|
63
64
|
if defined?(ActiveRecord)
|
|
64
65
|
ActiveRecord::Base.send(:include, Sorcery::Model)
|
|
65
|
-
ActiveRecord::Base.send(:include,
|
|
66
|
+
ActiveRecord::Base.send(:include, Sorcery::Model::Adapters::ActiveRecord)
|
|
66
67
|
end
|
|
67
68
|
|
|
68
69
|
if defined?(Mongoid)
|
|
69
70
|
Mongoid::Document.module_eval do
|
|
70
71
|
included do
|
|
71
72
|
attr_reader :new_record
|
|
72
|
-
include Sorcery::Model::Adapters::Mongoid
|
|
73
73
|
include Sorcery::Model
|
|
74
|
+
include Sorcery::Model::Adapters::Mongoid
|
|
74
75
|
end
|
|
75
76
|
end
|
|
76
77
|
end
|
|
77
78
|
|
|
78
79
|
require 'sorcery/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
|
79
80
|
require 'sorcery/sinatra' if defined?(Sinatra)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
81
|
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.6.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-07-30}
|
|
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 = [
|
|
@@ -71,6 +71,7 @@ Gem::Specification.new do |s|
|
|
|
71
71
|
"lib/sorcery/test_helpers/internal.rb",
|
|
72
72
|
"lib/sorcery/test_helpers/internal/rails.rb",
|
|
73
73
|
"lib/sorcery/test_helpers/internal/sinatra.rb",
|
|
74
|
+
"lib/sorcery/test_helpers/internal/sinatra_modular.rb",
|
|
74
75
|
"lib/sorcery/test_helpers/rails.rb",
|
|
75
76
|
"lib/sorcery/test_helpers/sinatra.rb",
|
|
76
77
|
"sorcery.gemspec",
|
|
@@ -217,6 +218,15 @@ Gem::Specification.new do |s|
|
|
|
217
218
|
"spec/rails3_mongoid/spec/user_reset_password_spec.rb",
|
|
218
219
|
"spec/rails3_mongoid/spec/user_spec.rb",
|
|
219
220
|
"spec/rails3_mongoid/vendor/plugins/.gitkeep",
|
|
221
|
+
"spec/shared_examples/controller_oauth2_shared_examples.rb",
|
|
222
|
+
"spec/shared_examples/controller_oauth_shared_examples.rb",
|
|
223
|
+
"spec/shared_examples/user_activation_shared_examples.rb",
|
|
224
|
+
"spec/shared_examples/user_activity_logging_shared_examples.rb",
|
|
225
|
+
"spec/shared_examples/user_brute_force_protection_shared_examples.rb",
|
|
226
|
+
"spec/shared_examples/user_oauth_shared_examples.rb",
|
|
227
|
+
"spec/shared_examples/user_remember_me_shared_examples.rb",
|
|
228
|
+
"spec/shared_examples/user_reset_password_shared_examples.rb",
|
|
229
|
+
"spec/shared_examples/user_shared_examples.rb",
|
|
220
230
|
"spec/sinatra/Gemfile",
|
|
221
231
|
"spec/sinatra/Gemfile.lock",
|
|
222
232
|
"spec/sinatra/Rakefile",
|
|
@@ -229,6 +239,7 @@ Gem::Specification.new do |s|
|
|
|
229
239
|
"spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb",
|
|
230
240
|
"spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb",
|
|
231
241
|
"spec/sinatra/filters.rb",
|
|
242
|
+
"spec/sinatra/modular.rb",
|
|
232
243
|
"spec/sinatra/myapp.rb",
|
|
233
244
|
"spec/sinatra/sorcery_mailer.rb",
|
|
234
245
|
"spec/sinatra/spec/controller_activity_logging_spec.rb",
|
|
@@ -243,6 +254,33 @@ Gem::Specification.new do |s|
|
|
|
243
254
|
"spec/sinatra/spec/spec_helper.rb",
|
|
244
255
|
"spec/sinatra/user.rb",
|
|
245
256
|
"spec/sinatra/views/test_login.erb",
|
|
257
|
+
"spec/sinatra_modular/Gemfile",
|
|
258
|
+
"spec/sinatra_modular/Gemfile.lock",
|
|
259
|
+
"spec/sinatra_modular/Rakefile",
|
|
260
|
+
"spec/sinatra_modular/authentication.rb",
|
|
261
|
+
"spec/sinatra_modular/db/migrate/activation/20101224223622_add_activation_to_users.rb",
|
|
262
|
+
"spec/sinatra_modular/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb",
|
|
263
|
+
"spec/sinatra_modular/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb",
|
|
264
|
+
"spec/sinatra_modular/db/migrate/core/20101224223620_create_users.rb",
|
|
265
|
+
"spec/sinatra_modular/db/migrate/external/20101224223628_create_authentications.rb",
|
|
266
|
+
"spec/sinatra_modular/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb",
|
|
267
|
+
"spec/sinatra_modular/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb",
|
|
268
|
+
"spec/sinatra_modular/filters.rb",
|
|
269
|
+
"spec/sinatra_modular/modular.rb",
|
|
270
|
+
"spec/sinatra_modular/myapp.rb",
|
|
271
|
+
"spec/sinatra_modular/sorcery_mailer.rb",
|
|
272
|
+
"spec/sinatra_modular/spec_modular/controller_activity_logging_spec.rb",
|
|
273
|
+
"spec/sinatra_modular/spec_modular/controller_brute_force_protection_spec.rb",
|
|
274
|
+
"spec/sinatra_modular/spec_modular/controller_http_basic_auth_spec.rb",
|
|
275
|
+
"spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb",
|
|
276
|
+
"spec/sinatra_modular/spec_modular/controller_oauth_spec.rb",
|
|
277
|
+
"spec/sinatra_modular/spec_modular/controller_remember_me_spec.rb",
|
|
278
|
+
"spec/sinatra_modular/spec_modular/controller_session_timeout_spec.rb",
|
|
279
|
+
"spec/sinatra_modular/spec_modular/controller_spec.rb",
|
|
280
|
+
"spec/sinatra_modular/spec_modular/spec.opts",
|
|
281
|
+
"spec/sinatra_modular/spec_modular/spec_helper.rb",
|
|
282
|
+
"spec/sinatra_modular/user.rb",
|
|
283
|
+
"spec/sinatra_modular/views/test_login.erb",
|
|
246
284
|
"spec/sorcery_crypto_providers_spec.rb",
|
|
247
285
|
"spec/spec.opts",
|
|
248
286
|
"spec/spec_helper.rb"
|
|
@@ -326,6 +364,15 @@ Gem::Specification.new do |s|
|
|
|
326
364
|
"spec/rails3_mongoid/spec/user_remember_me_spec.rb",
|
|
327
365
|
"spec/rails3_mongoid/spec/user_reset_password_spec.rb",
|
|
328
366
|
"spec/rails3_mongoid/spec/user_spec.rb",
|
|
367
|
+
"spec/shared_examples/controller_oauth2_shared_examples.rb",
|
|
368
|
+
"spec/shared_examples/controller_oauth_shared_examples.rb",
|
|
369
|
+
"spec/shared_examples/user_activation_shared_examples.rb",
|
|
370
|
+
"spec/shared_examples/user_activity_logging_shared_examples.rb",
|
|
371
|
+
"spec/shared_examples/user_brute_force_protection_shared_examples.rb",
|
|
372
|
+
"spec/shared_examples/user_oauth_shared_examples.rb",
|
|
373
|
+
"spec/shared_examples/user_remember_me_shared_examples.rb",
|
|
374
|
+
"spec/shared_examples/user_reset_password_shared_examples.rb",
|
|
375
|
+
"spec/shared_examples/user_shared_examples.rb",
|
|
329
376
|
"spec/sinatra/authentication.rb",
|
|
330
377
|
"spec/sinatra/db/migrate/activation/20101224223622_add_activation_to_users.rb",
|
|
331
378
|
"spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb",
|
|
@@ -335,6 +382,7 @@ Gem::Specification.new do |s|
|
|
|
335
382
|
"spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb",
|
|
336
383
|
"spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb",
|
|
337
384
|
"spec/sinatra/filters.rb",
|
|
385
|
+
"spec/sinatra/modular.rb",
|
|
338
386
|
"spec/sinatra/myapp.rb",
|
|
339
387
|
"spec/sinatra/sorcery_mailer.rb",
|
|
340
388
|
"spec/sinatra/spec/controller_activity_logging_spec.rb",
|
|
@@ -347,6 +395,28 @@ Gem::Specification.new do |s|
|
|
|
347
395
|
"spec/sinatra/spec/controller_spec.rb",
|
|
348
396
|
"spec/sinatra/spec/spec_helper.rb",
|
|
349
397
|
"spec/sinatra/user.rb",
|
|
398
|
+
"spec/sinatra_modular/authentication.rb",
|
|
399
|
+
"spec/sinatra_modular/db/migrate/activation/20101224223622_add_activation_to_users.rb",
|
|
400
|
+
"spec/sinatra_modular/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb",
|
|
401
|
+
"spec/sinatra_modular/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb",
|
|
402
|
+
"spec/sinatra_modular/db/migrate/core/20101224223620_create_users.rb",
|
|
403
|
+
"spec/sinatra_modular/db/migrate/external/20101224223628_create_authentications.rb",
|
|
404
|
+
"spec/sinatra_modular/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb",
|
|
405
|
+
"spec/sinatra_modular/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb",
|
|
406
|
+
"spec/sinatra_modular/filters.rb",
|
|
407
|
+
"spec/sinatra_modular/modular.rb",
|
|
408
|
+
"spec/sinatra_modular/myapp.rb",
|
|
409
|
+
"spec/sinatra_modular/sorcery_mailer.rb",
|
|
410
|
+
"spec/sinatra_modular/spec_modular/controller_activity_logging_spec.rb",
|
|
411
|
+
"spec/sinatra_modular/spec_modular/controller_brute_force_protection_spec.rb",
|
|
412
|
+
"spec/sinatra_modular/spec_modular/controller_http_basic_auth_spec.rb",
|
|
413
|
+
"spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb",
|
|
414
|
+
"spec/sinatra_modular/spec_modular/controller_oauth_spec.rb",
|
|
415
|
+
"spec/sinatra_modular/spec_modular/controller_remember_me_spec.rb",
|
|
416
|
+
"spec/sinatra_modular/spec_modular/controller_session_timeout_spec.rb",
|
|
417
|
+
"spec/sinatra_modular/spec_modular/controller_spec.rb",
|
|
418
|
+
"spec/sinatra_modular/spec_modular/spec_helper.rb",
|
|
419
|
+
"spec/sinatra_modular/user.rb",
|
|
350
420
|
"spec/sorcery_crypto_providers_spec.rb",
|
|
351
421
|
"spec/spec_helper.rb"
|
|
352
422
|
]
|
data/spec/Gemfile.lock
CHANGED
data/spec/rails3/Gemfile.lock
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/controller_oauth2_shared_examples')
|
|
2
3
|
|
|
3
4
|
def stub_all_oauth2_requests!
|
|
4
5
|
@client = OAuth2::Client.new("key","secret", :site => "http://myapi.com")
|
|
@@ -58,30 +59,8 @@ describe ApplicationController do
|
|
|
58
59
|
end
|
|
59
60
|
end
|
|
60
61
|
|
|
61
|
-
describe ApplicationController
|
|
62
|
-
|
|
63
|
-
stub_all_oauth2_requests!
|
|
64
|
-
User.delete_all
|
|
65
|
-
Authentication.delete_all
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it "should create a new user" do
|
|
69
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
70
|
-
sorcery_controller_external_property_set(:facebook, :user_info_mapping, {:username => "name"})
|
|
71
|
-
lambda do
|
|
72
|
-
get :test_create_from_provider, :provider => "facebook"
|
|
73
|
-
end.should change(User, :count).by(1)
|
|
74
|
-
User.first.username.should == "Noam Ben Ari"
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it "should support nested attributes" do
|
|
78
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
79
|
-
sorcery_controller_external_property_set(:facebook, :user_info_mapping, {:username => "hometown/name"})
|
|
80
|
-
lambda do
|
|
81
|
-
get :test_create_from_provider, :provider => "facebook"
|
|
82
|
-
end.should change(User, :count).by(1)
|
|
83
|
-
User.first.username.should == "Haifa, Israel"
|
|
84
|
-
end
|
|
62
|
+
describe ApplicationController do
|
|
63
|
+
it_behaves_like "oauth2_controller"
|
|
85
64
|
end
|
|
86
65
|
|
|
87
66
|
describe ApplicationController, "OAuth with User Activation features" do
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/controller_oauth_shared_examples')
|
|
2
3
|
require 'ostruct'
|
|
3
4
|
|
|
4
5
|
def stub_all_oauth_requests!
|
|
@@ -64,30 +65,8 @@ describe ApplicationController do
|
|
|
64
65
|
end
|
|
65
66
|
end
|
|
66
67
|
|
|
67
|
-
describe ApplicationController
|
|
68
|
-
|
|
69
|
-
stub_all_oauth_requests!
|
|
70
|
-
User.delete_all
|
|
71
|
-
Authentication.delete_all
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "should create a new user" do
|
|
75
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
76
|
-
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "screen_name"})
|
|
77
|
-
lambda do
|
|
78
|
-
get :test_create_from_provider, :provider => "twitter"
|
|
79
|
-
end.should change(User, :count).by(1)
|
|
80
|
-
User.first.username.should == "nbenari"
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it "should support nested attributes" do
|
|
84
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
85
|
-
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "status/text"})
|
|
86
|
-
lambda do
|
|
87
|
-
get :test_create_from_provider, :provider => "twitter"
|
|
88
|
-
end.should change(User, :count).by(1)
|
|
89
|
-
User.first.username.should == "coming soon to sorcery gem: twitter and facebook authentication support."
|
|
90
|
-
end
|
|
68
|
+
describe ApplicationController do
|
|
69
|
+
it_behaves_like "oauth_controller"
|
|
91
70
|
end
|
|
92
71
|
|
|
93
72
|
describe ApplicationController, "using OAuth with User Activation features" do
|
|
@@ -14,8 +14,8 @@ describe ApplicationController do
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it "should enable configuration option 'user_class'" do
|
|
17
|
-
sorcery_controller_property_set(:user_class, TestUser)
|
|
18
|
-
Sorcery::Controller::Config.user_class.should
|
|
17
|
+
sorcery_controller_property_set(:user_class, "TestUser")
|
|
18
|
+
Sorcery::Controller::Config.user_class.should == "TestUser"
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "should enable configuration option 'not_authenticated_action'" do
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../app/mailers/sorcery_mailer')
|
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/user_activation_shared_examples')
|
|
3
4
|
|
|
4
5
|
describe "User with activation submodule" do
|
|
5
6
|
before(:all) do
|
|
@@ -10,173 +11,6 @@ describe "User with activation submodule" do
|
|
|
10
11
|
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activation")
|
|
11
12
|
end
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
describe User, "loaded plugin configuration" do
|
|
15
|
-
before(:all) do
|
|
16
|
-
sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
after(:each) do
|
|
20
|
-
User.sorcery_config.reset!
|
|
21
|
-
sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "should enable configuration option 'activation_state_attribute_name'" do
|
|
25
|
-
sorcery_model_property_set(:activation_state_attribute_name, :status)
|
|
26
|
-
User.sorcery_config.activation_state_attribute_name.should equal(:status)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
it "should enable configuration option 'activation_token_attribute_name'" do
|
|
30
|
-
sorcery_model_property_set(:activation_token_attribute_name, :code)
|
|
31
|
-
User.sorcery_config.activation_token_attribute_name.should equal(:code)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "should enable configuration option 'user_activation_mailer'" do
|
|
35
|
-
sorcery_model_property_set(:user_activation_mailer, TestMailer)
|
|
36
|
-
User.sorcery_config.user_activation_mailer.should equal(TestMailer)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it "should enable configuration option 'activation_needed_email_method_name'" do
|
|
40
|
-
sorcery_model_property_set(:activation_needed_email_method_name, :my_activation_email)
|
|
41
|
-
User.sorcery_config.activation_needed_email_method_name.should equal(:my_activation_email)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "should enable configuration option 'activation_success_email_method_name'" do
|
|
45
|
-
sorcery_model_property_set(:activation_success_email_method_name, :my_activation_email)
|
|
46
|
-
User.sorcery_config.activation_success_email_method_name.should equal(:my_activation_email)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "if mailer is nil on activation, throw exception!" do
|
|
50
|
-
expect{sorcery_reload!([:user_activation])}.to raise_error(ArgumentError)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# ----------------- ACTIVATION PROCESS -----------------------
|
|
55
|
-
describe User, "activation process" do
|
|
56
|
-
before(:all) do
|
|
57
|
-
sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
before(:each) do
|
|
61
|
-
create_new_user
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it "should initialize user state to 'pending'" do
|
|
65
|
-
@user.activation_state.should == "pending"
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
specify { @user.should respond_to(:activate!) }
|
|
69
|
-
|
|
70
|
-
it "should clear activation code and change state to 'active' on activation" do
|
|
71
|
-
activation_token = @user.activation_token
|
|
72
|
-
@user.activate!
|
|
73
|
-
@user2 = User.find(@user.id) # go to db to make sure it was saved and not just in memory
|
|
74
|
-
@user2.activation_token.should be_nil
|
|
75
|
-
@user2.activation_state.should == "active"
|
|
76
|
-
User.find_by_activation_token(activation_token).should be_nil
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it "should send the user an activation email" do
|
|
80
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
81
|
-
create_new_user
|
|
82
|
-
ActionMailer::Base.deliveries.size.should == old_size + 1
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "subsequent saves do not send activation email" do
|
|
86
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
87
|
-
@user.username = "Shauli"
|
|
88
|
-
@user.save!
|
|
89
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
it "should send the user an activation success email on successful activation" do
|
|
93
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
94
|
-
@user.activate!
|
|
95
|
-
ActionMailer::Base.deliveries.size.should == old_size + 1
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it "subsequent saves do not send activation success email" do
|
|
99
|
-
@user.activate!
|
|
100
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
101
|
-
@user.username = "Shauli"
|
|
102
|
-
@user.save!
|
|
103
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it "activation needed email is optional" do
|
|
107
|
-
sorcery_model_property_set(:activation_needed_email_method_name, nil)
|
|
108
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
109
|
-
create_new_user
|
|
110
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
it "activation success email is optional" do
|
|
114
|
-
sorcery_model_property_set(:activation_success_email_method_name, nil)
|
|
115
|
-
old_size = ActionMailer::Base.deliveries.size
|
|
116
|
-
@user.activate!
|
|
117
|
-
ActionMailer::Base.deliveries.size.should == old_size
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
describe User, "prevent non-active login feature" do
|
|
122
|
-
before(:all) do
|
|
123
|
-
sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
it "should not allow a non-active user to authenticate" do
|
|
127
|
-
create_new_user
|
|
128
|
-
User.authenticate(@user.username,'secret').should be_false
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it "should allow a non-active user to authenticate if configured so" do
|
|
132
|
-
create_new_user
|
|
133
|
-
sorcery_model_property_set(:prevent_non_active_users_to_login, false)
|
|
134
|
-
User.authenticate(@user.username,'secret').should be_true
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
describe User, "load_from_activation_token" do
|
|
139
|
-
before(:all) do
|
|
140
|
-
sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
after(:each) do
|
|
144
|
-
Timecop.return
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
it "load_from_activation_token should return user when token is found" do
|
|
148
|
-
create_new_user
|
|
149
|
-
User.load_from_activation_token(@user.activation_token).should == @user
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
it "load_from_activation_token should NOT return user when token is NOT found" do
|
|
153
|
-
create_new_user
|
|
154
|
-
User.load_from_activation_token("a").should == nil
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
it "load_from_activation_token should return user when token is found and not expired" do
|
|
158
|
-
sorcery_model_property_set(:activation_token_expiration_period, 500)
|
|
159
|
-
create_new_user
|
|
160
|
-
User.load_from_activation_token(@user.activation_token).should == @user
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
it "load_from_activation_token should NOT return user when token is found and expired" do
|
|
164
|
-
sorcery_model_property_set(:activation_token_expiration_period, 0.1)
|
|
165
|
-
create_new_user
|
|
166
|
-
Timecop.travel(Time.now+0.5)
|
|
167
|
-
User.load_from_activation_token(@user.activation_token).should == nil
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
it "load_from_activation_token should return nil if token is blank" do
|
|
171
|
-
User.load_from_activation_token(nil).should == nil
|
|
172
|
-
User.load_from_activation_token("").should == nil
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
it "load_from_activation_token should always be valid if expiration period is nil" do
|
|
176
|
-
sorcery_model_property_set(:activation_token_expiration_period, nil)
|
|
177
|
-
create_new_user
|
|
178
|
-
User.load_from_activation_token(@user.activation_token).should == @user
|
|
179
|
-
end
|
|
180
|
-
end
|
|
14
|
+
it_behaves_like "rails_3_activation_model"
|
|
181
15
|
|
|
182
16
|
end
|
|
@@ -1,36 +1,8 @@
|
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/user_activity_logging_shared_examples')
|
|
2
3
|
|
|
3
4
|
describe "User with activity logging submodule" do
|
|
4
|
-
before(:all) do
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
after(:all) do
|
|
8
|
-
end
|
|
9
5
|
|
|
10
|
-
|
|
11
|
-
describe User, "loaded plugin configuration" do
|
|
12
|
-
before(:all) do
|
|
13
|
-
sorcery_reload!([:activity_logging])
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
after(:each) do
|
|
17
|
-
User.sorcery_config.reset!
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "should allow configuration option 'last_login_at_attribute_name'" do
|
|
21
|
-
sorcery_model_property_set(:last_login_at_attribute_name, :login_time)
|
|
22
|
-
User.sorcery_config.last_login_at_attribute_name.should equal(:login_time)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
it "should allow configuration option 'last_logout_at_attribute_name'" do
|
|
26
|
-
sorcery_model_property_set(:last_logout_at_attribute_name, :logout_time)
|
|
27
|
-
User.sorcery_config.last_logout_at_attribute_name.should equal(:logout_time)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it "should allow configuration option 'last_activity_at_attribute_name'" do
|
|
31
|
-
sorcery_model_property_set(:last_activity_at_attribute_name, :activity_time)
|
|
32
|
-
User.sorcery_config.last_activity_at_attribute_name.should equal(:activity_time)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
6
|
+
it_behaves_like "rails_3_activity_logging_model"
|
|
35
7
|
|
|
36
8
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/user_brute_force_protection_shared_examples')
|
|
2
3
|
|
|
3
4
|
describe "User with brute_force_protection submodule" do
|
|
4
5
|
before(:all) do
|
|
@@ -9,40 +10,6 @@ describe "User with brute_force_protection submodule" do
|
|
|
9
10
|
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/brute_force_protection")
|
|
10
11
|
end
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
describe User, "loaded plugin configuration" do
|
|
14
|
-
|
|
15
|
-
before(:all) do
|
|
16
|
-
sorcery_reload!([:brute_force_protection])
|
|
17
|
-
create_new_user
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
after(:each) do
|
|
21
|
-
User.sorcery_config.reset!
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
specify { @user.should respond_to(:failed_logins_count) }
|
|
25
|
-
specify { @user.should respond_to(:lock_expires_at) }
|
|
26
|
-
|
|
27
|
-
it "should enable configuration option 'failed_logins_count_attribute_name'" do
|
|
28
|
-
sorcery_model_property_set(:failed_logins_count_attribute_name, :my_count)
|
|
29
|
-
User.sorcery_config.failed_logins_count_attribute_name.should equal(:my_count)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "should enable configuration option 'lock_expires_at_attribute_name'" do
|
|
33
|
-
sorcery_model_property_set(:lock_expires_at_attribute_name, :expires)
|
|
34
|
-
User.sorcery_config.lock_expires_at_attribute_name.should equal(:expires)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "should enable configuration option 'consecutive_login_retries_amount_allowed'" do
|
|
38
|
-
sorcery_model_property_set(:consecutive_login_retries_amount_limit, 34)
|
|
39
|
-
User.sorcery_config.consecutive_login_retries_amount_limit.should equal(34)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "should enable configuration option 'login_lock_time_period'" do
|
|
43
|
-
sorcery_model_property_set(:login_lock_time_period, 2.hours)
|
|
44
|
-
User.sorcery_config.login_lock_time_period.should == 2.hours
|
|
45
|
-
end
|
|
46
|
-
end
|
|
13
|
+
it_behaves_like "rails_3_brute_force_protection_model"
|
|
47
14
|
|
|
48
15
|
end
|