authlogic 3.4.6 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE.md +13 -0
  3. data/.github/triage.md +87 -0
  4. data/.gitignore +4 -0
  5. data/.rubocop.yml +127 -0
  6. data/.rubocop_todo.yml +65 -0
  7. data/.travis.yml +18 -10
  8. data/CHANGELOG.md +156 -6
  9. data/CONTRIBUTING.md +71 -3
  10. data/Gemfile +2 -2
  11. data/README.md +386 -0
  12. data/Rakefile +13 -7
  13. data/UPGRADING.md +22 -0
  14. data/authlogic.gemspec +33 -22
  15. data/lib/authlogic.rb +60 -52
  16. data/lib/authlogic/acts_as_authentic/base.rb +40 -26
  17. data/lib/authlogic/acts_as_authentic/email.rb +96 -32
  18. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +36 -12
  19. data/lib/authlogic/acts_as_authentic/login.rb +114 -49
  20. data/lib/authlogic/acts_as_authentic/magic_columns.rb +17 -6
  21. data/lib/authlogic/acts_as_authentic/password.rb +296 -139
  22. data/lib/authlogic/acts_as_authentic/perishable_token.rb +34 -20
  23. data/lib/authlogic/acts_as_authentic/persistence_token.rb +20 -24
  24. data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +67 -0
  25. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +68 -23
  26. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +128 -85
  27. data/lib/authlogic/acts_as_authentic/single_access_token.rb +41 -25
  28. data/lib/authlogic/acts_as_authentic/validations_scope.rb +8 -8
  29. data/lib/authlogic/authenticates_many/association.rb +22 -14
  30. data/lib/authlogic/authenticates_many/base.rb +35 -16
  31. data/lib/authlogic/config.rb +10 -10
  32. data/lib/authlogic/controller_adapters/abstract_adapter.rb +40 -12
  33. data/lib/authlogic/controller_adapters/rack_adapter.rb +15 -8
  34. data/lib/authlogic/controller_adapters/rails_adapter.rb +42 -22
  35. data/lib/authlogic/controller_adapters/sinatra_adapter.rb +3 -3
  36. data/lib/authlogic/crypto_providers.rb +91 -0
  37. data/lib/authlogic/crypto_providers/aes256.rb +42 -14
  38. data/lib/authlogic/crypto_providers/bcrypt.rb +35 -20
  39. data/lib/authlogic/crypto_providers/md5.rb +11 -9
  40. data/lib/authlogic/crypto_providers/scrypt.rb +26 -13
  41. data/lib/authlogic/crypto_providers/sha1.rb +14 -8
  42. data/lib/authlogic/crypto_providers/sha256.rb +16 -12
  43. data/lib/authlogic/crypto_providers/sha512.rb +8 -24
  44. data/lib/authlogic/crypto_providers/wordpress.rb +44 -15
  45. data/lib/authlogic/i18n.rb +33 -20
  46. data/lib/authlogic/i18n/translator.rb +1 -1
  47. data/lib/authlogic/random.rb +12 -29
  48. data/lib/authlogic/regex.rb +59 -27
  49. data/lib/authlogic/session/activation.rb +36 -23
  50. data/lib/authlogic/session/active_record_trickery.rb +13 -10
  51. data/lib/authlogic/session/base.rb +20 -8
  52. data/lib/authlogic/session/brute_force_protection.rb +87 -56
  53. data/lib/authlogic/session/callbacks.rb +99 -49
  54. data/lib/authlogic/session/cookies.rb +128 -59
  55. data/lib/authlogic/session/existence.rb +29 -19
  56. data/lib/authlogic/session/foundation.rb +70 -16
  57. data/lib/authlogic/session/http_auth.rb +39 -31
  58. data/lib/authlogic/session/id.rb +27 -15
  59. data/lib/authlogic/session/klass.rb +17 -13
  60. data/lib/authlogic/session/magic_columns.rb +78 -59
  61. data/lib/authlogic/session/magic_states.rb +50 -27
  62. data/lib/authlogic/session/params.rb +79 -50
  63. data/lib/authlogic/session/password.rb +197 -118
  64. data/lib/authlogic/session/perishable_token.rb +12 -6
  65. data/lib/authlogic/session/persistence.rb +20 -14
  66. data/lib/authlogic/session/priority_record.rb +20 -16
  67. data/lib/authlogic/session/scopes.rb +63 -33
  68. data/lib/authlogic/session/session.rb +40 -25
  69. data/lib/authlogic/session/timeout.rb +51 -34
  70. data/lib/authlogic/session/unauthorized_record.rb +24 -18
  71. data/lib/authlogic/session/validation.rb +32 -21
  72. data/lib/authlogic/test_case.rb +123 -35
  73. data/lib/authlogic/test_case/mock_controller.rb +14 -13
  74. data/lib/authlogic/test_case/mock_cookie_jar.rb +14 -5
  75. data/lib/authlogic/test_case/mock_logger.rb +1 -1
  76. data/lib/authlogic/test_case/mock_request.rb +9 -4
  77. data/lib/authlogic/test_case/rails_request_adapter.rb +8 -7
  78. data/lib/authlogic/version.rb +21 -0
  79. data/test/acts_as_authentic_test/base_test.rb +1 -1
  80. data/test/acts_as_authentic_test/email_test.rb +80 -63
  81. data/test/acts_as_authentic_test/logged_in_status_test.rb +14 -8
  82. data/test/acts_as_authentic_test/login_test.rb +91 -49
  83. data/test/acts_as_authentic_test/magic_columns_test.rb +13 -13
  84. data/test/acts_as_authentic_test/password_test.rb +82 -60
  85. data/test/acts_as_authentic_test/perishable_token_test.rb +31 -25
  86. data/test/acts_as_authentic_test/persistence_token_test.rb +9 -5
  87. data/test/acts_as_authentic_test/restful_authentication_test.rb +18 -9
  88. data/test/acts_as_authentic_test/session_maintenance_test.rb +86 -22
  89. data/test/acts_as_authentic_test/single_access_test.rb +15 -15
  90. data/test/adapter_test.rb +21 -0
  91. data/test/authenticates_many_test.rb +26 -11
  92. data/test/config_test.rb +9 -9
  93. data/test/crypto_provider_test/aes256_test.rb +3 -3
  94. data/test/crypto_provider_test/bcrypt_test.rb +1 -1
  95. data/test/crypto_provider_test/scrypt_test.rb +2 -2
  96. data/test/crypto_provider_test/sha1_test.rb +4 -4
  97. data/test/crypto_provider_test/sha256_test.rb +2 -2
  98. data/test/crypto_provider_test/sha512_test.rb +3 -3
  99. data/test/crypto_provider_test/wordpress_test.rb +24 -0
  100. data/test/gemfiles/Gemfile.rails-4.2.x +2 -2
  101. data/test/gemfiles/Gemfile.rails-5.0.x +6 -0
  102. data/test/gemfiles/Gemfile.rails-5.1.x +6 -0
  103. data/test/gemfiles/Gemfile.rails-5.2.x +6 -0
  104. data/test/gemfiles/Gemfile.rails-master +6 -0
  105. data/test/i18n_test.rb +9 -9
  106. data/test/libs/affiliate.rb +2 -2
  107. data/test/libs/company.rb +4 -4
  108. data/test/libs/employee.rb +2 -2
  109. data/test/libs/employee_session.rb +1 -1
  110. data/test/libs/ldaper.rb +1 -1
  111. data/test/libs/project.rb +1 -1
  112. data/test/libs/user_session.rb +2 -2
  113. data/test/random_test.rb +9 -38
  114. data/test/session_test/activation_test.rb +7 -7
  115. data/test/session_test/active_record_trickery_test.rb +9 -6
  116. data/test/session_test/brute_force_protection_test.rb +26 -21
  117. data/test/session_test/callbacks_test.rb +10 -4
  118. data/test/session_test/cookies_test.rb +54 -20
  119. data/test/session_test/existence_test.rb +45 -23
  120. data/test/session_test/foundation_test.rb +17 -1
  121. data/test/session_test/http_auth_test.rb +11 -12
  122. data/test/session_test/id_test.rb +3 -3
  123. data/test/session_test/klass_test.rb +2 -2
  124. data/test/session_test/magic_columns_test.rb +15 -17
  125. data/test/session_test/magic_states_test.rb +17 -19
  126. data/test/session_test/params_test.rb +26 -20
  127. data/test/session_test/password_test.rb +11 -12
  128. data/test/session_test/perishability_test.rb +5 -5
  129. data/test/session_test/persistence_test.rb +4 -3
  130. data/test/session_test/scopes_test.rb +15 -9
  131. data/test/session_test/session_test.rb +7 -6
  132. data/test/session_test/timeout_test.rb +16 -14
  133. data/test/session_test/unauthorized_record_test.rb +3 -3
  134. data/test/session_test/validation_test.rb +5 -5
  135. data/test/test_helper.rb +115 -49
  136. metadata +107 -36
  137. data/README.rdoc +0 -232
  138. data/test/gemfiles/Gemfile.rails-3.2.x +0 -7
  139. data/test/gemfiles/Gemfile.rails-4.0.x +0 -7
  140. data/test/gemfiles/Gemfile.rails-4.1.x +0 -7
