From c4e78dfe36cd8f61d4815d559c0ee66854dee83e Mon Sep 17 00:00:00 2001 From: Sandro Turriate Date: Thu, 20 Jan 2011 12:27:05 -0500 Subject: [PATCH] Whitespace --- lib/httparty/net_digest_auth.rb | 22 +++++++-------- spec/httparty/net_digest_auth_spec.rb | 40 +++++++++++++-------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/httparty/net_digest_auth.rb b/lib/httparty/net_digest_auth.rb index 093d91d..e18aef1 100644 --- a/lib/httparty/net_digest_auth.rb +++ b/lib/httparty/net_digest_auth.rb @@ -7,9 +7,9 @@ module Net @header['Authorization'] = DigestAuthenticator.new(username, password, @method, @path, response).authorization_header end - - - class DigestAuthenticator + + + class DigestAuthenticator def initialize(username, password, method, path, response_header) @username = username @password = password @@ -17,7 +17,7 @@ module Net @path = path @response = parse(response_header) end - + def authorization_header @cnonce = md5(random) header = [%Q(Digest username="#{@username}"), @@ -31,34 +31,34 @@ module Net %Q(nc="0")].each { |field| header << field } if qop_present? header end - + private - + def parse(response_header) response_header['www-authenticate'] =~ /^(\w+) (.*)/ params = {} $2.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 } params end - + def qop_present? @response.has_key?('qop') and not @response['qop'].empty? end - + def random "%x" % (Time.now.to_i + rand(65535)) end - + def request_digest a = [md5(a1), @response['nonce'], md5(a2)] a.insert(2, "0", @cnonce, @response['qop']) if qop_present? md5(a.join(":")) end - + def md5(str) Digest::MD5.hexdigest(str) end - + def a1 [@username, @response['realm'], @password].join(":") end diff --git a/spec/httparty/net_digest_auth_spec.rb b/spec/httparty/net_digest_auth_spec.rb index c0f0c6c..4d96f34 100644 --- a/spec/httparty/net_digest_auth_spec.rb +++ b/spec/httparty/net_digest_auth_spec.rb @@ -3,12 +3,12 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) describe Net::HTTPHeader::DigestAuthenticator do def setup_digest(response) digest = Net::HTTPHeader::DigestAuthenticator.new("Mufasa", - "Circle Of Life", "GET", "/dir/index.html", response) + "Circle Of Life", "GET", "/dir/index.html", response) digest.stub(:random).and_return("deadbeef") Digest::MD5.stub(:hexdigest) { |str| "md5(#{str})" } digest end - + def authorization_header @digest.authorization_header.join(", ") end @@ -16,14 +16,14 @@ describe Net::HTTPHeader::DigestAuthenticator do context "with specified quality of protection (qop)" do before do - @digest = setup_digest({'www-authenticate' => + @digest = setup_digest({'www-authenticate' => 'Digest realm="myhost@testrealm.com", nonce="NONCE", qop="auth"'}) end - + it "should set prefix" do authorization_header.should =~ /^Digest / end - + it "should set username" do authorization_header.should include(%Q(username="Mufasa")) end @@ -31,19 +31,19 @@ describe Net::HTTPHeader::DigestAuthenticator do it "should set digest-uri" do authorization_header.should include(%Q(uri="/dir/index.html")) end - - it "should set qop" do + + it "should set qop" do authorization_header.should include(%Q(qop="auth")) end it "should set cnonce" do authorization_header.should include(%Q(cnonce="md5(deadbeef)")) end - + it "should set nonce-count" do authorization_header.should include(%Q(nc="0")) end - + it "should set response" do request_digest = "md5(md5(Mufasa:myhost@testrealm.com:Circle Of Life)" + @@ -55,14 +55,14 @@ describe Net::HTTPHeader::DigestAuthenticator do context "with unspecified quality of protection (qop)" do before do - @digest = setup_digest({'www-authenticate' => + @digest = setup_digest({'www-authenticate' => 'Digest realm="myhost@testrealm.com", nonce="NONCE"'}) end - + it "should set prefix" do authorization_header.should =~ /^Digest / end - + it "should set username" do authorization_header.should include(%Q(username="Mufasa")) end @@ -70,19 +70,19 @@ describe Net::HTTPHeader::DigestAuthenticator do it "should set digest-uri" do authorization_header.should include(%Q(uri="/dir/index.html")) end - - it "should not set qop" do + + it "should not set qop" do authorization_header.should_not include(%Q(qop=)) end - - it "should not set cnonce" do + + it "should not set cnonce" do authorization_header.should_not include(%Q(cnonce=)) end - - it "should not set nonce-count" do + + it "should not set nonce-count" do authorization_header.should_not include(%Q(nc=)) end - + it "should set response" do request_digest = "md5(md5(Mufasa:myhost@testrealm.com:Circle Of Life)" + @@ -90,4 +90,4 @@ describe Net::HTTPHeader::DigestAuthenticator do authorization_header.should include(%Q(response="#{request_digest}")) end end -end \ No newline at end of file +end