mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Formatting cleanup.
This commit is contained in:
parent
e976c80348
commit
c0f0dc0e7b
11 changed files with 50 additions and 40 deletions
|
@ -6,7 +6,6 @@ describe HTTParty::CookieHash do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#add_cookies" do
|
describe "#add_cookies" do
|
||||||
|
|
||||||
describe "with a hash" do
|
describe "with a hash" do
|
||||||
it "should add new key/value pairs to the hash" do
|
it "should add new key/value pairs to the hash" do
|
||||||
@cookie_hash.add_cookies(:foo => "bar")
|
@cookie_hash.add_cookies(:foo => "bar")
|
||||||
|
|
|
@ -13,11 +13,11 @@ describe Net::HTTPHeader::DigestAuthenticator do
|
||||||
@digest.authorization_header.join(", ")
|
@digest.authorization_header.join(", ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
context "with specified quality of protection (qop)" do
|
context "with specified quality of protection (qop)" do
|
||||||
before do
|
before do
|
||||||
@digest = setup_digest({'www-authenticate' =>
|
@digest = setup_digest({
|
||||||
'Digest realm="myhost@testrealm.com", nonce="NONCE", qop="auth"'})
|
'www-authenticate' => 'Digest realm="myhost@testrealm.com", nonce="NONCE", qop="auth"',
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should set prefix" do
|
it "should set prefix" do
|
||||||
|
@ -45,9 +45,7 @@ describe Net::HTTPHeader::DigestAuthenticator do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should set response" do
|
it "should set response" do
|
||||||
request_digest =
|
request_digest = "md5(md5(Mufasa:myhost@testrealm.com:Circle Of Life):NONCE:0:md5(deadbeef):auth:md5(GET:/dir/index.html))"
|
||||||
"md5(md5(Mufasa:myhost@testrealm.com:Circle Of Life)" +
|
|
||||||
":NONCE:0:md5(deadbeef):auth:md5(GET:/dir/index.html))"
|
|
||||||
authorization_header.should include(%Q(response="#{request_digest}"))
|
authorization_header.should include(%Q(response="#{request_digest}"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -55,8 +53,9 @@ describe Net::HTTPHeader::DigestAuthenticator do
|
||||||
|
|
||||||
context "with unspecified quality of protection (qop)" do
|
context "with unspecified quality of protection (qop)" do
|
||||||
before do
|
before do
|
||||||
@digest = setup_digest({'www-authenticate' =>
|
@digest = setup_digest({
|
||||||
'Digest realm="myhost@testrealm.com", nonce="NONCE"'})
|
'www-authenticate' => 'Digest realm="myhost@testrealm.com", nonce="NONCE"',
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should set prefix" do
|
it "should set prefix" do
|
||||||
|
@ -84,9 +83,7 @@ describe Net::HTTPHeader::DigestAuthenticator do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should set response" do
|
it "should set response" do
|
||||||
request_digest =
|
request_digest = "md5(md5(Mufasa:myhost@testrealm.com:Circle Of Life):NONCE:md5(GET:/dir/index.html))"
|
||||||
"md5(md5(Mufasa:myhost@testrealm.com:Circle Of Life)" +
|
|
||||||
":NONCE:md5(GET:/dir/index.html))"
|
|
||||||
authorization_header.should include(%Q(response="#{request_digest}"))
|
authorization_header.should include(%Q(response="#{request_digest}"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -102,9 +102,9 @@ describe HTTParty::Response do
|
||||||
|
|
||||||
describe "semantic methods for response codes" do
|
describe "semantic methods for response codes" do
|
||||||
def response_mock(klass)
|
def response_mock(klass)
|
||||||
r = klass.new('', '', '')
|
response = klass.new('', '', '')
|
||||||
r.stub(:body)
|
response.stub(:body)
|
||||||
r
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
context "major codes" do
|
context "major codes" do
|
||||||
|
|
|
@ -3,11 +3,11 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
||||||
describe HTTParty::Request do
|
describe HTTParty::Request do
|
||||||
context "SSL certificate verification" do
|
context "SSL certificate verification" do
|
||||||
before do
|
before do
|
||||||
FakeWeb.allow_net_connect = true # enable network connections just for this test
|
FakeWeb.allow_net_connect = true
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
FakeWeb.allow_net_connect = false # Restore allow_net_connect value for testing
|
FakeWeb.allow_net_connect = false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should work with when no trusted CA list is specified" do
|
it "should work with when no trusted CA list is specified" do
|
||||||
|
@ -25,6 +25,7 @@ describe HTTParty::Request do
|
||||||
it "should work when using ssl_ca_file with a certificate authority" do
|
it "should work when using ssl_ca_file with a certificate authority" do
|
||||||
ssl_verify_test(:ssl_ca_file, "ca.crt", "server.crt").should == {'success' => true}
|
ssl_verify_test(:ssl_ca_file, "ca.crt", "server.crt").should == {'success' => true}
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should work when using ssl_ca_path with a certificate authority" do
|
it "should work when using ssl_ca_path with a certificate authority" do
|
||||||
ssl_verify_test(:ssl_ca_path, ".", "server.crt").should == {'success' => true}
|
ssl_verify_test(:ssl_ca_path, ".", "server.crt").should == {'success' => true}
|
||||||
end
|
end
|
||||||
|
@ -34,6 +35,7 @@ describe HTTParty::Request do
|
||||||
ssl_verify_test(:ssl_ca_file, "ca.crt", "selfsigned.crt")
|
ssl_verify_test(:ssl_ca_file, "ca.crt", "selfsigned.crt")
|
||||||
end.should raise_error(OpenSSL::SSL::SSLError)
|
end.should raise_error(OpenSSL::SSL::SSLError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should fail when using ssl_ca_path and the server uses an unrecognized certificate authority" do
|
it "should fail when using ssl_ca_path and the server uses an unrecognized certificate authority" do
|
||||||
lambda do
|
lambda do
|
||||||
ssl_verify_test(:ssl_ca_path, ".", "selfsigned.crt")
|
ssl_verify_test(:ssl_ca_path, ".", "selfsigned.crt")
|
||||||
|
@ -45,6 +47,7 @@ describe HTTParty::Request do
|
||||||
ssl_verify_test(:ssl_ca_file, "ca.crt", "bogushost.crt")
|
ssl_verify_test(:ssl_ca_file, "ca.crt", "bogushost.crt")
|
||||||
end.should raise_error(OpenSSL::SSL::SSLError)
|
end.should raise_error(OpenSSL::SSL::SSLError)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should fail when using ssl_ca_path and the server uses a bogus hostname" do
|
it "should fail when using ssl_ca_path and the server uses a bogus hostname" do
|
||||||
lambda do
|
lambda do
|
||||||
ssl_verify_test(:ssl_ca_path, ".", "bogushost.crt")
|
ssl_verify_test(:ssl_ca_path, ".", "bogushost.crt")
|
||||||
|
|
|
@ -10,6 +10,7 @@ describe HTTParty do
|
||||||
before do
|
before do
|
||||||
Kernel.stub(:warn)
|
Kernel.stub(:warn)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "warns with a deprecation message" do
|
it "warns with a deprecation message" do
|
||||||
Kernel.should_receive(:warn).with("Deprecated: Use HTTParty::Parser::SupportedFormats")
|
Kernel.should_receive(:warn).with("Deprecated: Use HTTParty::Parser::SupportedFormats")
|
||||||
HTTParty::AllowedFormats
|
HTTParty::AllowedFormats
|
||||||
|
@ -21,7 +22,6 @@ describe HTTParty do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "pem" do
|
describe "pem" do
|
||||||
|
|
||||||
it 'should set the pem content' do
|
it 'should set the pem content' do
|
||||||
@klass.pem 'PEM-CONTENT'
|
@klass.pem 'PEM-CONTENT'
|
||||||
@klass.default_options[:pem].should == 'PEM-CONTENT'
|
@klass.default_options[:pem].should == 'PEM-CONTENT'
|
||||||
|
@ -36,7 +36,6 @@ describe HTTParty do
|
||||||
@klass.pem 'PEM-CONTENT', 'PASSWORD'
|
@klass.pem 'PEM-CONTENT', 'PASSWORD'
|
||||||
@klass.default_options[:pem_password].should == 'PASSWORD'
|
@klass.default_options[:pem_password].should == 'PASSWORD'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'http_proxy' do
|
describe 'http_proxy' do
|
||||||
|
|
|
@ -13,9 +13,11 @@ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].e
|
||||||
Spec::Runner.configure do |config|
|
Spec::Runner.configure do |config|
|
||||||
config.include HTTParty::StubResponse
|
config.include HTTParty::StubResponse
|
||||||
config.include HTTParty::SSLTestHelper
|
config.include HTTParty::SSLTestHelper
|
||||||
|
|
||||||
config.before(:suite) do
|
config.before(:suite) do
|
||||||
FakeWeb.allow_net_connect = false
|
FakeWeb.allow_net_connect = false
|
||||||
end
|
end
|
||||||
|
|
||||||
config.after(:suite) do
|
config.after(:suite) do
|
||||||
FakeWeb.allow_net_connect = true
|
FakeWeb.allow_net_connect = true
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,13 +3,12 @@ module HTTParty
|
||||||
def ssl_verify_test(mode, ca_basename, server_cert_filename)
|
def ssl_verify_test(mode, ca_basename, server_cert_filename)
|
||||||
test_server = nil
|
test_server = nil
|
||||||
begin
|
begin
|
||||||
# Start an HTTPS server
|
|
||||||
test_server = SSLTestServer.new(
|
test_server = SSLTestServer.new(
|
||||||
:rsa_key => File.read(File.expand_path("../../fixtures/ssl/generated/server.key", __FILE__)),
|
:rsa_key => File.read(File.expand_path("../../fixtures/ssl/generated/server.key", __FILE__)),
|
||||||
:cert => File.read(File.expand_path("../../fixtures/ssl/generated/#{server_cert_filename}", __FILE__)))
|
:cert => File.read(File.expand_path("../../fixtures/ssl/generated/#{server_cert_filename}", __FILE__)))
|
||||||
|
|
||||||
test_server.start
|
test_server.start
|
||||||
|
|
||||||
# Build a request
|
|
||||||
if mode
|
if mode
|
||||||
ca_path = File.expand_path("../../fixtures/ssl/generated/#{ca_basename}", __FILE__)
|
ca_path = File.expand_path("../../fixtures/ssl/generated/#{ca_basename}", __FILE__)
|
||||||
raise ArgumentError.new("#{ca_path} does not exist") unless File.exist?(ca_path)
|
raise ArgumentError.new("#{ca_path} does not exist") unless File.exist?(ca_path)
|
||||||
|
|
|
@ -22,14 +22,18 @@ class SSLTestServer
|
||||||
|
|
||||||
def start
|
def start
|
||||||
@raw_server = TCPServer.new(@port)
|
@raw_server = TCPServer.new(@port)
|
||||||
|
|
||||||
if @port == 0
|
if @port == 0
|
||||||
@port = Socket::getnameinfo(@raw_server.getsockname, Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV)[1].to_i
|
@port = Socket::getnameinfo(@raw_server.getsockname, Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV)[1].to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
@ssl_server = OpenSSL::SSL::SSLServer.new(@raw_server, @ctx)
|
@ssl_server = OpenSSL::SSL::SSLServer.new(@raw_server, @ctx)
|
||||||
|
|
||||||
@stopping_mutex.synchronize{
|
@stopping_mutex.synchronize{
|
||||||
return if @stopping
|
return if @stopping
|
||||||
@thread = Thread.new{ thread_main }
|
@thread = Thread.new{ thread_main }
|
||||||
}
|
}
|
||||||
|
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -46,24 +50,31 @@ class SSLTestServer
|
||||||
def thread_main
|
def thread_main
|
||||||
until @stopping_mutex.synchronize{ @stopping }
|
until @stopping_mutex.synchronize{ @stopping }
|
||||||
(rr,ww,ee) = select([@ssl_server.to_io], nil, nil, 0.1)
|
(rr,ww,ee) = select([@ssl_server.to_io], nil, nil, 0.1)
|
||||||
|
|
||||||
next unless rr && rr.include?(@ssl_server.to_io)
|
next unless rr && rr.include?(@ssl_server.to_io)
|
||||||
|
|
||||||
socket = @ssl_server.accept
|
socket = @ssl_server.accept
|
||||||
|
|
||||||
Thread.new{
|
Thread.new{
|
||||||
header = []
|
header = []
|
||||||
|
|
||||||
until (line = socket.readline).rstrip.empty?
|
until (line = socket.readline).rstrip.empty?
|
||||||
header << line
|
header << line
|
||||||
end
|
end
|
||||||
|
|
||||||
socket.write <<'EOF'.gsub(/\r\n/n, "\n").gsub(/\n/n, "\r\n")
|
response =<<EOF
|
||||||
HTTP/1.1 200 OK
|
HTTP/1.1 200 OK
|
||||||
Connection: close
|
Connection: close
|
||||||
Content-Type: application/json; charset=UTF-8
|
Content-Type: application/json; charset=UTF-8
|
||||||
|
|
||||||
{"success":true}
|
{"success":true}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
socket.write(response.gsub(/\r\n/n, "\n").gsub(/\n/n, "\r\n"))
|
||||||
socket.close
|
socket.close
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ssl_server.close
|
@ssl_server.close
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue