authlogic 0.10.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of authlogic might be problematic. Click here for more details.
- data/CHANGELOG.rdoc +11 -0
- data/Manifest +18 -81
- data/README.rdoc +53 -17
- data/Rakefile +1 -1
- data/authlogic.gemspec +7 -6
- data/lib/authlogic.rb +5 -0
- data/lib/authlogic/active_record/acts_as_authentic.rb +90 -58
- data/lib/authlogic/active_record/authenticates_many.rb +37 -0
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +5 -7
- data/lib/authlogic/controller_adapters/merb_adapter.rb +55 -0
- data/lib/authlogic/controller_adapters/rails_adapter.rb +21 -15
- data/lib/authlogic/session/base.rb +64 -116
- data/lib/authlogic/session/callbacks.rb +29 -13
- data/lib/authlogic/session/config.rb +5 -1
- data/lib/authlogic/session/scopes.rb +101 -0
- data/lib/authlogic/version.rb +3 -3
- data/test/active_record_acts_as_authentic_test.rb +213 -0
- data/test/active_record_authenticates_many_test.rb +28 -0
- data/{test_app/test → test}/fixtures/companies.yml +0 -2
- data/test/fixtures/employees.yml +17 -0
- data/{test_app/test → test}/fixtures/projects.yml +1 -2
- data/{test_app/test → test}/fixtures/users.yml +3 -5
- data/test/test_helper.rb +142 -0
- data/test/user_session_active_record_trickery_test.rb +12 -0
- data/test/user_session_base_test.rb +316 -0
- data/test/user_session_config_test.rb +144 -0
- data/test/user_session_scopes_test.rb +19 -0
- data/test_libs/aes128_crypto_provider.rb +17 -0
- data/test_libs/mock_controller.rb +19 -0
- data/test_libs/mock_cookie_jar.rb +6 -0
- data/test_libs/mock_request.rb +5 -0
- data/test_libs/ordered_hash.rb +9 -0
- metadata +32 -87
- data/test_app/README +0 -256
- data/test_app/Rakefile +0 -10
- data/test_app/app/controllers/application.rb +0 -72
- data/test_app/app/controllers/companies_controller.rb +0 -2
- data/test_app/app/controllers/user_sessions_controller.rb +0 -25
- data/test_app/app/controllers/users_controller.rb +0 -61
- data/test_app/app/helpers/application_helper.rb +0 -3
- data/test_app/app/helpers/companies_helper.rb +0 -2
- data/test_app/app/helpers/user_sessions_helper.rb +0 -2
- data/test_app/app/helpers/users_helper.rb +0 -2
- data/test_app/app/models/company.rb +0 -4
- data/test_app/app/models/project.rb +0 -3
- data/test_app/app/models/user.rb +0 -5
- data/test_app/app/models/user_session.rb +0 -3
- data/test_app/app/views/layouts/application.html.erb +0 -27
- data/test_app/app/views/user_sessions/new.html.erb +0 -15
- data/test_app/app/views/users/_form.erb +0 -15
- data/test_app/app/views/users/edit.html.erb +0 -8
- data/test_app/app/views/users/new.html.erb +0 -8
- data/test_app/app/views/users/show.html.erb +0 -29
- data/test_app/config/boot.rb +0 -109
- data/test_app/config/database.yml +0 -19
- data/test_app/config/environment.rb +0 -69
- data/test_app/config/environments/development.rb +0 -17
- data/test_app/config/environments/production.rb +0 -22
- data/test_app/config/environments/test.rb +0 -22
- data/test_app/config/initializers/inflections.rb +0 -10
- data/test_app/config/initializers/mime_types.rb +0 -5
- data/test_app/config/initializers/new_rails_defaults.rb +0 -17
- data/test_app/config/routes.rb +0 -11
- data/test_app/db/development.sqlite3 +0 -0
- data/test_app/db/migrate/20081023040052_create_users.rb +0 -20
- data/test_app/db/migrate/20081103003828_create_companies.rb +0 -14
- data/test_app/db/migrate/20081103003834_create_projects.rb +0 -18
- data/test_app/db/schema.rb +0 -46
- data/test_app/db/test.sqlite3 +0 -0
- data/test_app/doc/README_FOR_APP +0 -2
- data/test_app/public/404.html +0 -30
- data/test_app/public/422.html +0 -30
- data/test_app/public/500.html +0 -30
- data/test_app/public/dispatch.cgi +0 -10
- data/test_app/public/dispatch.fcgi +0 -24
- data/test_app/public/dispatch.rb +0 -10
- data/test_app/public/favicon.ico +0 -0
- data/test_app/public/images/rails.png +0 -0
- data/test_app/public/javascripts/application.js +0 -2
- data/test_app/public/javascripts/controls.js +0 -963
- data/test_app/public/javascripts/dragdrop.js +0 -972
- data/test_app/public/javascripts/effects.js +0 -1120
- data/test_app/public/javascripts/prototype.js +0 -4225
- data/test_app/public/robots.txt +0 -5
- data/test_app/public/stylesheets/scaffold.css +0 -62
- data/test_app/script/about +0 -4
- data/test_app/script/console +0 -3
- data/test_app/script/dbconsole +0 -3
- data/test_app/script/destroy +0 -3
- data/test_app/script/generate +0 -3
- data/test_app/script/performance/benchmarker +0 -3
- data/test_app/script/performance/profiler +0 -3
- data/test_app/script/performance/request +0 -3
- data/test_app/script/plugin +0 -3
- data/test_app/script/process/inspector +0 -3
- data/test_app/script/process/reaper +0 -3
- data/test_app/script/process/spawner +0 -3
- data/test_app/script/runner +0 -3
- data/test_app/script/server +0 -3
- data/test_app/test/functional/companies_controller_test.rb +0 -8
- data/test_app/test/functional/user_sessions_controller_test.rb +0 -36
- data/test_app/test/functional/users_controller_test.rb +0 -8
- data/test_app/test/integration/company_user_session_stories_test.rb +0 -46
- data/test_app/test/integration/user_sesion_stories_test.rb +0 -105
- data/test_app/test/integration/user_session_config_test.rb +0 -24
- data/test_app/test/integration/user_session_test.rb +0 -161
- data/test_app/test/test_helper.rb +0 -81
- data/test_app/test/unit/account_test.rb +0 -8
- data/test_app/test/unit/company_test.rb +0 -8
- data/test_app/test/unit/project_test.rb +0 -8
- data/test_app/test/unit/user_test.rb +0 -80
@@ -0,0 +1,17 @@
|
|
1
|
+
drew:
|
2
|
+
company: binary_logic
|
3
|
+
email: dgainor@binarylogic.com
|
4
|
+
password_salt: <%= salt = Employee.unique_token %>
|
5
|
+
crypted_password: "<%= Employee.crypto_provider.encrypt("drewrocks" + salt) %>"
|
6
|
+
remember_token: 5273d85ed156e9dbd6a7c1438d319ef8c8d41dd24368db6c222de11346c7b11e53ee08d45ecf619b1c1dc91233d22b372482b751b066d0a6f6f9bac42eacaabf
|
7
|
+
first_name: Drew
|
8
|
+
last_name: Gainor
|
9
|
+
|
10
|
+
jennifer:
|
11
|
+
company: logic_over_data
|
12
|
+
email: jjohnson@logicoverdata.com
|
13
|
+
password_salt: <%= salt = Employee.unique_token %>
|
14
|
+
crypted_password: "<%= Employee.crypto_provider.encrypt("jenniferocks" + salt) %>"
|
15
|
+
remember_token: 2be52a8f741ad00056e6f94eb6844d5316527206da7a3a5e3d0e14d19499ef9fe4c47c89b87febb59a2b41a69edfb4733b6b79302040f3de83f297c6991c75a2
|
16
|
+
first_name: Jennifer
|
17
|
+
last_name: Johnson
|
@@ -1,6 +1,5 @@
|
|
1
1
|
ben:
|
2
|
-
|
3
|
-
company_id: 1
|
2
|
+
company: binary_logic
|
4
3
|
projects: web_services
|
5
4
|
login: bjohnson
|
6
5
|
password_salt: <%= salt = User.unique_token %>
|
@@ -10,12 +9,11 @@ ben:
|
|
10
9
|
last_name: Johnson
|
11
10
|
|
12
11
|
zack:
|
13
|
-
|
14
|
-
company_id: 2
|
12
|
+
company: logic_over_data
|
15
13
|
projects: web_services
|
16
14
|
login: zham
|
17
15
|
password_salt: <%= salt = User.unique_token %>
|
18
16
|
crypted_password: <%= Authlogic::Sha512CryptoProvider.encrypt("zackrocks" + salt) %>
|
19
17
|
remember_token: fd3c2d5ce09ab98e7547d21f1b3dcf9158a9a19b5d3022c0402f32ae197019fce3fdbc6614d7ee57d719bae53bb089e30edc9e5d6153e5bc3afca0ac1d320342
|
20
18
|
first_name: Zack
|
21
|
-
last_name: Ham
|
19
|
+
last_name: Ham
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "rubygems"
|
3
|
+
require "ruby-debug"
|
4
|
+
require "active_record"
|
5
|
+
require 'active_record/fixtures'
|
6
|
+
require File.dirname(__FILE__) + '/../lib/authlogic'
|
7
|
+
require File.dirname(__FILE__) + '/../test_libs/aes128_crypto_provider'
|
8
|
+
require File.dirname(__FILE__) + '/../test_libs/mock_request'
|
9
|
+
require File.dirname(__FILE__) + '/../test_libs/mock_cookie_jar'
|
10
|
+
require File.dirname(__FILE__) + '/../test_libs/mock_controller'
|
11
|
+
|
12
|
+
ActiveRecord::Schema.verbose = false
|
13
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
|
14
|
+
ActiveRecord::Base.configurations = true
|
15
|
+
ActiveRecord::Schema.define(:version => 1) do
|
16
|
+
create_table :companies do |t|
|
17
|
+
t.datetime :created_at
|
18
|
+
t.datetime :updated_at
|
19
|
+
t.string :name
|
20
|
+
t.boolean :active
|
21
|
+
end
|
22
|
+
|
23
|
+
create_table :projects do |t|
|
24
|
+
t.datetime :created_at
|
25
|
+
t.datetime :updated_at
|
26
|
+
t.string :name
|
27
|
+
end
|
28
|
+
|
29
|
+
create_table :projects_users, :id => false do |t|
|
30
|
+
t.integer :project_id
|
31
|
+
t.integer :user_id
|
32
|
+
end
|
33
|
+
|
34
|
+
create_table :users do |t|
|
35
|
+
t.datetime :created_at
|
36
|
+
t.datetime :updated_at
|
37
|
+
t.integer :company_id
|
38
|
+
t.string :login
|
39
|
+
t.string :crypted_password
|
40
|
+
t.string :password_salt
|
41
|
+
t.string :remember_token
|
42
|
+
t.string :first_name
|
43
|
+
t.string :last_name
|
44
|
+
t.integer :login_count
|
45
|
+
t.datetime :last_request_at
|
46
|
+
t.datetime :current_login_at
|
47
|
+
t.datetime :last_login_at
|
48
|
+
t.string :current_login_ip
|
49
|
+
t.string :last_login_ip
|
50
|
+
end
|
51
|
+
|
52
|
+
create_table :employees do |t|
|
53
|
+
t.datetime :created_at
|
54
|
+
t.datetime :updated_at
|
55
|
+
t.integer :company_id
|
56
|
+
t.string :email
|
57
|
+
t.string :crypted_password
|
58
|
+
t.string :password_salt
|
59
|
+
t.string :remember_token
|
60
|
+
t.string :first_name
|
61
|
+
t.string :last_name
|
62
|
+
t.integer :login_count
|
63
|
+
t.datetime :last_request_at
|
64
|
+
t.datetime :current_login_at
|
65
|
+
t.datetime :last_login_at
|
66
|
+
t.string :current_login_ip
|
67
|
+
t.string :last_login_ip
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class Project < ActiveRecord::Base
|
72
|
+
has_and_belongs_to_many :users
|
73
|
+
end
|
74
|
+
|
75
|
+
class UserSession < Authlogic::Session::Base
|
76
|
+
end
|
77
|
+
|
78
|
+
class EmployeeSession < Authlogic::Session::Base
|
79
|
+
end
|
80
|
+
|
81
|
+
class Company < ActiveRecord::Base
|
82
|
+
authenticates_many :employee_sessions
|
83
|
+
authenticates_many :user_sessions
|
84
|
+
has_many :employees, :dependent => :destroy
|
85
|
+
has_many :users, :dependent => :destroy
|
86
|
+
end
|
87
|
+
|
88
|
+
class User < ActiveRecord::Base
|
89
|
+
acts_as_authentic
|
90
|
+
belongs_to :company
|
91
|
+
has_and_belongs_to_many :projects
|
92
|
+
end
|
93
|
+
|
94
|
+
class Employee < ActiveRecord::Base
|
95
|
+
acts_as_authentic :crypto_provider => AES128CryptoProvider
|
96
|
+
belongs_to :company
|
97
|
+
end
|
98
|
+
|
99
|
+
class Test::Unit::TestCase
|
100
|
+
self.fixture_path = File.dirname(__FILE__) + "/fixtures"
|
101
|
+
self.use_transactional_fixtures = true
|
102
|
+
self.use_instantiated_fixtures = false
|
103
|
+
self.pre_loaded_fixtures = true
|
104
|
+
fixtures :all
|
105
|
+
setup :activate_authlogic
|
106
|
+
teardown :deactivate_authlogic
|
107
|
+
|
108
|
+
private
|
109
|
+
def activate_authlogic
|
110
|
+
@controller = MockController.new
|
111
|
+
Authlogic::Session::Base.controller = @controller
|
112
|
+
end
|
113
|
+
|
114
|
+
def deactivate_authlogic
|
115
|
+
Authlogic::Session::Base.reset_controllers!
|
116
|
+
end
|
117
|
+
|
118
|
+
def http_basic_auth_for(user = nil, &block)
|
119
|
+
unless user.blank?
|
120
|
+
@controller.http_user = user.login
|
121
|
+
@controller.http_password = user.crypted_password
|
122
|
+
end
|
123
|
+
yield
|
124
|
+
@controller.http_user = @controller.http_password = nil
|
125
|
+
end
|
126
|
+
|
127
|
+
def set_cookie_for(user, id = nil)
|
128
|
+
@controller.cookies["user_credentials"] = {:value => user.remember_token, :expires => nil}
|
129
|
+
end
|
130
|
+
|
131
|
+
def unset_cookie
|
132
|
+
@controller.cookies["user_credentials"] = nil
|
133
|
+
end
|
134
|
+
|
135
|
+
def set_session_for(user, id = nil)
|
136
|
+
@controller.session["user_credentials"] = user.remember_token
|
137
|
+
end
|
138
|
+
|
139
|
+
def unset_session
|
140
|
+
@controller.session["user_credentials"] = nil
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class UserSessionActiveRecordTrickeryTest < ActiveSupport::TestCase
|
4
|
+
def test_human_attribute_name
|
5
|
+
assert_equal "Some attribute", UserSession.human_attribute_name("some_attribute")
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_new_record
|
9
|
+
session = UserSession.new
|
10
|
+
assert session.new_record?
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,316 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class UserSessionBaseTest < ActiveSupport::TestCase
|
4
|
+
def test_activated
|
5
|
+
assert UserSession.activated?
|
6
|
+
Authlogic::Session::Base.reset_controllers!
|
7
|
+
assert !UserSession.activated?
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_controllers
|
11
|
+
Authlogic::Session::Base.reset_controllers!
|
12
|
+
assert_equal 0, Authlogic::Session::Base.send(:controllers).size
|
13
|
+
thread1 = Thread.new do
|
14
|
+
controller = MockController.new
|
15
|
+
Authlogic::Session::Base.controller = controller
|
16
|
+
assert_equal controller, Authlogic::Session::Base.controller
|
17
|
+
end
|
18
|
+
thread1.join
|
19
|
+
assert_equal 1, Authlogic::Session::Base.send(:controllers).size
|
20
|
+
assert_equal nil, Authlogic::Session::Base.controller
|
21
|
+
thread2 = Thread.new do
|
22
|
+
controller = MockController.new
|
23
|
+
Authlogic::Session::Base.controller = controller
|
24
|
+
assert_equal controller, Authlogic::Session::Base.controller
|
25
|
+
end
|
26
|
+
thread2.join
|
27
|
+
assert_equal 2, Authlogic::Session::Base.send(:controllers).size
|
28
|
+
assert_equal nil, Authlogic::Session::Base.controller
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_create
|
32
|
+
ben = users(:ben)
|
33
|
+
assert !UserSession.create(ben.login, "badpw")
|
34
|
+
assert UserSession.create(ben.login, "benrocks")
|
35
|
+
assert_raise(Authlogic::Session::SessionInvalid) { UserSession.create!(ben.login, "badpw") }
|
36
|
+
assert UserSession.create!(ben.login, "benrocks")
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_find
|
40
|
+
ben = users(:ben)
|
41
|
+
assert !UserSession.find
|
42
|
+
http_basic_auth_for(ben) { assert UserSession.find }
|
43
|
+
set_cookie_for(ben)
|
44
|
+
assert UserSession.find
|
45
|
+
unset_cookie
|
46
|
+
set_session_for(ben)
|
47
|
+
session = UserSession.find
|
48
|
+
assert session
|
49
|
+
assert !session.record.last_request_at.nil?
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_klass
|
53
|
+
assert_equal User, UserSession.klass
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_klass_name
|
57
|
+
assert_equal "User", UserSession.klass_name
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_scope_method # test_scope is reserved
|
61
|
+
UserSession.with_scope(:find_options => {:conditions => "1 = 1"}, :id => "some_id") do
|
62
|
+
assert_equal({:find_options => {:conditions => "1 = 1"}, :id => "some_id"}, UserSession.scope)
|
63
|
+
|
64
|
+
ben = users(:ben)
|
65
|
+
session = UserSession.new
|
66
|
+
assert_equal({:find_options => {:conditions => "1 = 1"}, :id => "some_id"}, session.scope)
|
67
|
+
|
68
|
+
session.id = :another_id
|
69
|
+
session.unauthorized_record = ben
|
70
|
+
assert session.save
|
71
|
+
assert_equal ben.remember_token, @controller.session["another_id_some_id_user_credentials"]
|
72
|
+
assert_equal ben.remember_token, @controller.cookies["another_id_some_id_user_credentials"]
|
73
|
+
end
|
74
|
+
|
75
|
+
assert_equal nil, UserSession.scope
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_with_scope_method # test_with_scope is reserved
|
79
|
+
assert_raise(ArgumentError) { UserSession.with_scope }
|
80
|
+
# the rest of the method was tested in test_scope
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_init
|
84
|
+
UserSession.reset_controllers!
|
85
|
+
assert_raise(Authlogic::Session::NotActivated) { UserSession.new }
|
86
|
+
UserSession.controller = @controller
|
87
|
+
|
88
|
+
session = UserSession.new
|
89
|
+
assert session.respond_to?(:login)
|
90
|
+
assert session.respond_to?(:login=)
|
91
|
+
assert session.respond_to?(:password)
|
92
|
+
assert session.respond_to?(:password=)
|
93
|
+
assert session.respond_to?(:protected_password, true)
|
94
|
+
|
95
|
+
|
96
|
+
session = UserSession.new(:my_id)
|
97
|
+
assert_equal :my_id, session.id
|
98
|
+
|
99
|
+
session = UserSession.new("login", "pass", true, :my_id)
|
100
|
+
assert_equal "login", session.login
|
101
|
+
assert_equal nil, session.password
|
102
|
+
assert_equal "pass", session.send(:protected_password)
|
103
|
+
assert_equal true, session.remember_me
|
104
|
+
assert_equal :my_id, session.id
|
105
|
+
|
106
|
+
session = UserSession.new({:login => "login", :password => "pass", :remember_me => true}, :my_id)
|
107
|
+
assert_equal "login", session.login
|
108
|
+
assert_equal nil, session.password
|
109
|
+
assert_equal "pass", session.send(:protected_password)
|
110
|
+
assert_equal true, session.remember_me
|
111
|
+
assert_equal :my_id, session.id
|
112
|
+
|
113
|
+
session = UserSession.new(users(:ben), :my_id)
|
114
|
+
assert_equal nil, session.login
|
115
|
+
assert_equal nil, session.password
|
116
|
+
assert_equal nil, session.send(:protected_password)
|
117
|
+
assert_equal nil, session.remember_me
|
118
|
+
assert_equal :my_id, session.id
|
119
|
+
assert_equal users(:ben), session.unauthorized_record
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_credentials
|
123
|
+
session = UserSession.new
|
124
|
+
session.credentials = {:login => "login", :password => "pass", :remember_me => true}
|
125
|
+
assert_equal "login", session.login
|
126
|
+
assert_equal nil, session.password
|
127
|
+
assert_equal "pass", session.send(:protected_password)
|
128
|
+
assert_equal true, session.remember_me
|
129
|
+
assert_equal({:password => "<Protected>", :login => "login"}, session.credentials)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_destroy
|
133
|
+
ben = users(:ben)
|
134
|
+
session = UserSession.create(ben)
|
135
|
+
assert session
|
136
|
+
assert_equal ben.remember_token, @controller.session["user_credentials"]
|
137
|
+
assert_equal ben.remember_token, @controller.cookies["user_credentials"]
|
138
|
+
session.destroy
|
139
|
+
assert_equal nil, @controller.session["user_credentials"]
|
140
|
+
assert_equal nil, @controller.cookies["user_credentials"]
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_errors
|
144
|
+
session = UserSession.new
|
145
|
+
assert session.errors.is_a?(Authlogic::Session::Errors)
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_find_record
|
149
|
+
# tested thoroughly in test_find
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_id
|
153
|
+
ben = users(:ben)
|
154
|
+
session = UserSession.new(ben, :my_id)
|
155
|
+
assert_equal :my_id, session.id
|
156
|
+
assert session.save
|
157
|
+
assert_equal ben.remember_token, @controller.session["my_id_user_credentials"]
|
158
|
+
assert_equal ben.remember_token, @controller.cookies["my_id_user_credentials"]
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_inspect
|
162
|
+
session = UserSession.new
|
163
|
+
assert_equal "#<UserSession {:unauthorized_record=>\"<protected>\"}>", session.inspect
|
164
|
+
session.login = "login"
|
165
|
+
session.password = "pass"
|
166
|
+
assert "#<UserSession {:login=>\"login\", :password=>\"<protected>\"}>" == session.inspect || "#<UserSession {:password=>\"<protected>\", :login=>\"login\"}>" == session.inspect
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_new_session
|
170
|
+
session = UserSession.new
|
171
|
+
assert session.new_session?
|
172
|
+
|
173
|
+
set_session_for(users(:ben))
|
174
|
+
session = UserSession.find
|
175
|
+
assert !session.new_session?
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_remember_me
|
179
|
+
session = UserSession.new
|
180
|
+
assert_equal nil, session.remember_me
|
181
|
+
assert !session.remember_me?
|
182
|
+
|
183
|
+
session.remember_me = false
|
184
|
+
assert_equal false, session.remember_me
|
185
|
+
assert !session.remember_me?
|
186
|
+
|
187
|
+
session.remember_me = true
|
188
|
+
assert_equal true, session.remember_me
|
189
|
+
assert session.remember_me?
|
190
|
+
|
191
|
+
session.remember_me = nil
|
192
|
+
assert_equal nil, session.remember_me
|
193
|
+
assert !session.remember_me?
|
194
|
+
|
195
|
+
session.remember_me = "1"
|
196
|
+
assert_equal "1", session.remember_me
|
197
|
+
assert session.remember_me?
|
198
|
+
|
199
|
+
session.remember_me = "true"
|
200
|
+
assert_equal "true", session.remember_me
|
201
|
+
assert session.remember_me?
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_remember_me_until
|
205
|
+
session = UserSession.new
|
206
|
+
assert_equal nil, session.remember_me_until
|
207
|
+
|
208
|
+
session.remember_me = true
|
209
|
+
assert 3.months.from_now <= session.remember_me_until
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_save_with_nothing
|
213
|
+
session = UserSession.new
|
214
|
+
assert !session.save
|
215
|
+
assert session.new_session?
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_save_with_record
|
219
|
+
ben = users(:ben)
|
220
|
+
session = UserSession.new(ben.login, "benrocks")
|
221
|
+
assert session.save
|
222
|
+
assert !session.new_session?
|
223
|
+
assert_equal ben.remember_token, @controller.session["user_credentials"]
|
224
|
+
assert_equal ben.remember_token, @controller.cookies["user_credentials"]
|
225
|
+
assert_equal 1, session.record.login_count
|
226
|
+
assert Time.now >= session.record.current_login_at
|
227
|
+
assert_equal "1.1.1.1", session.record.current_login_ip
|
228
|
+
unset_cookie
|
229
|
+
unset_session
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_save_with_credentials
|
233
|
+
ben = users(:ben)
|
234
|
+
session = UserSession.new(ben)
|
235
|
+
assert session.save
|
236
|
+
assert !session.new_session?
|
237
|
+
assert_equal ben.remember_token, @controller.session["user_credentials"]
|
238
|
+
assert_equal ben.remember_token, @controller.cookies["user_credentials"]
|
239
|
+
assert_equal 1, session.record.login_count
|
240
|
+
assert Time.now >= session.record.current_login_at
|
241
|
+
assert_equal "1.1.1.1", session.record.current_login_ip
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_save_with_bang
|
245
|
+
session = UserSession.new
|
246
|
+
assert_raise(Authlogic::Session::SessionInvalid) { session.save! }
|
247
|
+
|
248
|
+
session.unauthorized_record = users(:ben)
|
249
|
+
assert session.save!
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_unauthorized_record
|
253
|
+
session = UserSession.new
|
254
|
+
ben = users(:ben)
|
255
|
+
session.unauthorized_record = ben
|
256
|
+
assert_equal ben, session.unauthorized_record
|
257
|
+
assert_equal :unauthorized_record, session.login_with
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_valid
|
261
|
+
session = UserSession.new
|
262
|
+
assert !session.valid?
|
263
|
+
assert_equal nil, session.record
|
264
|
+
assert session.errors.count > 0
|
265
|
+
|
266
|
+
ben = users(:ben)
|
267
|
+
session.unauthorized_record = ben
|
268
|
+
assert session.valid?
|
269
|
+
assert_equal ben, session.record
|
270
|
+
assert session.errors.empty?
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_valid_http_auth
|
274
|
+
ben = users(:ben)
|
275
|
+
session = UserSession.new
|
276
|
+
|
277
|
+
http_basic_auth_for { assert !session.valid_http_auth? }
|
278
|
+
|
279
|
+
http_basic_auth_for(ben) do
|
280
|
+
assert session.valid_http_auth?
|
281
|
+
assert_equal ben, session.record
|
282
|
+
assert_equal ben.remember_token, @controller.session["user_credentials"]
|
283
|
+
assert_equal ben.login, session.login
|
284
|
+
assert_equal ben.crypted_password, session.send(:protected_password)
|
285
|
+
assert !session.new_session?
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
def test_valid_cookie
|
290
|
+
ben = users(:ben)
|
291
|
+
session = UserSession.new
|
292
|
+
|
293
|
+
assert !session.valid_cookie?
|
294
|
+
|
295
|
+
set_cookie_for(ben)
|
296
|
+
assert session.valid_cookie?
|
297
|
+
assert_equal ben, session.record
|
298
|
+
assert_equal ben.remember_token, @controller.session["user_credentials"]
|
299
|
+
assert_equal ben, session.unauthorized_record
|
300
|
+
assert !session.new_session?
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_valid_session
|
304
|
+
ben = users(:ben)
|
305
|
+
session = UserSession.new
|
306
|
+
|
307
|
+
assert !session.valid_session?
|
308
|
+
|
309
|
+
set_session_for(ben)
|
310
|
+
assert session.valid_session?
|
311
|
+
assert_equal ben, session.record
|
312
|
+
assert_equal ben.remember_token, @controller.session["user_credentials"]
|
313
|
+
assert_equal ben, session.unauthorized_record
|
314
|
+
assert !session.new_session?
|
315
|
+
end
|
316
|
+
end
|