Functional test for HTTP Basic Authentication in Rails 2
If you want to provide a username and password for a HTTP Basic Authentication in one of your functional tests, simply use the following:
def test_should_get_index
@request.env["HTTP_AUTHORIZATION"] = "Basic " + Base64::encode64("username:password")
get :index
assert_response :success
assert_not_nil assigns(:articles)
end
Keywords: rails test, functionals, authorization, basic http authentication, how to test
Filed under: English, Rails 2.0, Rails 2.1, Ruby, Ruby 1.8, Ruby On Rails on Juni 23rd, 2008
Thanks ….
I did it through this article …
Congrats ….
thanks a lot.. searched a lot and this is my favourite solution
I second Tim S. Saved me a lot of time.
Thanks for the info!
One additional suggestion: use ActionController::HttpAuthentication::Basic.encode_credentials. That way you don’t have to manually concatenate “Basic “, etc.
Details are here: http://tek-zappeln.blogspot.com/2009/04/rails-2-functional-tests-with-http.html
You’re a life saver! Thanks.
Thanks buddy I was looking for this.