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