spec/lib/connection_spec.rb in flexirest-1.3.14 vs spec/lib/connection_spec.rb in flexirest-1.3.15

- old
+ new

@@ -109,11 +109,11 @@ context 'with custom timeouts' do it 'should set a custom timeout' do stub_request(:get, "www.example.com/foo") .to_return(body: "{result:true}") - expect_any_instance_of(Flexirest::Connection).to receive(:set_per_request_timeout) + expect_any_instance_of(Flexirest::Connection).to receive(:set_per_request_timeout).and_call_original @connection.get("/foo", {:timeout => "5"}) end end context 'with api auth signing requests' do @@ -122,11 +122,12 @@ Flexirest::Base.api_auth_credentials('id123', 'secret123') @options = { :api_auth => { :api_auth_access_id => 'id123', - :api_auth_secret_key => 'secret123' + :api_auth_secret_key => 'secret123', + :api_auth_options => {} } } @default_headers = {'Date' => 'Sat, 14 Mar 2015 15:13:24 GMT'} @@ -140,10 +141,40 @@ it 'should have an Authorization header' do stub_request(:get, "www.example.com/foo") .with(:headers => @default_headers) .to_return(body: "{result:true}") result = @connection.get("/foo", @options) - expect(result.env.request_headers['Authorization']).to eq("APIAuth id123:PMWBThkB8vKbvUccHvoqu9G3eVk=") + auth_header = result.env.request_headers['Authorization'] + expect(auth_header == "APIAuth id123:TQiQIW6vVaDC5jvh99uTNkxIg6Q=" || auth_header == "APIAuth id123:PMWBThkB8vKbvUccHvoqu9G3eVk=").to be_truthy + end + + if Gem.loaded_specs["api-auth"].version.to_s >= "2.0.0" + it 'should have an Authorization header with a custom digest method' do + puts Gem.loaded_specs["api-auth"].version + @options[:api_auth][:api_auth_options] = { + digest: "sha256" + } + stub_request(:get, "www.example.com/foo") + .with(:headers => @default_headers) + .to_return(body: "{result:true}") + result = @connection.get("/foo", @options) + expect(result.env.request_headers['Authorization']).to eq("APIAuth-HMAC-SHA256 id123:fDrJfQ1fOoPFHtzhqqdHby+v6bbn2K8b2HR5AKo3vmg=") + end + end + + it "should warn about using custom digest methods with an Authorization header if ApiAuth doesn't support it" do + @options[:api_auth][:api_auth_options] = { + digest: "sha256" + } + stub_request(:get, "www.example.com/foo") + .with(:headers => @default_headers) + .to_return(body: "{result:true}") + expect(ApiAuth).to receive(:sign!).once.with(anything, anything, anything, {digest: "sha256"}).and_raise(ArgumentError) + expect(ApiAuth).to receive(:sign!).once.with(anything, anything, anything).and_call_original + expect(Flexirest::Logger).to receive(:warn) + result = @connection.get("/foo", @options) + auth_header = result.env.request_headers['Authorization'] + expect(auth_header == "APIAuth id123:TQiQIW6vVaDC5jvh99uTNkxIg6Q=" || auth_header == "APIAuth id123:PMWBThkB8vKbvUccHvoqu9G3eVk=").to be_truthy end it 'should have an Content-MD5 header' do stub_request(:put, "www.example.com/foo"). with(body: "body", :headers => @default_headers).