@@ -4,21 +4,26 @@ module Authlogic
4
4
  #
5
5
  # UserSession.create(my_user_object)
6
6
  #
7
- # Be careful with this, because Authlogic is assuming that you have already confirmed that the
8
- # user is who he says he is.
7
+ # Be careful with this, because Authlogic is assuming that you have already
8
+ # confirmed that the user is who he says he is.
9
9
  #
10
- # For example, this is the method used to persist the session internally. Authlogic finds the user with
11
- # the persistence token. At this point we know the user is who he says he is, so Authlogic just creates a
12
- # session with the record. This is particularly useful for 3rd party authentication methods, such as
13
- # OpenID. Let that method verify the identity, once it's verified, pass the object and create a session.
10
+ # For example, this is the method used to persist the session internally.
11
+ # Authlogic finds the user with the persistence token. At this point we know
12
+ # the user is who he says he is, so Authlogic just creates a session with
13
+ # the record. This is particularly useful for 3rd party authentication
14
+ # methods, such as OpenID. Let that method verify the identity, once it's
15
+ # verified, pass the object and create a session.
14
16
  module UnauthorizedRecord
15
17
  def self.included(klass)
16
18
  klass.class_eval do
17
19
  attr_accessor :unauthorized_record
18
- validate :validate_by_unauthorized_record, :if => :authenticating_with_unauthorized_record?
20
+ validate(
21
+ :validate_by_unauthorized_record,
22
+ if: :authenticating_with_unauthorized_record?
23
+ )
19
24
  end
