11Nov
HTTP Basic Authentication for Functional Tests
0
While I was trying to cover a controller with some tests, I faced a problem. The controller actions were protected by a filter that prompted the users for login via basic http authentication. I found a solution in rails code here, where it said you should do your get as follows.
This didn't work for me where basic http authentication required sending the encoded credentials in the request headers, while the previous get request sent the authorization credentials in the session.
I found the following code snippet, which allowed for setting request headers:
class ActionController::TestRequest def set_header(name, value) @env[name] = value end end
In my tests, I now write the following:
And it works like a charm!
Written By:
Ahmed Sobhi (http://humanzz.spaces.live.com)
Post a Comment
eSpace podcast Prodcast
Archive
Latest Comments
- SpectraMind Commented on Egypt Wins UK's National Outsourcing Association Award
- Rofaida Awad Commented on Go Egypt Go!
- Different Mike Commented on Only idiots change their iPhone root password!
- Mike Commented on Only idiots change their iPhone root password!
- smile Commented on Only idiots change their iPhone root password!

