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.

Files changed (111) hide show
  1. data/CHANGELOG.rdoc +11 -0
  2. data/Manifest +18 -81
  3. data/README.rdoc +53 -17
  4. data/Rakefile +1 -1
  5. data/authlogic.gemspec +7 -6
  6. data/lib/authlogic.rb +5 -0
  7. data/lib/authlogic/active_record/acts_as_authentic.rb +90 -58
  8. data/lib/authlogic/active_record/authenticates_many.rb +37 -0
  9. data/lib/authlogic/controller_adapters/abstract_adapter.rb +5 -7
  10. data/lib/authlogic/controller_adapters/merb_adapter.rb +55 -0
  11. data/lib/authlogic/controller_adapters/rails_adapter.rb +21 -15
  12. data/lib/authlogic/session/base.rb +64 -116
  13. data/lib/authlogic/session/callbacks.rb +29 -13
  14. data/lib/authlogic/session/config.rb +5 -1
  15. data/lib/authlogic/session/scopes.rb +101 -0
  16. data/lib/authlogic/version.rb +3 -3
  17. data/test/active_record_acts_as_authentic_test.rb +213 -0
  18. data/test/active_record_authenticates_many_test.rb +28 -0
  19. data/{test_app/test → test}/fixtures/companies.yml +0 -2
  20. data/test/fixtures/employees.yml +17 -0
  21. data/{test_app/test → test}/fixtures/projects.yml +1 -2
  22. data/{test_app/test → test}/fixtures/users.yml +3 -5
  23. data/test/test_helper.rb +142 -0
  24. data/test/user_session_active_record_trickery_test.rb +12 -0
  25. data/test/user_session_base_test.rb +316 -0
  26. data/test/user_session_config_test.rb +144 -0
  27. data/test/user_session_scopes_test.rb +19 -0
  28. data/test_libs/aes128_crypto_provider.rb +17 -0
  29. data/test_libs/mock_controller.rb +19 -0
  30. data/test_libs/mock_cookie_jar.rb +6 -0
  31. data/test_libs/mock_request.rb +5 -0
  32. data/test_libs/ordered_hash.rb +9 -0
  33. metadata +32 -87
  34. data/test_app/README +0 -256
  35. data/test_app/Rakefile +0 -10
  36. data/test_app/app/controllers/application.rb +0 -72
  37. data/test_app/app/controllers/companies_controller.rb +0 -2
  38. data/test_app/app/controllers/user_sessions_controller.rb +0 -25
  39. data/test_app/app/controllers/users_controller.rb +0 -61
  40. data/test_app/app/helpers/application_helper.rb +0 -3
  41. data/test_app/app/helpers/companies_helper.rb +0 -2
  42. data/test_app/app/helpers/user_sessions_helper.rb +0 -2
  43. data/test_app/app/helpers/users_helper.rb +0 -2
  44. data/test_app/app/models/company.rb +0 -4
  45. data/test_app/app/models/project.rb +0 -3
  46. data/test_app/app/models/user.rb +0 -5
  47. data/test_app/app/models/user_session.rb +0 -3
  48. data/test_app/app/views/layouts/application.html.erb +0 -27
  49. data/test_app/app/views/user_sessions/new.html.erb +0 -15
  50. data/test_app/app/views/users/_form.erb +0 -15
  51. data/test_app/app/views/users/edit.html.erb +0 -8
  52. data/test_app/app/views/users/new.html.erb +0 -8
  53. data/test_app/app/views/users/show.html.erb +0 -29
  54. data/test_app/config/boot.rb +0 -109
  55. data/test_app/config/database.yml +0 -19
  56. data/test_app/config/environment.rb +0 -69
  57. data/test_app/config/environments/development.rb +0 -17
  58. data/test_app/config/environments/production.rb +0 -22
  59. data/test_app/config/environments/test.rb +0 -22
  60. data/test_app/config/initializers/inflections.rb +0 -10
  61. data/test_app/config/initializers/mime_types.rb +0 -5
  62. data/test_app/config/initializers/new_rails_defaults.rb +0 -17
  63. data/test_app/config/routes.rb +0 -11
  64. data/test_app/db/development.sqlite3 +0 -0
  65. data/test_app/db/migrate/20081023040052_create_users.rb +0 -20
  66. data/test_app/db/migrate/20081103003828_create_companies.rb +0 -14
  67. data/test_app/db/migrate/20081103003834_create_projects.rb +0 -18
  68. data/test_app/db/schema.rb +0 -46
  69. data/test_app/db/test.sqlite3 +0 -0
  70. data/test_app/doc/README_FOR_APP +0 -2
  71. data/test_app/public/404.html +0 -30
  72. data/test_app/public/422.html +0 -30
  73. data/test_app/public/500.html +0 -30
  74. data/test_app/public/dispatch.cgi +0 -10
  75. data/test_app/public/dispatch.fcgi +0 -24
  76. data/test_app/public/dispatch.rb +0 -10
  77. data/test_app/public/favicon.ico +0 -0
  78. data/test_app/public/images/rails.png +0 -0
  79. data/test_app/public/javascripts/application.js +0 -2
  80. data/test_app/public/javascripts/controls.js +0 -963
  81. data/test_app/public/javascripts/dragdrop.js +0 -972
  82. data/test_app/public/javascripts/effects.js +0 -1120
  83. data/test_app/public/javascripts/prototype.js +0 -4225
  84. data/test_app/public/robots.txt +0 -5
  85. data/test_app/public/stylesheets/scaffold.css +0 -62
  86. data/test_app/script/about +0 -4
  87. data/test_app/script/console +0 -3
  88. data/test_app/script/dbconsole +0 -3
  89. data/test_app/script/destroy +0 -3
  90. data/test_app/script/generate +0 -3
  91. data/test_app/script/performance/benchmarker +0 -3
  92. data/test_app/script/performance/profiler +0 -3
  93. data/test_app/script/performance/request +0 -3
  94. data/test_app/script/plugin +0 -3
  95. data/test_app/script/process/inspector +0 -3
  96. data/test_app/script/process/reaper +0 -3
  97. data/test_app/script/process/spawner +0 -3
  98. data/test_app/script/runner +0 -3
  99. data/test_app/script/server +0 -3
  100. data/test_app/test/functional/companies_controller_test.rb +0 -8
  101. data/test_app/test/functional/user_sessions_controller_test.rb +0 -36
  102. data/test_app/test/functional/users_controller_test.rb +0 -8
  103. data/test_app/test/integration/company_user_session_stories_test.rb +0 -46
  104. data/test_app/test/integration/user_sesion_stories_test.rb +0 -105
  105. data/test_app/test/integration/user_session_config_test.rb +0 -24
  106. data/test_app/test/integration/user_session_test.rb +0 -161
  107. data/test_app/test/test_helper.rb +0 -81
  108. data/test_app/test/unit/account_test.rb +0 -8
  109. data/test_app/test/unit/company_test.rb +0 -8
  110. data/test_app/test/unit/project_test.rb +0 -8
  111. data/test_app/test/unit/user_test.rb +0 -80
@@ -1,81 +0,0 @@
1
- ENV["RAILS_ENV"] = "test"
2
- require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
- require 'test_help'
4
-
5
- class Test::Unit::TestCase
6
- self.use_transactional_fixtures = true
7
- self.use_instantiated_fixtures = false
8
- fixtures :all
9
- end
10
-
11
- class ActionController::IntegrationTest
12
- attr_accessor :scope
13
-
14
- def setup
15
- get new_user_session_url # to active authlogic
16
- end
17
-
18
- def teardown
19
- Authlogic::Session::Base.controller = nil
20
- end
21
-
22
- private
23
- def assert_successful_login(login, password)
24
- post scoped_url("user_session_url"), :user_session => {:login => login, :password => password}
25
- assert_redirected_to scoped_url("account_url")
26
- follow_redirect!
27
- assert_template "users/show"
28
- end
29
-
30
- def assert_unsuccessful_login(login = nil, password = nil)
31
- params = (login || password) ? {:user_session => {:login => login, :password => password}} : nil
32
- post scoped_url("user_session_url"), params
33
- assert_template "user_sessions/new"
34
- end
35
-
36
- def assert_successful_logout(alt_redirect = nil)
37
- redirecting_to = alt_redirect || scoped_url("new_user_session_url")
38
- delete scoped_url("user_session_url")
39
- assert_redirected_to redirecting_to # because I tried to access registration above, and it stored it
40
- follow_redirect!
41
- assert flash.key?(:notice)
42
- assert_equal nil, session[scoped_key]
43
- assert_equal "", cookies[scoped_key]
44
- assert_template redirecting_to.gsub("http://www.example.com/", "").gsub("user_session", "user_sessions").gsub("account", "users").gsub(/^companies\/[1-9]*\//, "")
45
- end
46
-
47
- def assert_account_access(user = nil)
48
- user ||= users(:ben).reload
49
- # Perform multiple requests to make sure the session is persisting properly, just being anal here
50
- 3.times do
51
- get scoped_url("account_url")
52
- assert_equal user.remember_token, session[scoped_key]
53
- assert_equal user.remember_token, cookies[scoped_key]
54
- assert_response :success
55
- assert_template "users/show"
56
- end
57
- end
58
-
59
- def assert_no_account_access(alt_redirect = nil)
60
- get scoped_url("account_url")
61
- assert_redirected_to alt_redirect || scoped_url("new_user_session_url")
62
- end
63
-
64
- def scoped_url(unscoped_url, *args)
65
- case scope
66
- when Company
67
- regex = /^(new|edit)_/
68
- prefix = unscoped_url =~ regex ? "#{$1}_" : ""
69
- send("#{prefix}company_#{unscoped_url.gsub(regex, "")}", scope.id, *args)
70
- else
71
- send(unscoped_url, *args)
72
- end
73
- end
74
-
75
- def scoped_key
76
- parts = []
77
- parts << "#{scope.class.model_name.underscore}_#{scope.id}" if scope
78
- parts << "user_credentials"
79
- parts.join("_")
80
- end
81
- end
@@ -1,8 +0,0 @@
1
- require 'test_helper'
2
-
3
- class AccountTest < ActiveSupport::TestCase
4
- # Replace this with your real tests.
5
- def test_truth
6
- assert true
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- require 'test_helper'
2
-
3
- class CompanyTest < ActiveSupport::TestCase
4
- # Replace this with your real tests.
5
- def test_truth
6
- assert true
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ProjectTest < ActiveSupport::TestCase
4
- # Replace this with your real tests.
5
- def test_truth
6
- assert true
7
- end
8
- end
@@ -1,80 +0,0 @@
1
- require 'test_helper'
2
-
3
- class UserTest < ActiveSupport::TestCase
4
- def test_validations
5
- user = User.new
6
- assert !user.valid?
7
- assert user.errors.on(:login)
8
- user.login = "^fds#%"
9
- assert !user.valid?
10
- assert user.errors.on(:login)
11
- user.login = "bjohnson"
12
- assert !user.valid?
13
- assert user.errors.on(:login)
14
- user.login = "unique"
15
- assert !user.valid?
16
- assert user.errors.on(:password)
17
- user.password = "awesome"
18
- assert !user.valid?
19
- assert user.errors.on(:confirm_password)
20
- user.confirm_password = "awesome"
21
- assert user.valid?
22
- end
23
-
24
- def test_unique_token
25
- tokens = []
26
- 100.times { tokens << User.unique_token }
27
- assert_equal 100, tokens.uniq.size
28
- end
29
-
30
- def test_crypto_provider
31
- assert_equal Authlogic::Sha512CryptoProvider, User.crypto_provider
32
- end
33
-
34
- def test_forget_all
35
- bens_token = users(:ben).remember_token
36
- zacks_token = users(:zack).remember_token
37
- User.forget_all!
38
- assert_not_equal bens_token, users(:ben).reload.remember_token
39
- assert_not_equal zacks_token, users(:zack).reload.remember_token
40
- end
41
-
42
- def test_logged_in
43
- ben = users(:ben)
44
- assert !ben.logged_in?
45
- ben.update_attribute(:last_request_at, Time.now)
46
- assert ben.logged_in?
47
- end
48
-
49
- def test_password
50
- user = User.new
51
- user.password = "test"
52
- assert user.password_salt
53
- assert_equal User.crypto_provider.encrypt("test" + user.password_salt), user.crypted_password
54
- assert user.remember_token
55
- end
56
-
57
- def test_valid_password
58
- ben = users(:ben)
59
- assert ben.valid_password?("benrocks")
60
- assert ben.valid_password?(User.crypto_provider.encrypt("benrocks" + ben.password_salt))
61
- end
62
-
63
- def test_forget
64
- ben = users(:ben)
65
- token = ben.remember_token
66
- ben.forget!
67
- ben.reload
68
- assert_not_equal token, ben.remember_token
69
- end
70
-
71
- def test_randomize_password
72
- ben = users(:ben)
73
- crypted_password = ben.crypted_password
74
- password_salt = ben.password_salt
75
- ben.randomize_password!
76
- ben.reload
77
- assert_not_equal crypted_password, ben.crypted_password
78
- assert_not_equal password_salt, ben.password_salt
79
- end
80
- end