Methods
- A
- B
- D
- R
- S
- T
-
- test_authorization_header,
- test_authorization_header_explicitly_setting_password_but_no_username,
- test_authorization_header_explicitly_setting_username_and_password,
- test_authorization_header_explicitly_setting_username_but_no_password,
- test_authorization_header_if_credentials_supplied_and_auth_type_is_basic,
- test_authorization_header_if_credentials_supplied_and_auth_type_is_digest,
- test_authorization_header_with_decoded_credentials_from_url,
- test_authorization_header_with_password_but_no_username,
- test_authorization_header_with_query_string_if_auth_type_is_digest,
- test_authorization_header_with_username_but_no_password,
- test_client_nonce_is_not_nil,
- test_delete,
- test_delete_with_digest_auth_handles_initial_401_response_and_retries,
- test_get,
- test_get_with_digest_auth_caches_nonce,
- test_get_with_digest_auth_handles_initial_401_response_and_retries,
- test_head,
- test_head_with_digest_auth_handles_initial_401_response_and_retries,
- test_post,
- test_post_with_digest_auth_handles_initial_401_response_and_retries,
- test_put,
- test_put_with_digest_auth_handles_initial_401_response_and_retries,
- test_raises_invalid_request_on_unauthorized_requests,
- test_raises_invalid_request_on_unauthorized_requests_with_digest_auth,
- test_retry_on_401_only_happens_with_digest_auth
Constants
| Response | = | Struct.new(:code) |
Instance Public methods
setup()
Link
# File activeresource/test/cases/authorization_test.rb, line 7 def setup @conn = ActiveResource::Connection.new('http://localhost') @matz = { :person => { :id => 1, :name => 'Matz' } }.to_json @david = { :person => { :id => 2, :name => 'David' } }.to_json @authenticated_conn = ActiveResource::Connection.new("http://david:test123@localhost") @basic_authorization_request_header = { 'Authorization' => 'Basic ZGF2aWQ6dGVzdDEyMw==' } @nonce = "MTI0OTUxMzc4NzpjYWI3NDM3NDNmY2JmODU4ZjQ2ZjcwNGZkMTJiMjE0NA==" ActiveResource::HttpMock.respond_to do |mock| mock.get "/people/2.json", @basic_authorization_request_header, @david mock.get "/people/1.json", @basic_authorization_request_header, nil, 401, { 'WWW-Authenticate' => 'i_should_be_ignored' } mock.put "/people/2.json", @basic_authorization_request_header, nil, 204 mock.delete "/people/2.json", @basic_authorization_request_header, nil, 200 mock.post "/people/2/addresses.json", @basic_authorization_request_header, nil, 201, 'Location' => '/people/1/addresses/5' mock.head "/people/2.json", @basic_authorization_request_header, nil, 200 mock.get "/people/2.json", { 'Authorization' => blank_digest_auth_header("/people/2.json", "fad396f6a34aeba28e28b9b96ddbb671") }, nil, 401, { 'WWW-Authenticate' => response_digest_auth_header } mock.get "/people/2.json", { 'Authorization' => request_digest_auth_header("/people/2.json", "c064d5ba8891a25290c76c8c7d31fb7b") }, @david, 200 mock.get "/people/1.json", { 'Authorization' => request_digest_auth_header("/people/1.json", "f9c0b594257bb8422af4abd429c5bb70") }, @matz, 200 mock.put "/people/2.json", { 'Authorization' => blank_digest_auth_header("/people/2.json", "50a685d814f94665b9d160fbbaa3958a") }, nil, 401, { 'WWW-Authenticate' => response_digest_auth_header } mock.put "/people/2.json", { 'Authorization' => request_digest_auth_header("/people/2.json", "5a75cde841122d8e0f20f8fd1f98a743") }, nil, 204 mock.delete "/people/2.json", { 'Authorization' => blank_digest_auth_header("/people/2.json", "846f799107eab5ca4285b909ee299a33") }, nil, 401, { 'WWW-Authenticate' => response_digest_auth_header } mock.delete "/people/2.json", { 'Authorization' => request_digest_auth_header("/people/2.json", "9f5b155224edbbb69fd99d8ce094681e") }, nil, 200 mock.post "/people/2/addresses.json", { 'Authorization' => blank_digest_auth_header("/people/2/addresses.json", "6984d405ff3d9ed07bbf747dcf16afb0") }, nil, 401, { 'WWW-Authenticate' => response_digest_auth_header } mock.post "/people/2/addresses.json", { 'Authorization' => request_digest_auth_header("/people/2/addresses.json", "4bda6a28dbf930b5af9244073623bd04") }, nil, 201, 'Location' => '/people/1/addresses/5' mock.head "/people/2.json", { 'Authorization' => blank_digest_auth_header("/people/2.json", "15e5ed84ba5c4cfcd5c98a36c2e4f421") }, nil, 401, { 'WWW-Authenticate' => response_digest_auth_header } mock.head "/people/2.json", { 'Authorization' => request_digest_auth_header("/people/2.json", "d4c6d2bcc8717abb2e2ccb8c49ee6a91") }, nil, 200 end # Make client nonce deterministic class << @authenticated_conn private def client_nonce 'i-am-a-client-nonce' end end end
test_authorization_header_explicitly_setting_password_but_no_username()
Link
test_authorization_header_explicitly_setting_username_but_no_password()
Link
test_authorization_header_if_credentials_supplied_and_auth_type_is_basic()
Link
test_authorization_header_if_credentials_supplied_and_auth_type_is_digest()
Link
test_client_nonce_is_not_nil()
Link
test_delete()
Link
test_delete_with_digest_auth_handles_initial_401_response_and_retries()
Link
test_get()
Link
test_get_with_digest_auth_caches_nonce()
Link
# File activeresource/test/cases/authorization_test.rb, line 197 def test_get_with_digest_auth_caches_nonce @authenticated_conn.auth_type = :digest response = @authenticated_conn.get("/people/2.json") assert_equal "David", decode(response)["name"] # There is no mock for this request with a non-cached nonce. response = @authenticated_conn.get("/people/1.json") assert_equal "Matz", decode(response)["name"] end
test_get_with_digest_auth_handles_initial_401_response_and_retries()
Link
# File activeresource/test/cases/authorization_test.rb, line 166 def test_get_with_digest_auth_handles_initial_401_response_and_retries @authenticated_conn.auth_type = :digest response = @authenticated_conn.get("/people/2.json") assert_equal "David", decode(response)["name"] end
test_head()
Link
test_head_with_digest_auth_handles_initial_401_response_and_retries()
Link
test_post()
Link
test_post_with_digest_auth_handles_initial_401_response_and_retries()
Link
# File activeresource/test/cases/authorization_test.rb, line 172 def test_post_with_digest_auth_handles_initial_401_response_and_retries @authenticated_conn.auth_type = :digest response = @authenticated_conn.post("/people/2/addresses.json") assert_equal "/people/1/addresses/5", response["Location"] assert_equal 201, response.code end
test_put()
Link
test_put_with_digest_auth_handles_initial_401_response_and_retries()
Link
test_raises_invalid_request_on_unauthorized_requests_with_digest_auth()
Link
test_retry_on_401_only_happens_with_digest_auth()
Link
# File activeresource/test/cases/authorization_test.rb, line 207 def test_retry_on_401_only_happens_with_digest_auth assert_raise(ActiveResource::UnauthorizedAccess) { @authenticated_conn.get("/people/1.json") } assert_equal "", @authenticated_conn.send(:response_auth_header) end
Instance Protected methods
assert_response_raises(klass, code)
Link
blank_digest_auth_header(uri, response)
Link
decode(response)
Link
request_digest_auth_header(uri, response)
Link
# File activeresource/test/cases/authorization_test.rb, line 244 def request_digest_auth_header(uri, response) %Q(Digest username="david", realm="RailsTestApp", qop="auth", uri="#{uri}", nonce="#{@nonce}", nc="0", cnonce="i-am-a-client-nonce", opaque="ef6dfb078ba22298d366f99567814ffb", response="#{response}") end