2011-03-11 5 views
5

OAuth 제공 업체 인 API를 작성 중입니다. rspec 테스트를 작성하는 데 권장되는 방법이 있습니까?oauth 공급자에 대한 Rspec 테스트

oauth를 활성화하여 모든 엔드 포인트를 보호 한 후에는 인증 단계를 통과하는 rspec 테스트를 어떻게 작성합니까?

답변

6

당신은 OAuth를하고 OAuth를-플러그인 보석을 사용하는 경우,이 게시물에 당신을 도울 수 있습니다 http://peachshake.com/2010/11/11/oauth-capybara-rspec-headers-and-a-lot-of-pain/

그러나

는 OAuth를-플러그인 보석은 당신이를 시뮬레이션하기 위해 도우미를 포함 일부 사양을 생성 인증 프로세스.

이 파일을 살펴 보자 귀하의 요청에 서명 https://github.com/pelle/oauth-plugin/blob/v0.4.0.pre4/lib/generators/rspec/templates/controller_spec_helper.rb

다음과 같은 방법을 사용할 수 있습니다 :

def sign_request_with_oauth(token=nil,options={}) 
    ActionController::TestRequest.use_oauth=true 
    @request.configure_oauth(current_consumer,token,options) 
end 

def two_legged_sign_request_with_oauth(consumer=nil,options={}) 
    ActionController::TestRequest.use_oauth=true 
    @request.configure_oauth(consumer,nil,options) 
end 

def add_oauth2_token_header(token,options={}) 
    request.env['HTTP_AUTHORIZATION'] = "OAuth #{token.token}" 
end 

을 당신이 당신의 사양을위한 도우미로이 파일을 복사하고 수정하는 것이 좋습니다 필요에 따라

관련 문제