Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controller Specs Using 2-Legged OAuth fails #110

Open
coneybeare opened this issue Feb 5, 2012 · 2 comments
Open

Controller Specs Using 2-Legged OAuth fails #110

coneybeare opened this issue Feb 5, 2012 · 2 comments

Comments

@coneybeare
Copy link

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
Copy link
Author

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

@coneybeare
Copy link
Author

Please help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant