-
Website
http://jonathansng.com -
Original page
http://www.jonathansng.com/ruby-on-rails/testing-with-basic-http-authentication-in-rails-20/ -
Subscribe
All Comments -
Community
-
Top Commenters
-
Search Engine Optimization
1 comment · 1 points
-
Nik Bauman
1 comment · 1 points
-
zackmctee
1 comment · 1 points
-
srinathbtech
2 comments · 1 points
-
Quad Core Imac
1 comment · 1 points
-
-
Popular Threads
Take Care.
Hugues
I definitely spent too much time trying to figure this out...it's the simple things that are always a pain!
Regards
In case you're unfamiliar with testing Rails, this goes in test/test_helper.rb
The function above doesn't actually let you test HTTP Authentication. To do that you'll need to do something like:
def authenticate_with_http(username, password)
@request.env[”HTTP_AUTHORIZATION”] =
"Basic #{Base64.encode64("#{username}:#{password}")}"
end
Like unit testing you can do
def setup
http_auth
end
so all your test methods are authenticated.
ActionController::HttpAuthentication::Basic.encode_credentials('username', 'password')