Permalink
Browse files

Merge pull request #156 from brookemckim/opaque_incorrectly_set_when_…

…not_present

Fix: Opaque value incorrectly sent in request when not present in response from server.
  • Loading branch information...
2 parents fffc08d + 034244c commit 62213dd11a2fb0e113caa3910f936f2ac4391dc6 @jnunemaker committed Sep 7, 2012
Showing with 33 additions and 1 deletion.
  1. +8 −1 lib/httparty/net_digest_auth.rb
  2. +25 −0 spec/httparty/net_digest_auth_spec.rb
@@ -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
@@ -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
@@ -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({

0 comments on commit 62213dd

Please sign in to comment.