20
25
  end
21
-
26
+
22
27
  # Returning meaningful credentials
23
28
  def credentials
24
29
  if authenticating_with_unauthorized_record?
@@ -29,22 +34,23 @@ module Authlogic
29
34
  super
30
35
  end
31
36
  end
32
-
37
+
33
38
  # Setting the unauthorized record if it exists in the credentials passed.
34
39
  def credentials=(value)
35
40
  super
36
41
  values = value.is_a?(Array) ? value : [value]
37
42
  self.unauthorized_record = values.first if values.first.class < ::ActiveRecord::Base
38
43
  end
39
-
44
+
40
45
  private
41
- def authenticating_with_unauthorized_record?
42
- !unauthorized_record.nil?
43
- end
44
-
45
- def validate_by_unauthorized_record
46
- self.attempted_record = unauthorized_record
47
- end
46
+
47
+ def authenticating_with_unauthorized_record?
48
+ !unauthorized_record.nil?
49
+ end
50
+
51
+ def validate_by_unauthorized_record
52
+ self.attempted_record = unauthorized_record
53
+ end
48
54
  end
49
55
  end
50
- end
56
+ end
@@ -2,7 +2,8 @@ module Authlogic
2
2
  module Session
3
3
  # Responsible for session validation
4
4
  module Validation
5
- # The errors in Authlogic work JUST LIKE ActiveRecord. In fact, it uses the exact same ActiveRecord errors class. Use it the same way:
5
+ # The errors in Authlogic work JUST LIKE ActiveRecord. In fact, it uses
6
+ # the exact same ActiveRecord errors class. Use it the same way:
6
7
  #
