diff --git a/lib/api_auth/headers.rb b/lib/api_auth/headers.rb index 5ec0d42e..6504708b 100644 --- a/lib/api_auth/headers.rb +++ b/lib/api_auth/headers.rb @@ -67,15 +67,15 @@ def authorization_header end def set_date - @request.set_date if @request.timestamp.empty? + @request.set_date if @request.timestamp.nil? end def calculate_md5 - @request.populate_content_md5 if @request.content_md5.empty? + @request.populate_content_md5 if @request.content_md5.nil? end def md5_mismatch? - if @request.content_md5.empty? + if @request.content_md5.nil? false else @request.md5_mismatch? diff --git a/lib/api_auth/request_drivers/action_controller.rb b/lib/api_auth/request_drivers/action_controller.rb index 458c7372..62563ea9 100644 --- a/lib/api_auth/request_drivers/action_controller.rb +++ b/lib/api_auth/request_drivers/action_controller.rb @@ -43,13 +43,11 @@ def http_method end def content_type - value = find_header(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE]) - value.nil? ? '' : value + find_header(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE]) end def content_md5 - value = find_header(%w[CONTENT-MD5 CONTENT_MD5 HTTP_CONTENT_MD5]) - value.nil? ? '' : value + find_header(%w[CONTENT-MD5 CONTENT_MD5 HTTP_CONTENT_MD5]) end def original_uri @@ -66,8 +64,7 @@ def set_date end def timestamp - value = find_header(%w[DATE HTTP_DATE]) - value.nil? ? '' : value + find_header(%w[DATE HTTP_DATE]) end def authorization_header diff --git a/lib/api_auth/request_drivers/curb.rb b/lib/api_auth/request_drivers/curb.rb index 2be6c100..af049eae 100644 --- a/lib/api_auth/request_drivers/curb.rb +++ b/lib/api_auth/request_drivers/curb.rb @@ -32,13 +32,11 @@ def http_method end def content_type - value = find_header(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE]) - value.nil? ? '' : value + find_header(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE]) end def content_md5 - value = find_header(%w[CONTENT-MD5 CONTENT_MD5]) - value.nil? ? '' : value + find_header(%w[CONTENT-MD5 CONTENT_MD5]) end def original_uri @@ -55,8 +53,7 @@ def set_date end def timestamp - value = find_header(%w[DATE HTTP_DATE]) - value.nil? ? '' : value + find_header(%w[DATE HTTP_DATE]) end def authorization_header diff --git a/lib/api_auth/request_drivers/faraday.rb b/lib/api_auth/request_drivers/faraday.rb index dc6960a9..d4cb9077 100644 --- a/lib/api_auth/request_drivers/faraday.rb +++ b/lib/api_auth/request_drivers/faraday.rb @@ -43,13 +43,11 @@ def http_method end def content_type - value = find_header(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE]) - value.nil? ? '' : value + find_header(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE]) end def content_md5 - value = find_header(%w[CONTENT-MD5 CONTENT_MD5 HTTP-CONTENT-MD5 HTTP_CONTENT_MD5]) - value.nil? ? '' : value + find_header(%w[CONTENT-MD5 CONTENT_MD5 HTTP-CONTENT-MD5 HTTP_CONTENT_MD5]) end def original_uri @@ -69,8 +67,7 @@ def set_date end def timestamp - value = find_header(%w[DATE HTTP_DATE]) - value.nil? ? '' : value + find_header(%w[DATE HTTP_DATE]) end def authorization_header diff --git a/lib/api_auth/request_drivers/httpi.rb b/lib/api_auth/request_drivers/httpi.rb index 1ffcfc91..4543cc2e 100644 --- a/lib/api_auth/request_drivers/httpi.rb +++ b/lib/api_auth/request_drivers/httpi.rb @@ -42,13 +42,11 @@ def http_method end def content_type - value = find_header(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE]) - value.nil? ? '' : value + find_header(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE]) end def content_md5 - value = find_header(%w[CONTENT-MD5 CONTENT_MD5]) - value.nil? ? '' : value + find_header(%w[CONTENT-MD5 CONTENT_MD5]) end def original_uri @@ -65,8 +63,7 @@ def set_date end def timestamp - value = find_header(%w[DATE HTTP_DATE]) - value.nil? ? '' : value + find_header(%w[DATE HTTP_DATE]) end def authorization_header diff --git a/lib/api_auth/request_drivers/net_http.rb b/lib/api_auth/request_drivers/net_http.rb index 4d301bfa..4b5d3865 100644 --- a/lib/api_auth/request_drivers/net_http.rb +++ b/lib/api_auth/request_drivers/net_http.rb @@ -49,13 +49,11 @@ def http_method end def content_type - value = find_header(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE]) - value.nil? ? '' : value + find_header(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE]) end def content_md5 - value = find_header(%w[CONTENT-MD5 CONTENT_MD5]) - value.nil? ? '' : value + find_header(%w[CONTENT-MD5 CONTENT_MD5]) end def original_uri @@ -71,8 +69,7 @@ def set_date end def timestamp - value = find_header(%w[DATE HTTP_DATE]) - value.nil? ? '' : value + find_header(%w[DATE HTTP_DATE]) end def authorization_header diff --git a/lib/api_auth/request_drivers/rack.rb b/lib/api_auth/request_drivers/rack.rb index c31f98a7..2ee4554a 100644 --- a/lib/api_auth/request_drivers/rack.rb +++ b/lib/api_auth/request_drivers/rack.rb @@ -48,13 +48,11 @@ def http_method end def content_type - value = find_header(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE]) - value.nil? ? '' : value + find_header(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE]) end def content_md5 - value = find_header(%w[CONTENT-MD5 CONTENT_MD5 HTTP-CONTENT-MD5 HTTP_CONTENT_MD5]) - value.nil? ? '' : value + find_header(%w[CONTENT-MD5 CONTENT_MD5 HTTP-CONTENT-MD5 HTTP_CONTENT_MD5]) end def original_uri @@ -71,8 +69,7 @@ def set_date end def timestamp - value = find_header(%w[DATE HTTP_DATE]) - value.nil? ? '' : value + find_header(%w[DATE HTTP_DATE]) end def authorization_header diff --git a/lib/api_auth/request_drivers/rest_client.rb b/lib/api_auth/request_drivers/rest_client.rb index 977a437c..cf7870d4 100644 --- a/lib/api_auth/request_drivers/rest_client.rb +++ b/lib/api_auth/request_drivers/rest_client.rb @@ -51,13 +51,11 @@ def http_method end def content_type - value = find_header(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE]) - value.nil? ? '' : value + find_header(%w[CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE]) end def content_md5 - value = find_header(%w[CONTENT-MD5 CONTENT_MD5]) - value.nil? ? '' : value + find_header(%w[CONTENT-MD5 CONTENT_MD5]) end def original_uri @@ -74,8 +72,7 @@ def set_date end def timestamp - value = find_header(%w[DATE HTTP_DATE]) - value.nil? ? '' : value + find_header(%w[DATE HTTP_DATE]) end def authorization_header diff --git a/spec/headers_spec.rb b/spec/headers_spec.rb index c352f253..4fbc50b4 100644 --- a/spec/headers_spec.rb +++ b/spec/headers_spec.rb @@ -188,14 +188,14 @@ context 'when request has no md5' do it "doesn't ask the driver" do - allow(driver).to receive(:content_md5).and_return '' + allow(driver).to receive(:content_md5).and_return nil expect(driver).not_to receive(:md5_mismatch?).and_call_original headers.md5_mismatch? end it 'returns false' do - allow(driver).to receive(:content_md5).and_return '' + allow(driver).to receive(:content_md5).and_return nil expect(headers.md5_mismatch?).to be false end