Welcome Guest | Login

Testing with request headers

Hi.  I'm using HTTP Basic auth for some of my REST interfaces, so I
want to run tests setting the HTTP AUTHORIZATION header.  But I can't
find a way to do it in the functional test.  I can see the response
headers in @response.headers, but there's no analogous hash in
@request.

Any hints?

Also, I can't find any API documentation for
ActionController::TestRequest -- anybody know where that's hiding?

2007-04-06 03:41 PM

Fantastic question - I'm not sure - take a look at
http://api.rubyonrails.org/classes/ActionController/AbstractRequest.htmlhttp://caboo.se/doc/classes/ActionController/TestRequest.html

and you might get some hints following the rabbit trails through
http://dev.rubyonrails.org/ticket/7372

~William



2007-04-06 05:15 PM

Thanks, William.  The source for the accept method of TestRequest (at the caboo.se site) gave me what I needed.  I case somebody else needs this, I added

class ActionController::TestRequest 
 def set_header(name, value)
   @env[name] = value
 end
end
to the functional test call.  Then, for my needs a simple call to

@request.set_header "HTTP_AUTHORIZATION", "Basic " + Base64.encode64('test@collabomatic.com:testpass')
added the header I needed.  Test passed.

Thanks!

2007-04-07 11:39 AM


Hello Guest! In order to post you must be an active client with us, please log in or sign up today!