Skip to content

Commit

Permalink
Merge pull request jnunemaker#156 from brookemckim/opaque_incorrectly…
Browse files Browse the repository at this point in the history
…_set_when_not_present

Fix: Opaque value incorrectly sent in request when not present in response from server.
  • Loading branch information
greatuserongithub committed Sep 7, 2012
2 parents fffc08d + 034244c commit 62213dd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/httparty/net_digest_auth.rb
Expand Up @@ -25,10 +25,13 @@ def authorization_header
%Q(nonce="#{@response['nonce']}"),
%Q(uri="#{@path}"),
%Q(response="#{request_digest}")]

[%Q(cnonce="#{@cnonce}"),
%Q(opaque="#{@response['opaque']}"),
%Q(qop="#{@response['qop']}"),
%Q(nc="0")].each { |field| header << field } if qop_present?

header << %Q(opaque="#{@response['opaque']}") if opaque_present?

header
end

Expand All @@ -41,6 +44,10 @@ def parse(response_header)
params
end

def opaque_present?
@response.has_key?('opaque') and not @response['opaque'].empty?
end

def qop_present?
@response.has_key?('qop') and not @response['qop'].empty?
end
Expand Down
25 changes: 25 additions & 0 deletions spec/httparty/net_digest_auth_spec.rb
Expand Up @@ -13,6 +13,31 @@ def authorization_header
@digest.authorization_header.join(", ")
end


context "with an opaque value in the response header" do
before do
@digest = setup_digest({
'www-authenticate' => 'Digest realm="myhost@testrealm.com", opaque="solid"'
})
end

it "should set opaque" do
authorization_header.should include(%Q(opaque="solid"))
end
end

context "without an opaque valid in the response header" do
before do
@digest = setup_digest({
'www-authenticate' => 'Digest realm="myhost@testrealm.com"'
})
end

it "should not set opaque" do
authorization_header.should_not include(%Q(opaque=))
end
end

context "with specified quality of protection (qop)" do
before do
@digest = setup_digest({
Expand Down

0 comments on commit 62213dd

Please sign in to comment.