7
8
  # class UserSession
8
9
  # validate :check_if_awesome
@@ -21,21 +22,22 @@ module Authlogic
21
22
  end
22
23
  end
23
24
  end
24
-
25
- # You should use this as a place holder for any records that you find during validation. The main reason for this is to
26
- # allow other modules to use it if needed. Take the failed_login_count feature, it needs this in order to increase
27
- # the failed login count.
25
+
26
+ # You should use this as a place holder for any records that you find
27
+ # during validation. The main reason for this is to allow other modules to
28
+ # use it if needed. Take the failed_login_count feature, it needs this in
29
+ # order to increase the failed login count.
28
30
  def attempted_record
29
31
  @attempted_record
30
32
  end
31
-
33
+
32
34
  # See attempted_record
33
35
  def attempted_record=(value)
34
36
  @attempted_record = value
35
37
  end
36
-
37
- # The errors in Authlogic work JUST LIKE ActiveRecord. In fact, it uses the exact same ActiveRecord errors class.
38
- # Use it the same way:
38
+
39
+ # The errors in Authlogic work JUST LIKE ActiveRecord. In fact, it uses
40
+ # the exact same ActiveRecord errors class. Use it the same way:
39
41
  #
40
42
  # === Example
41
43
  #
@@ -51,32 +53,41 @@ module Authlogic
51
53
  def errors
52
54
  @errors ||= Errors.new(self)
53
55
  end
54
-
55
- # Determines if the information you provided for authentication is valid or not. If there is
56
- # a problem with the information provided errors will be added to the errors object and this
57
- # method will return false.
56
+
57
+ # Determines if the information you provided for authentication is valid
58
+ # or not. If there is a problem with the information provided errors will
59
+ # be added to the errors object and this method will return false.
58
60
  def valid?
59
61
  errors.clear
60
62
  self.attempted_record = nil
61
-
63
+
62
64
  before_validation
63
65
  new_session? ? before_validation_on_create : before_validation_on_update
64
66
  validate
65
67
  ensure_authentication_attempted
66
-
67
- if errors.size == 0
68
+
69
+ if errors.empty?
68
70
  new_session? ? after_validation_on_create : after_validation_on_update
69
71
  after_validation
70
72
  end
71
-
73
+
72
74
  save_record(attempted_record)
73
- errors.size == 0
75
+ errors.empty?
74
76
  end
75
-
77
+
76
78
  private
77
- def ensure_authentication_attempted
78
- errors.add(:base, I18n.t('error_messages.no_authentication_details', :default => "You did not provide any details for authentication.")) if errors.empty? && attempted_record.nil?
79
+
80
+ def ensure_authentication_attempted
81
+ if errors.empty? && attempted_record.nil?
82
+ errors.add(
83
+ :base,
84
+ I18n.t(
85
+ "error_messages.no_authentication_details",
86
+ default: "You did not provide any details for authentication."
87
+ )
88
+ )
79
89
  end
90
+ end
80
91
  end
81
92
  end
82
93
  end
@@ -5,8 +5,9 @@ require File.dirname(__FILE__) + "/test_case/mock_logger"
5
5
  require File.dirname(__FILE__) + "/test_case/mock_request"
6
6
 
7
7
  module Authlogic
8
- # This module is a collection of methods and classes that help you easily test Authlogic. In fact,
9
- # I use these same tools to test the internals of Authlogic.
8
+ # This module is a collection of methods and classes that help you easily test
9
+ # Authlogic. In fact, I use these same tools to test the internals of
10
+ # Authlogic.
10
11
  #
11
12
  # === The quick and dirty
12
13
  #
@@ -18,72 +19,88 @@ module Authlogic
18
19
  #
19
20
  # === Setting up
20
21
  #
21
- # Authlogic comes with some simple testing tools. To get these, you need to first require Authlogic's TestCase. If
22
- # you are doing this in a rails app, you would require this file at the top of your test_helper.rb file:
22
+ # Authlogic comes with some simple testing tools. To get these, you need to
23
+ # first require Authlogic's TestCase. If you are doing this in a rails app,
24
+ # you would require this file at the top of your test_helper.rb file:
23
25
  #
24
26
  # require "authlogic/test_case"
25
27
  #
26
- # If you are using Test::Unit::TestCase, the standard testing library that comes with ruby, then you can skip this next part.
27
- # If you are not, you need to include the Authlogic::TestCase into your testing suite as follows:
28
+ # If you are using Test::Unit::TestCase, the standard testing library that
29
+ # comes with ruby, then you can skip this next part. If you are not, you need
30
+ # to include the Authlogic::TestCase into your testing suite as follows:
28
31
  #
29
32
  # include Authlogic::TestCase
30
33
  #
31
- # Now that everything is ready to go, let's move onto actually testing. Here is the basic idea behind testing:
34
+ # Now that everything is ready to go, let's move onto actually testing. Here
35
+ # is the basic idea behind testing:
32
36
  #
33
- # Authlogic requires a "connection" to your controller to activate it. In the same manner that ActiveRecord requires a connection to
34
- # your database. It can't do anything until it gets connnected. That being said, Authlogic will raise an
35
- # Authlogic::Session::Activation::NotActivatedError any time you try to instantiate an object without a "connection".
36
- # So before you do anything with Authlogic, you need to activate / connect Authlogic. Let's walk through how to do this in tests:
37
+ # Authlogic requires a "connection" to your controller to activate it. In the
38
+ # same manner that ActiveRecord requires a connection to your database. It
39
+ # can't do anything until it gets connected. That being said, Authlogic will
40
+ # raise an Authlogic::Session::Activation::NotActivatedError any time you try
41
+ # to instantiate an object without a "connection". So before you do anything
42
+ # with Authlogic, you need to activate / connect Authlogic. Let's walk through
43
+ # how to do this in tests:
37
44
  #
38
45
  # === Fixtures / Factories
39
46
  #
40
- # Creating users via fixtures / factories is easy. Here's an example of a fixture:
47
+ # Creating users via fixtures / factories is easy. Here's an example of a
48
+ # fixture:
41
49
  #
42
50
  # ben:
43
51
  # email: whatever@whatever.com
44
52
  # password_salt: <%= salt = Authlogic::Random.hex_token %>
45
- # crypted_password: <%= Authlogic::CryptoProviders::Sha512.encrypt("benrocks" + salt) %>
53
+ # crypted_password: <%= Authlogic::CryptoProviders::SCrypt.encrypt("benrocks" + salt) %>
46
54
  # persistence_token: <%= Authlogic::Random.hex_token %>
47
55
  # single_access_token: <%= Authlogic::Random.friendly_token %>
48
56
  # perishable_token: <%= Authlogic::Random.friendly_token %>
49
57
  #
50
- # Notice the crypted_password value. Just supplement that with whatever crypto provider you are using, if you are not using the default.
58
+ # Notice the crypted_password value. Just supplement that with whatever crypto
59
+ # provider you are using, if you are not using the default.
51
60
  #
52
61
  # === Functional tests
53
62
  #
54
- # Activating Authlogic isn't a problem here, because making a request will activate Authlogic for you. The problem is
55
- # logging users in so they can access restricted areas. Solving this is simple, just do this:
63
+ # Activating Authlogic isn't a problem here, because making a request will
64
+ # activate Authlogic for you. The problem is logging users in so they can
65
+ # access restricted areas. Solving this is simple, just do this:
56
66
  #
57
67
  # setup :activate_authlogic
58
68
  #
59
- # For those of you unfamiliar with TestUnit, the setup method basically just executes a method before any test is ran.
60
- # It is essentially "setting up" your tests.
69
+ # For those of you unfamiliar with TestUnit, the setup method basically just
70
+ # executes a method before any test is ran. It is essentially "setting up"
71
+ # your tests.
61
72
  #
62
73
  # Once you have done this, just log users in like usual:
63
74
  #
64
75
  # UserSession.create(users(:whomever))
65
76
  # # access my restricted area here
66
77
  #
67
- # Do this before you make your request and it will act as if that user is logged in.
78
+ # Do this before you make your request and it will act as if that user is
79
+ # logged in.
68
80
  #
