Skip to content

Commit

Permalink
Merge pull request #145 from fwininger/headers
Browse files Browse the repository at this point in the history
Change return type for request #content_md5 #timestamp #content_type
  • Loading branch information
mgomes authored Aug 8, 2017
2 parents 22e91aa + 8196476 commit 9052df1
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 47 deletions.
6 changes: 3 additions & 3 deletions lib/api_auth/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
9 changes: 3 additions & 6 deletions lib/api_auth/request_drivers/action_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 3 additions & 6 deletions lib/api_auth/request_drivers/curb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 3 additions & 6 deletions lib/api_auth/request_drivers/faraday.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 3 additions & 6 deletions lib/api_auth/request_drivers/httpi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 3 additions & 6 deletions lib/api_auth/request_drivers/net_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 3 additions & 6 deletions lib/api_auth/request_drivers/rack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 3 additions & 6 deletions lib/api_auth/request_drivers/rest_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/headers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9052df1

Please sign in to comment.