Thanks to this excellent question and answer, I have found out how I can protect my rails application by putting the following code in my application controller:
before_filter :authenticate
protected
def authenticate
authenticate_or_request_with_http_basic do |username, password|
username == "username" && password == "password"
end
end
This all works fine, but I noticed that all tests that I wrote (which all passed) now all fail. When I comment out the before_filter call, they all pass again.
How can I go about this? Is there a way to exclude the tests from the htaccess protection?
You can change your tests by including the Basic authentication, see this:
Source: http://flip.netzbeben.de/2008/06/functional-test-for-http-authentication-in-rails-2/