pelle/oauth-plugin — Issue #110: Controller Specs Using 2-Legged OAuth fails
Author: coneybeare
Created: 2012-02-05 16:39:33+00:00
State: open

I can make a request via `rails console` fine, so I know the app has been implemented correctly. When using the provided helper methods to sign the simple get request in the controller spec, the request does not appear to be signed correctly. Am I doing something wrong?

The successful console call:

````ruby
coneybeare $ rails c test
Loading test environment (Rails 3.2.0)
rails test: main
>> consumer = OAuth::Consumer.new("one_key", "MyString", :site => [REDACTED])
# => #"HMAC-SHA1", :request_token_path=>"/oauth/request_token", :authorize_path=>"/oauth/authorize", :access_token_path=>"/oauth/access_token", :proxy=>nil, :scheme=>:header, :http_method=>:post, :oauth_version=>"1.0", :site=>[REDACTED]}>

rails test: main
>> access_token = OAuth::AccessToken.new consumer
# => #"HMAC-SHA1", :request_token_path=>"/oauth/request_token", :authorize_path=>"/oauth/authorize", :access_token_path=>"/oauth/access_token", :proxy=>nil, :scheme=>:header, :http_method=>:post, :oauth_version=>"1.0", :site=>[REDACTED]}>, @params={}>

rails test: main
>> r = access_token.get("/api/v1/users.json")
# => #

rails test: main
>> puts r.body
{"users":[{"id":206669143},{"id":358143215}]}
# => nil
````

The failed controller test:

````ruby
it "responds as success with a valid oath signature" do
consumer = OAuth::Consumer.new("one_key", "MyString", :site => [REDACTED])
two_legged_sign_request_with_oauth(consumer)
get :index, {:api_version => 'v1', :format => :json}
response.should be_success
end
````

````bash
coneybeare $ rspec spec/controllers/client_applications_controller_spec.rb --fail-fast; echo "==================================="; tail -6 log/test.log
````

````bash
1) Api::ClientApplicationsController GET index responds as success with a valid oath signature
Failure/Error: response.should be_success
expected success? to return true, got false
# ./spec/controllers/client_applications_controller_spec.rb:53:in `block (3 levels) in '

===================================

Processing by Api::ClientApplicationsController#index as JSON
Parameters: {"api_version"=>1}
Rendered text template (0.0ms)
Filter chain halted as #false, :strategies=>:two_legged}, @strategies=[:two_legged]> rendered or redirected
Completed 401 Unauthorized in 15ms (Views: 13.9ms | ActiveRecord: 0.0ms)
(0.2ms) ROLLBACK
coneybeare $
````

My versions are:

````bash
coneybeare $ bundle show oath
/path/redacted/gems/oauth-0.4.5
coneybeare $ bundle show oauth-plugin
/path/redacted/gems/oauth-plugin-0.4.0.rc2
````

Is this a bug? If not, can anybody point me in the right direction for testing controllers that are `oauthenticated` with a 2-legged approach?