69
81
  # === Integration tests
70
82
  #
71
- # Again, just like functional tests, you don't have to do anything. As soon as you make a request, Authlogic will be
72
- # connected. If you want to activate Authlogic before making a request follow the same steps described in the
83
+ # Again, just like functional tests, you don't have to do anything. As soon as
84
+ # you make a request, Authlogic will be connected. If you want to activate
85
+ # Authlogic before making a request follow the same steps described in the
73
86
  # "functional tests" section above. It works in the same manner.
74
87
  #
75
88
  # === Unit tests
76
89
  #
77
- # The only time you need to do any trickiness here is if you want to test Authlogic models. Maybe you added some custom
78
- # code or methods in your Authlogic models. Maybe you are writing a plugin or a library that extends Authlogic.
90
+ # The only time you need to do any trickiness here is if you want to test
91
+ # Authlogic models. Maybe you added some custom code or methods in your
92
+ # Authlogic models. Maybe you are writing a plugin or a library that extends
93
+ # Authlogic.
79
94
  #
80
- # That being said, in this environment there is no controller. So you need to use a "mock" controller. Something
81
- # that looks like a controller, acts like a controller, but isn't a "real" controller. You are essentially connecting
82
- # Authlogic to your "mock" controller, then you can test off of the mock controller to make sure everything is functioning
83
- # properly.
95
+ # That being said, in this environment there is no controller. So you need to
96
+ # use a "mock" controller. Something that looks like a controller, acts like a
97
+ # controller, but isn't a "real" controller. You are essentially connecting
98
+ # Authlogic to your "mock" controller, then you can test off of the mock
99
+ # controller to make sure everything is functioning properly.
84
100
  #
85
- # I use a mock controller to test Authlogic myself. It's part of the Authlogic library that you can easily use. It's as simple
86
- # as functional and integration tests. Just do the following:
101
+ # I use a mock controller to test Authlogic myself. It's part of the Authlogic
102
+ # library that you can easily use. It's as simple as functional and
103
+ # integration tests. Just do the following:
87
104
  #
88
105
  # setup :activate_authlogic
89
106
  #
@@ -94,23 +111,94 @@ module Authlogic
94
111
  # assert UserSession.create(ben)
95
112
  # assert_equal controller.session["user_credentials"], ben.persistence_token
96
113
  #
97
- # See how I am checking that Authlogic is interacting with the controller properly? That's the idea here.
114
+ # See how I am checking that Authlogic is interacting with the controller
115
+ # properly? That's the idea here.
116
+ #
117
+ # === Testing with Rails 5
118
+ #
119
+ # Rails 5 has [deprecated classic controller tests](https://goo.gl/4zmt6y).
120
+ # Controller tests now inherit from `ActionDispatch::IntegrationTest` making
121
+ # them plain old integration tests now. You have two options for testing
122
+ # AuthLogic in Rails 5:
123
+ #
124
+ # * Add the `rails-controller-testing` gem to bring back the original
125
+ # controller testing usage
126
+ # * Go full steam ahead with integration testing and actually log a user in
127
+ # by submitting a form in the integration test.
128
+ #
129
+ # Naturally DHH recommends the second method and this is
130
+ # [what he does in his own tests](https://goo.gl/Ar6p0u). This is useful
131
+ # for testing not only AuthLogic itself (submitting login credentials to a
132
+ # UserSessionsController, for example) but any controller action that is
133
+ # behind a login wall. Add a helper method and use that before testing your
134
+ # actual controller action:
135
+ #
136
+ # # test/test_helper.rb
137
+ # def login(user)
138
+ # post user_sessions_url, :params => { :email => user.email, :password => 'password' }
139
+ # end
140
+ #
141
+ # # test/controllers/posts_controller_test.rb
142
+ # test "#create requires a user to be logged in
143
+ # post posts_url, :params => { :body => 'Lorem ipsum' }
144
+ #
145
+ # assert_redirected_to new_user_session_url
146
+ # end
147
+ #
148
+ # test "#create lets a logged in user create a new post" do
149
+ # login(users(:admin))
150
+ #
151
+ # assert_difference 'Posts.count' do
152
+ # post posts_url, :params => { :body => 'Lorem ipsum' }
153
+ # end
154
+ #
155
+ # assert_redirected_to posts_url
156
+ # end
157
+ #
158
+ # You still have access to the `session` helper in an integration test and so
159
+ # you can still test to see if a user is logged in. A couple of helper methods
160
+ # might look like:
161
+ #
162
+ # # test/test_helper.rb
163
+ # def assert_logged_in
164
+ # assert session[:user_credentials].present?
165
+ # end
166
+ #
167
+ # def assert_not_logged_in
168
+ # assert session[:user_credentials].blank?
169
+ # end
170
+ #
171
+ # # test/user_sessions_controller_test.rb
172
+ # test "#create logs in a user" do
173
+ # login(users(:admin))
174
+ #
175
+ # assert_logged_in
176
+ # end
98
177
  module TestCase
