Topic: Testing an action that uses http token authentication

I'm trying to test a controller that's using an http token authentication in the before filter. My problem is that it works ok wheh I use curl to pass the token, but in my tests it always fails (I'm using rspec btw). Tried a simple test to see if the token was being passed at all, but it seems like it's not doing so. Am I missing anything to get the test to actually pass the token to the controller?

Here's the code for the filter and test: http://pastebin.com/AWnRAR1e

Last edited by JoseMarmolejos (2012-08-20 14:06:54)

Re: Testing an action that uses http token authentication

I'm running into the exact same issue only using TestUnit functional tests.

http://pastie.org/4651272

via curl I pass:

-H "Authorization: Token token=\"ABCDEF0123456789\""

however in my controller I have tried all of the following to set this header without success:

@request.env['Authorization'] = 'Token token=\"ABCDEF0123456789\"'
@request.env['HTTP_AUTHORIZATION'] = "Token token=\"ABCDEF0123456789\""
@request.env['X-HTTP_AUTHORIZATION'] = "Token token=\"ABCDEF0123456789\""
@request.env['X_HTTP_AUTHORIZATION'] = "Token token=\"ABCDEF0123456789\""
@request.env['REDIRECT_X_HTTP_AUTHORIZATION'] = "Token token=\"ABCDEF0123456789\""
@request.env['HTTP_AUTHORIZATION'] = "Token token=\"ABCDEF0123456789\""

So far I have no solution to this problem as of yet.

Re: Testing an action that uses http token authentication

I got it working in my case.  So even though when using curl I passed the header as "Authorization: Token token=\"ABCDEF0123456789\""

To get it working from my controller test I had to set it this way:

@request.env['HTTP_AUTHORIZATION'] = 'Token token="ABCDEF0123456789"'