Sha256: c61a6a24d976cf4cfa05a287a7513ae29c143c1672274e8036e0951e1447a565

Contents?: true

Size: 1.43 KB

Versions: 4

Compression:

Stored size: 1.43 KB

Contents

require_relative '../test_helper'
require 'faraday/request/digest_authentication'

module Faraday
  describe Request::DigestAuth do
    let(:connection) do
      Faraday.new('http://api.example.org/') do |builder|
        builder.request :digest, 'USER', 'PASS'
        builder.adapter :net_http
      end
    end

    describe 'when the server does not return a 401' do
      it 'does nothing' do
        stub_request(:get, 'http://api.example.org/productions/1').
          to_return(status: 500, body: 'Foo body')

        response = connection.get('/productions/1')
        response.body.must_equal 'Foo body'
      end
    end

    describe 'when the server returns a 401' do
      let(:first_call_headers) { 'Digest realm="MyApp", algorithm=MD5' }
      let(:second_call_headers) { 'Digest username="USER", realm="MyApp", uri="/", algorithm="MD5"' }
      it 'authenticates using digest' do
        stub_request(:get, 'http://api.example.org/productions/1').
          with(body: nil).
          to_return(status: 401, headers: {'www-authenticate' => first_call_headers})

        stub_request(:get, 'http://api.example.org/productions/1').
          with(body: "{\"foo\":1}",
               headers: {'Authorization' => %r{second_call_headers}}).
               to_return(body: '{"resource": "This is the resource"}',
                         headers: {content_type: 'application/json'})

        connection.get('/productions/1')
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hyperclient-0.4.0 test/faraday/digest_authentication_test.rb
hyperclient-0.3.2 test/faraday/digest_authentication_test.rb
hyperclient-0.3.1 test/faraday/digest_authentication_test.rb
hyperclient-0.3.0 test/faraday/digest_authentication_test.rb