Search code examples
rubymerbmerb-auth

Testing basic HTTP authenticated request in Merb


The Merb Open Source Book has a chapter on authentication. However, the testing an authenticated request section example only shows what you can do for forms based authentication. I have a web service that I want to test with HTTP basic authentication. How would I do that?


Solution

  • After posting my question, I tried a few more things and found my own answer. You can do something like the following:

    response = request('/widgets/2222', 
                       :method => "GET", 
                       "X_HTTP_AUTHORIZATION" => 'Basic ' + ["myusername:mypassword"].pack('m').delete("\r\n"))
    

    I may get around to updating the book, but at least this info is here for Google to find and possibly help someone else.