2011-07-25 12 views
2

私はRailsの機能テストでOAuthで署名されたリクエストを使用することで問題を解決しました。Rails機能テストとOAuthパラメータの問題

私は助けていただきたいと思います。

私はOAuthの宝石(0.4.5)であるActionControllerに建て:: TestRequestオーバーライドで動作するようにしようとしています。

私はすでに無駄にこのソリューションを試みたと思います:http://d.hatena.ne.jp/falkenhagen/20091110/1257830144

をこれは私が今やっていることです...

require 'oauth/client/action_controller_request' 

を、私はこれにログインを行うための方法を作成しましたOauthConsumerオブジェクト(ActiveRecord)とURLパラメータ(クエリ文字列)を渡すことができます。

def _do_oauth(consumer, params = {}) 
    c=OAuth::Consumer.new(consumer.consumer_key, consumer.consumer_secret) 
    t=OAuth::AccessToken.new(c) 
    ActionController::TestRequest.use_oauth=true 
    @request.configure_oauth(c, t, params) 
end 

と私のテストケースにそうようにそれを呼び出す:

params = { :store => 'foo' } 
_do_oauth(oauth_consumers(:one), params) # currently not working for passing params 
get :index, { :format => :json }.merge(params) 

しかし、要求は「のparams」を拾うか、適切にそれらをコードしているようにそれは見えません。

私は取得していますエラーが(上記の「取得」の行に発生する)である:

ArgumentError: comparison of Array with Array failed 
/home/sp/.rvm/gems/ruby-1.9.2-p180/gems/oauth-0.4.5/lib/oauth/helper.rb:37:in `sort' 
/home/sp/.rvm/gems/ruby-1.9.2-p180/gems/oauth-0.4.5/lib/oauth/helper.rb:37:in `normalize' 
/home/sp/.rvm/gems/ruby-1.9.2-p180/gems/oauth-0.4.5/lib/oauth/request_proxy/base.rb:98:in `normalized_parameters' 
/home/sp/.rvm/gems/ruby-1.9.2-p180/gems/oauth-0.4.5/lib/oauth/request_proxy/base.rb:113:in `signature_base_string' 
/home/sp/.rvm/gems/ruby-1.9.2-p180/gems/oauth-0.4.5/lib/oauth/signature/base.rb:77:in `signature_base_string' 
/home/sp/.rvm/gems/ruby-1.9.2-p180/gems/oauth-0.4.5/lib/oauth/signature/hmac/base.rb:12:in `digest' 
/home/sp/.rvm/gems/ruby-1.9.2-p180/gems/oauth-0.4.5/lib/oauth/signature/base.rb:65:in `signature' 
/home/sp/.rvm/gems/ruby-1.9.2-p180/gems/oauth-0.4.5/lib/oauth/signature.rb:23:in `sign' 
/home/sp/.rvm/gems/ruby-1.9.2-p180/gems/oauth-0.4.5/lib/oauth/client/helper.rb:45:in `signature' 
/home/sp/.rvm/gems/ruby-1.9.2-p180/gems/oauth-0.4.5/lib/oauth/client/helper.rb:75:in `header' 
/home/sp/.rvm/gems/ruby-1.9.2-p180/gems/oauth-0.4.5/lib/oauth/client/action_controller_request.rb:54:in `set_oauth_header' 
/home/sp/.rvm/gems/ruby-1.9.2-p180/gems/oauth-0.4.5/lib/oauth/client/action_controller_request.rb:50:in `apply_oauth!' 
/home/sp/.rvm/gems/ruby-1.9.2-p180/gems/oauth-0.4.5/lib/oauth/client/action_controller_request.rb:14:in `process_with_new_base_test' 
/home/sp/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/test_case.rb:412:in `process' 
/home/sp/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/test_case.rb:47:in `process' 
/home/sp/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/test_case.rb:350:in `get' 
test/functional/deals_controller_test.rb:56:in `block in <class:DealsControllerTest>' 

私はそれが正しくエンコードされていないクエリのparamsとは何かだと仮定すると、またはヘッダーよ適切にフォーマットされていません。どのような助け(または動作する例へのポインタ)も大いに感謝します。

また、私は、テストしようとしている問題のアプリが2本足のOAuthプロバイダーであることを指摘すべきです。だから、アプリは単に署名を解析し、消費者の鍵/秘密がチェックアウトすることを確認するだけです。

+0

paramsの順序が間違っていたときに問題が発生しました。多分助けになるかもしれない。ダニー。 – lzap

+0

はい、おそらくそうだと思います。私はそれを行うための「適切な」方法の例を見たいと思っています。 – stuffinq2010

+0

2足の認証されたコントローラで仕様を取得したことはありますか? – coneybeare

答えて

4

これはおそらくこの時点での最初の問題には役立ちませんが、数分の時間を節約する可能性があります。

問題は、ハッシュがシンボルと文字列のキーが混在していると、ハッシュのソート方法が不安定になることです。 Oauthは、文字列でキー入力されたエントリをparamsハッシュに追加します。

関連する問題