sorcery 0.4.0 → 0.4.2
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 +1 -1
- data/VERSION +1 -1
- data/lib/sorcery/crypto_providers/bcrypt.rb +2 -4
- data/lib/sorcery/initializers/initializer.rb +58 -58
- data/lib/sorcery/model/submodules/activity_logging.rb +1 -1
- data/lib/sorcery/model/submodules/brute_force_protection.rb +1 -1
- data/lib/sorcery/model/submodules/reset_password.rb +1 -1
- data/lib/sorcery/model.rb +21 -1
- data/lib/sorcery/test_helpers/internal/rails.rb +52 -0
- data/lib/sorcery/test_helpers/internal/sinatra.rb +122 -0
- data/lib/sorcery/test_helpers/internal.rb +55 -0
- data/lib/sorcery/test_helpers/rails.rb +5 -43
- data/lib/sorcery/test_helpers/sinatra.rb +59 -102
- data/lib/sorcery/test_helpers.rb +0 -47
- data/lib/sorcery.rb +7 -0
- data/sorcery.gemspec +5 -2
- data/spec/Gemfile +1 -1
- data/spec/Gemfile.lock +12 -4
- data/spec/rails3/Gemfile +1 -1
- data/spec/rails3/Gemfile.lock +2 -2
- 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 +13 -14
- data/spec/rails3/spec/user_spec.rb +18 -2
- data/spec/sinatra/Gemfile +1 -1
- data/spec/sinatra/Gemfile.lock +2 -2
- data/spec/sinatra/spec/controller_session_timeout_spec.rb +23 -22
- data/spec/sinatra/spec/spec_helper.rb +2 -1
- metadata +5 -2
|
@@ -1,127 +1,84 @@
|
|
|
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(rack_test_session.instance_variable_get(:@rack_mock_session).cookie_jar)
|
|
80
|
+
end
|
|
81
|
+
|
|
125
82
|
end
|
|
126
83
|
end
|
|
127
84
|
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
|
@@ -48,7 +48,14 @@ module Sorcery
|
|
|
48
48
|
module TestHelpers
|
|
49
49
|
autoload :Rails, 'sorcery/test_helpers/rails'
|
|
50
50
|
autoload :Sinatra, 'sorcery/test_helpers/sinatra'
|
|
51
|
+
autoload :Internal, 'sorcery/test_helpers/internal'
|
|
52
|
+
module Internal
|
|
53
|
+
autoload :Rails, 'sorcery/test_helpers/internal/rails'
|
|
54
|
+
autoload :Sinatra, 'sorcery/test_helpers/internal/sinatra'
|
|
55
|
+
end
|
|
56
|
+
|
|
51
57
|
end
|
|
58
|
+
|
|
52
59
|
|
|
53
60
|
require 'sorcery/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
|
54
61
|
require 'sorcery/sinatra' if defined?(Sinatra)
|
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.4.
|
|
8
|
+
s.version = "0.4.2"
|
|
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-04-
|
|
12
|
+
s.date = %q{2011-04-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 = [
|
|
@@ -66,6 +66,9 @@ Gem::Specification.new do |s|
|
|
|
66
66
|
"lib/sorcery/railties/tasks.rake",
|
|
67
67
|
"lib/sorcery/sinatra.rb",
|
|
68
68
|
"lib/sorcery/test_helpers.rb",
|
|
69
|
+
"lib/sorcery/test_helpers/internal.rb",
|
|
70
|
+
"lib/sorcery/test_helpers/internal/rails.rb",
|
|
71
|
+
"lib/sorcery/test_helpers/internal/sinatra.rb",
|
|
69
72
|
"lib/sorcery/test_helpers/rails.rb",
|
|
70
73
|
"lib/sorcery/test_helpers/sinatra.rb",
|
|
71
74
|
"sorcery.gemspec",
|
data/spec/Gemfile
CHANGED
data/spec/Gemfile.lock
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
PATH
|
|
2
|
-
remote:
|
|
2
|
+
remote: ../
|
|
3
3
|
specs:
|
|
4
|
-
sorcery (0.4.
|
|
4
|
+
sorcery (0.4.2)
|
|
5
|
+
bcrypt-ruby (~> 2.1.4)
|
|
6
|
+
json (>= 1.5.1)
|
|
7
|
+
oauth (>= 0.4.4)
|
|
8
|
+
oauth (>= 0.4.4)
|
|
9
|
+
oauth2 (>= 0.1.1)
|
|
10
|
+
oauth2 (>= 0.1.1)
|
|
11
|
+
rails (>= 3.0.0)
|
|
5
12
|
|
|
6
13
|
GEM
|
|
7
14
|
remote: http://rubygems.org/
|
|
@@ -36,7 +43,7 @@ GEM
|
|
|
36
43
|
addressable (2.2.4)
|
|
37
44
|
archive-tar-minitar (0.5.2)
|
|
38
45
|
arel (2.0.6)
|
|
39
|
-
bcrypt-ruby (2.1.
|
|
46
|
+
bcrypt-ruby (2.1.4)
|
|
40
47
|
builder (2.1.2)
|
|
41
48
|
columnize (0.3.2)
|
|
42
49
|
diff-lcs (1.1.2)
|
|
@@ -47,6 +54,7 @@ GEM
|
|
|
47
54
|
multipart-post (~> 1.1.0)
|
|
48
55
|
rack (< 2, >= 1.1.0)
|
|
49
56
|
i18n (0.5.0)
|
|
57
|
+
json (1.5.1)
|
|
50
58
|
linecache19 (0.5.11)
|
|
51
59
|
ruby_core_source (>= 0.1.4)
|
|
52
60
|
mail (2.2.13)
|
|
@@ -118,4 +126,4 @@ DEPENDENCIES
|
|
|
118
126
|
rspec (~> 2.5.0)
|
|
119
127
|
ruby-debug19
|
|
120
128
|
simplecov (>= 0.3.8)
|
|
121
|
-
sorcery (
|
|
129
|
+
sorcery (>= 0.1.0)!
|
data/spec/rails3/Gemfile
CHANGED
data/spec/rails3/Gemfile.lock
CHANGED
|
@@ -2,7 +2,7 @@ PATH
|
|
|
2
2
|
remote: ../../../
|
|
3
3
|
specs:
|
|
4
4
|
oauth (0.4.4)
|
|
5
|
-
sorcery (0.4.
|
|
5
|
+
sorcery (0.4.2)
|
|
6
6
|
bcrypt-ruby (~> 2.1.4)
|
|
7
7
|
json (>= 1.5.1)
|
|
8
8
|
oauth (>= 0.4.4)
|
|
@@ -131,6 +131,6 @@ DEPENDENCIES
|
|
|
131
131
|
rspec-rails (~> 2.5.0)
|
|
132
132
|
ruby-debug19
|
|
133
133
|
simplecov (>= 0.3.8)
|
|
134
|
-
sorcery (
|
|
134
|
+
sorcery (>= 0.1.0)!
|
|
135
135
|
sqlite3-ruby
|
|
136
136
|
timecop
|
|
@@ -22,10 +22,8 @@ describe ApplicationController do
|
|
|
22
22
|
after(:each) do
|
|
23
23
|
User.delete_all
|
|
24
24
|
end
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
subject.should respond_to(:current_users)
|
|
28
|
-
end
|
|
25
|
+
|
|
26
|
+
specify { subject.should respond_to(:current_users) }
|
|
29
27
|
|
|
30
28
|
it "'current_users' should be empty when no users are logged in" do
|
|
31
29
|
subject.current_users.size.should == 0
|
|
@@ -31,7 +31,7 @@ describe ApplicationController do
|
|
|
31
31
|
ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
|
|
32
32
|
end
|
|
33
33
|
# ----------------- OAuth -----------------------
|
|
34
|
-
describe ApplicationController, "'
|
|
34
|
+
describe ApplicationController, "'using external API to login'" do
|
|
35
35
|
|
|
36
36
|
before(:each) do
|
|
37
37
|
stub_all_oauth_requests!
|
|
@@ -64,7 +64,7 @@ describe ApplicationController do
|
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
describe ApplicationController, "'create_from'" do
|
|
67
|
+
describe ApplicationController, "using 'create_from'" do
|
|
68
68
|
before(:each) do
|
|
69
69
|
stub_all_oauth_requests!
|
|
70
70
|
User.delete_all
|
|
@@ -90,7 +90,7 @@ describe ApplicationController do
|
|
|
90
90
|
end
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
-
describe ApplicationController, "OAuth with User Activation features" do
|
|
93
|
+
describe ApplicationController, "using OAuth with User Activation features" do
|
|
94
94
|
before(:all) do
|
|
95
95
|
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
|
|
96
96
|
sorcery_reload!([:user_activation,:external], :user_activation_mailer => ::SorceryMailer)
|
|
@@ -29,26 +29,27 @@ describe ApplicationController do
|
|
|
29
29
|
response.should be_a_redirect
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
context "with 'session_timeout_from_last_action'" do
|
|
33
|
+
it "should not logout if there was activity" do
|
|
34
|
+
sorcery_controller_property_set(:session_timeout_from_last_action, true)
|
|
35
|
+
get :test_login, :username => 'gizmo', :password => 'secret'
|
|
36
|
+
Timecop.travel(Time.now+0.3)
|
|
37
|
+
get :test_should_be_logged_in
|
|
38
|
+
session[:user_id].should_not be_nil
|
|
39
|
+
Timecop.travel(Time.now+0.3)
|
|
40
|
+
get :test_should_be_logged_in
|
|
41
|
+
session[:user_id].should_not be_nil
|
|
42
|
+
response.should be_a_success
|
|
43
|
+
end
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
it "with 'session_timeout_from_last_action' should logout if there was no activity" do
|
|
46
|
+
sorcery_controller_property_set(:session_timeout_from_last_action, true)
|
|
47
|
+
get :test_login, :username => 'gizmo', :password => 'secret'
|
|
48
|
+
Timecop.travel(Time.now+0.6)
|
|
49
|
+
get :test_should_be_logged_in
|
|
50
|
+
session[:user_id].should be_nil
|
|
51
|
+
response.should be_a_redirect
|
|
52
|
+
end
|
|
51
53
|
end
|
|
52
|
-
|
|
53
54
|
end
|
|
54
55
|
end
|
|
@@ -37,21 +37,13 @@ describe ApplicationController do
|
|
|
37
37
|
sorcery_controller_property_set(:user_class, User)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
it "should respond to the instance method logout" do
|
|
45
|
-
should respond_to(:logout)
|
|
46
|
-
end
|
|
40
|
+
specify { should respond_to(:login) }
|
|
41
|
+
|
|
42
|
+
specify { should respond_to(:logout) }
|
|
47
43
|
|
|
48
|
-
|
|
49
|
-
should respond_to(:logged_in?)
|
|
50
|
-
end
|
|
44
|
+
specify { should respond_to(:logged_in?) }
|
|
51
45
|
|
|
52
|
-
|
|
53
|
-
should respond_to(:current_user)
|
|
54
|
-
end
|
|
46
|
+
specify { should respond_to(:current_user) }
|
|
55
47
|
|
|
56
48
|
it "login(username,password) should return the user when success and set the session with user.id" do
|
|
57
49
|
get :test_login, :username => 'gizmo', :password => 'secret'
|
|
@@ -93,9 +85,7 @@ describe ApplicationController do
|
|
|
93
85
|
subject.current_user.should == false
|
|
94
86
|
end
|
|
95
87
|
|
|
96
|
-
|
|
97
|
-
should respond_to(:require_login)
|
|
98
|
-
end
|
|
88
|
+
specify { should respond_to(:require_login) }
|
|
99
89
|
|
|
100
90
|
it "should call the configured 'not_authenticated_action' when authenticate before_filter fails" do
|
|
101
91
|
session[:user_id] = nil
|
|
@@ -57,23 +57,17 @@ describe "User with activation submodule" do
|
|
|
57
57
|
sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
before(:each) do
|
|
61
61
|
create_new_user
|
|
62
|
-
@user.activation_token.should_not be_nil
|
|
63
62
|
end
|
|
64
63
|
|
|
65
64
|
it "should initialize user state to 'pending'" do
|
|
66
|
-
create_new_user
|
|
67
65
|
@user.activation_state.should == "pending"
|
|
68
66
|
end
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
create_new_user
|
|
72
|
-
@user.should respond_to(:activate!)
|
|
73
|
-
end
|
|
68
|
+
specify { @user.should respond_to(:activate!) }
|
|
74
69
|
|
|
75
70
|
it "should clear activation code and change state to 'active' on activation" do
|
|
76
|
-
create_new_user
|
|
77
71
|
activation_token = @user.activation_token
|
|
78
72
|
@user.activate!
|
|
79
73
|
@user2 = User.find(@user.id) # go to db to make sure it was saved and not just in memory
|
|
@@ -89,7 +83,6 @@ describe "User with activation submodule" do
|
|
|
89
83
|
end
|
|
90
84
|
|
|
91
85
|
it "subsequent saves do not send activation email" do
|
|
92
|
-
create_new_user
|
|
93
86
|
old_size = ActionMailer::Base.deliveries.size
|
|
94
87
|
@user.username = "Shauli"
|
|
95
88
|
@user.save!
|
|
@@ -97,14 +90,12 @@ describe "User with activation submodule" do
|
|
|
97
90
|
end
|
|
98
91
|
|
|
99
92
|
it "should send the user an activation success email on successful activation" do
|
|
100
|
-
create_new_user
|
|
101
93
|
old_size = ActionMailer::Base.deliveries.size
|
|
102
94
|
@user.activate!
|
|
103
95
|
ActionMailer::Base.deliveries.size.should == old_size + 1
|
|
104
96
|
end
|
|
105
97
|
|
|
106
98
|
it "subsequent saves do not send activation success email" do
|
|
107
|
-
create_new_user
|
|
108
99
|
@user.activate!
|
|
109
100
|
old_size = ActionMailer::Base.deliveries.size
|
|
110
101
|
@user.username = "Shauli"
|
|
@@ -121,7 +112,6 @@ describe "User with activation submodule" do
|
|
|
121
112
|
|
|
122
113
|
it "activation success email is optional" do
|
|
123
114
|
sorcery_model_property_set(:activation_success_email_method_name, nil)
|
|
124
|
-
create_new_user
|
|
125
115
|
old_size = ActionMailer::Base.deliveries.size
|
|
126
116
|
@user.activate!
|
|
127
117
|
ActionMailer::Base.deliveries.size.should == old_size
|
|
@@ -21,13 +21,8 @@ describe "User with brute_force_protection submodule" do
|
|
|
21
21
|
User.sorcery_config.reset!
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "should respond to 'lock_expires_at'" do
|
|
29
|
-
@user.should respond_to(:failed_logins_count)
|
|
30
|
-
end
|
|
24
|
+
specify { @user.should respond_to(:failed_logins_count) }
|
|
25
|
+
specify { @user.should respond_to(:lock_expires_at) }
|
|
31
26
|
|
|
32
27
|
it "should enable configuration option 'failed_logins_count_attribute_name'" do
|
|
33
28
|
sorcery_model_property_set(:failed_logins_count_attribute_name, :my_count)
|
|
@@ -49,28 +44,5 @@ describe "User with brute_force_protection submodule" do
|
|
|
49
44
|
User.sorcery_config.login_lock_time_period.should == 2.hours
|
|
50
45
|
end
|
|
51
46
|
end
|
|
52
|
-
|
|
53
|
-
# ----------------- PLUGIN ACTIVATED -----------------------
|
|
54
|
-
describe User, "when activated with sorcery" do
|
|
55
|
-
|
|
56
|
-
before(:all) do
|
|
57
|
-
sorcery_reload!([:brute_force_protection])
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
before(:each) do
|
|
61
|
-
User.delete_all
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# it "should increment failed_logins_count on a failed login" do
|
|
65
|
-
# create_new_user
|
|
66
|
-
#
|
|
67
|
-
# end
|
|
68
|
-
#
|
|
69
|
-
# it "should set lock expiry (effectively lock user) when failed_logins_count reaches max within max period" do
|
|
70
|
-
# create_new_user
|
|
71
|
-
# @user.lock_expires_at.should == Time.now.utc + 30
|
|
72
|
-
# end
|
|
73
|
-
|
|
74
|
-
end
|
|
75
47
|
|
|
76
48
|
end
|
|
@@ -13,6 +13,7 @@ describe "User with remember_me submodule" do
|
|
|
13
13
|
describe User, "loaded plugin configuration" do
|
|
14
14
|
before(:all) do
|
|
15
15
|
sorcery_reload!([:remember_me])
|
|
16
|
+
create_new_user
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
after(:each) do
|
|
@@ -29,32 +30,23 @@ describe "User with remember_me submodule" do
|
|
|
29
30
|
User.sorcery_config.remember_me_token_expires_at_attribute_name.should equal(:my_expires)
|
|
30
31
|
end
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
create_new_user
|
|
34
|
-
@user.should respond_to(:remember_me!)
|
|
35
|
-
end
|
|
33
|
+
specify { @user.should respond_to(:remember_me!) }
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
create_new_user
|
|
39
|
-
@user.should respond_to(:forget_me!)
|
|
40
|
-
end
|
|
35
|
+
specify { @user.should respond_to(:forget_me!) }
|
|
41
36
|
|
|
42
37
|
it "should generate a new token on 'remember_me!'" do
|
|
43
|
-
create_new_user
|
|
44
38
|
@user.remember_me_token.should be_nil
|
|
45
39
|
@user.remember_me!
|
|
46
40
|
@user.remember_me_token.should_not be_nil
|
|
47
41
|
end
|
|
48
42
|
|
|
49
43
|
it "should set an expiration based on 'remember_me_for' attribute" do
|
|
50
|
-
create_new_user
|
|
51
44
|
sorcery_model_property_set(:remember_me_for, 2 * 60 * 60 * 24)
|
|
52
45
|
@user.remember_me!
|
|
53
46
|
@user.remember_me_token_expires_at.to_s.should == (Time.now + 2 * 60 * 60 * 24).utc.to_s
|
|
54
47
|
end
|
|
55
48
|
|
|
56
49
|
it "should delete the token and expiration on 'forget_me!'" do
|
|
57
|
-
create_new_user
|
|
58
50
|
@user.remember_me!
|
|
59
51
|
@user.remember_me_token.should_not be_nil
|
|
60
52
|
@user.forget_me!
|