99
- # Activates authlogic so that you can use it in your tests. You should call this method in your test's setup. Ex:
178
+ def initialize(*args)
179
+ @request = nil
180
+ super
181
+ end
182
+
183
+ # Activates authlogic so that you can use it in your tests. You should call
184
+ # this method in your test's setup. Ex:
100
185
  #
101
186
  # setup :activate_authlogic
102
187
  def activate_authlogic
103
- if @request && ! @request.respond_to?(:params)
188
+ if @request && !@request.respond_to?(:params)
104
189
  class <<@request
105
190
  alias_method :params, :parameters
106
191
  end
107
192
  end
108
193
 
109
- Authlogic::Session::Base.controller = (@request && Authlogic::TestCase::RailsRequestAdapter.new(@request)) || controller
194
+ Authlogic::Session::Base.controller = @request &&
195
+ Authlogic::TestCase::RailsRequestAdapter.new(@request) ||
196
+ controller
110
197
  end
111
198
 
112
- # The Authlogic::TestCase::MockController object passed to Authlogic to activate it. You can access this in your test.
113
- # See the module description for an example.
199
+ # The Authlogic::TestCase::MockController object passed to Authlogic to
200
+ # activate it. You can access this in your test. See the module description
201
+ # for an example.
114
202
  def controller
115
203
  @controller ||= Authlogic::TestCase::MockController.new
116
204
  end
@@ -1,19 +1,20 @@
1
1
  module Authlogic
2
2
  module TestCase
3
- # Basically acts like a controller but doesn't do anything. Authlogic can interact with this, do it's thing and then you
4
- # can look at the controller object to see if anything changed.
3
+ # Basically acts like a controller but doesn't do anything. Authlogic can interact
4
+ # with this, do it's thing and then you can look at the controller object to see if
5
+ # anything changed.
5
6
  class MockController < ControllerAdapters::AbstractAdapter
6
7
  attr_accessor :http_user, :http_password, :realm
7
8
  attr_writer :request_content_type
8
-
9
+
9
10
  def initialize
10
11
  end
11
-
12
- def authenticate_with_http_basic(&block)
12
+
13
+ def authenticate_with_http_basic
13
14
  yield http_user, http_password
14
15
  end
15
-
16
- def authenticate_or_request_with_http_basic(realm = 'DefaultRealm', &block)
16
+
17
+ def authenticate_or_request_with_http_basic(realm = "DefaultRealm")
17
18
  self.realm = realm
18
19
  @http_auth_requested = true
19
20
  yield http_user, http_password
@@ -22,27 +23,27 @@ module Authlogic
22
23
  def cookies
23
24
  @cookies ||= MockCookieJar.new
24
25
  end
25
-
26
+
26
27
  def cookie_domain
27
28
  nil
28
29
  end
29
-
30
+
30
31
  def logger
31
32
  @logger ||= MockLogger.new
32
33
  end
33
-
34
+
34
35
  def params
35
36
  @params ||= {}
36
37
  end
37
-
38
+
38
39
  def request
39
40
  @request ||= MockRequest.new(controller)
40
41
  end
41
-
42
+
42
43
  def request_content_type
43
44
  @request_content_type ||= "text/html"
44
45
  end
45
-
46
+
46
47
  def session
47
48
  @session ||= {}
48
49
  end