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

2 Responses to “Functional test for HTTP Basic Authentication in Rails 2”

  1. Thanks ….

    I did it through this article …

    Congrats ….

  2. thanks a lot.. searched a lot and this is my favourite solution :)

Leave a Reply


linkboost