pelle / oauth-plugin

Rails plugin for OAuth
http://stakeventures.com/articles/2009/07/21/consuming-oauth-intelligently-in-rails
MIT License
716 stars 216 forks source link

Controller Specs Using 2-Legged OAuth fails #110

Open coneybeare opened 12 years ago

coneybeare commented 12 years ago

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:

coneybeare $ rails c test
Loading test environment (Rails 3.2.0)
rails test: main 
>> consumer = OAuth::Consumer.new("one_key", "MyString", :site => [REDACTED])
# => #<OAuth::Consumer:0x007f9d01252268 @key="one_key", @secret="MyString", @options={:signature_method=>"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]}>  

ruby: main 
>> req = consumer.create_signed_request(:get, "/api/v1/users.json", nil)
# => #<Net::HTTP::Get GET>  

ruby: main 
>> res = Net::HTTP.start([REDACTED]) {|http| http.request(req) }
# => #<Net::HTTPOK 200 OK readbody=true>  

ruby: main 
>> puts res.body
{"users":[{"id":206669143},{"id":358143215}]}
# => nil  

The failed controller test:

    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
coneybeare $ rspec spec/controllers/client_applications_controller_spec.rb --fail-fast; echo "==================================="; tail -6 log/test.log 
  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 <top (required)>'

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

Processing by Api::ClientApplicationsController#index as JSON
  Parameters: {"api_version"=>1}
  Rendered text template (0.0ms)
Filter chain halted as #<OAuth::Controllers::ApplicationControllerMethods::Filter:0x007f9dfd9b2420 @options={:interactive=>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:

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?

coneybeare commented 12 years ago

There is a SO question about this with a bounty... any help is much appreciated. I just want to run my controller tests :/

coneybeare commented 12 years ago

Please help