summaryrefslogtreecommitdiff
path: root/spec/ruby/library/net/http
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-28 15:15:48 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-28 15:15:48 +0000
commit8c5b60eb22d6d661e87992a65d54e3a5bc0aeed4 (patch)
tree7905b284cb5b3d62c17ad8a939e339621a498a2c /spec/ruby/library/net/http
parent6530b14cee76e2512424d225e64d3c61dd1f6511 (diff)
Update to ruby/spec@a6b8805
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/library/net/http')
-rw-r--r--spec/ruby/library/net/http/http/fixtures/http_server.rb12
-rw-r--r--spec/ruby/library/net/http/http/post_spec.rb39
-rw-r--r--spec/ruby/library/net/http/http/request_types_spec.rb28
-rw-r--r--spec/ruby/library/net/http/httpheader/content_length_spec.rb2
4 files changed, 66 insertions, 15 deletions
diff --git a/spec/ruby/library/net/http/http/fixtures/http_server.rb b/spec/ruby/library/net/http/http/fixtures/http_server.rb
index c2ae2360d3..198fef36fb 100644
--- a/spec/ruby/library/net/http/http/fixtures/http_server.rb
+++ b/spec/ruby/library/net/http/http/fixtures/http_server.rb
@@ -42,6 +42,17 @@ module NetHTTPSpecs
end
end
+ class RequestBasicAuthServlet < SpecServlet
+ def reply(req, res)
+ res.content_type = "text/plain"
+
+ WEBrick::HTTPAuth.basic_auth(req, res, "realm") do |user, pass|
+ res.body = "username: #{user}\npassword: #{pass}"
+ true
+ end
+ end
+ end
+
class << self
@server = nil
@server_thread = nil
@@ -69,6 +80,7 @@ module NetHTTPSpecs
@server.mount('/request', RequestServlet)
@server.mount("/request/body", RequestBodyServlet)
@server.mount("/request/header", RequestHeaderServlet)
+ @server.mount("/request/basic_auth", RequestBasicAuthServlet)
@server_thread = @server.start
end
diff --git a/spec/ruby/library/net/http/http/post_spec.rb b/spec/ruby/library/net/http/http/post_spec.rb
index a50663a01d..66a00f0670 100644
--- a/spec/ruby/library/net/http/http/post_spec.rb
+++ b/spec/ruby/library/net/http/http/post_spec.rb
@@ -1,7 +1,45 @@
require File.expand_path('../../../../../spec_helper', __FILE__)
require 'net/http'
+require 'uri'
require File.expand_path('../fixtures/http_server', __FILE__)
+ruby_version_is '2.4' do
+ describe "Net::HTTP.post" do
+ before :each do
+ NetHTTPSpecs.start_server
+ end
+
+ after :each do
+ NetHTTPSpecs.stop_server
+ end
+
+ it "sends post request to the specified URI and returns response" do
+ response = Net::HTTP.post(
+ URI("http://localhost:#{NetHTTPSpecs.port}/request"),
+ '{ "q": "ruby", "max": "50" }',
+ "Content-Type" => "application/json")
+ response.body.should == "Request type: POST"
+ end
+
+ it "returns a Net::HTTPResponse" do
+ response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request"), "test=test")
+ response.should be_kind_of(Net::HTTPResponse)
+ end
+
+ it "sends Content-Type: application/x-www-form-urlencoded by default" do
+ response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request/header"), "test=test")
+ response.body.should include('"content-type"=>["application/x-www-form-urlencoded"]')
+ end
+
+ it "does not support HTTP Basic Auth" do
+ response = Net::HTTP.post(
+ URI("http://john:qwerty@localhost:#{NetHTTPSpecs.port}/request/basic_auth"),
+ "test=test")
+ response.body.should == "username: \npassword: "
+ end
+ end
+end
+
describe "Net::HTTP#post" do
before :each do
NetHTTPSpecs.start_server
@@ -36,3 +74,4 @@ describe "Net::HTTP#post" do
end
end
end
+
diff --git a/spec/ruby/library/net/http/http/request_types_spec.rb b/spec/ruby/library/net/http/http/request_types_spec.rb
index 8855a7db66..71fe863bb2 100644
--- a/spec/ruby/library/net/http/http/request_types_spec.rb
+++ b/spec/ruby/library/net/http/http/request_types_spec.rb
@@ -14,7 +14,7 @@ describe "Net::HTTP::Get" do
Net::HTTP::Get::REQUEST_HAS_BODY.should be_false
end
- it "has a Respone Body" do
+ it "has a Response Body" do
Net::HTTP::Get::RESPONSE_HAS_BODY.should be_true
end
end
@@ -32,7 +32,7 @@ describe "Net::HTTP::Head" do
Net::HTTP::Head::REQUEST_HAS_BODY.should be_false
end
- it "has no Respone Body" do
+ it "has no Response Body" do
Net::HTTP::Head::RESPONSE_HAS_BODY.should be_false
end
end
@@ -50,7 +50,7 @@ describe "Net::HTTP::Post" do
Net::HTTP::Post::REQUEST_HAS_BODY.should be_true
end
- it "has a Respone Body" do
+ it "has a Response Body" do
Net::HTTP::Post::RESPONSE_HAS_BODY.should be_true
end
end
@@ -68,7 +68,7 @@ describe "Net::HTTP::Put" do
Net::HTTP::Put::REQUEST_HAS_BODY.should be_true
end
- it "has a Respone Body" do
+ it "has a Response Body" do
Net::HTTP::Put::RESPONSE_HAS_BODY.should be_true
end
end
@@ -86,7 +86,7 @@ describe "Net::HTTP::Delete" do
Net::HTTP::Delete::REQUEST_HAS_BODY.should be_false
end
- it "has a Respone Body" do
+ it "has a Response Body" do
Net::HTTP::Delete::RESPONSE_HAS_BODY.should be_true
end
end
@@ -104,7 +104,7 @@ describe "Net::HTTP::Options" do
Net::HTTP::Options::REQUEST_HAS_BODY.should be_false
end
- it "has no Respone Body" do
+ it "has no Response Body" do
Net::HTTP::Options::RESPONSE_HAS_BODY.should be_true
end
end
@@ -122,7 +122,7 @@ describe "Net::HTTP::Trace" do
Net::HTTP::Trace::REQUEST_HAS_BODY.should be_false
end
- it "has a Respone Body" do
+ it "has a Response Body" do
Net::HTTP::Trace::RESPONSE_HAS_BODY.should be_true
end
end
@@ -140,7 +140,7 @@ describe "Net::HTTP::Propfind" do
Net::HTTP::Propfind::REQUEST_HAS_BODY.should be_true
end
- it "has a Respone Body" do
+ it "has a Response Body" do
Net::HTTP::Propfind::RESPONSE_HAS_BODY.should be_true
end
end
@@ -158,7 +158,7 @@ describe "Net::HTTP::Proppatch" do
Net::HTTP::Proppatch::REQUEST_HAS_BODY.should be_true
end
- it "has a Respone Body" do
+ it "has a Response Body" do
Net::HTTP::Proppatch::RESPONSE_HAS_BODY.should be_true
end
end
@@ -176,7 +176,7 @@ describe "Net::HTTP::Mkcol" do
Net::HTTP::Mkcol::REQUEST_HAS_BODY.should be_true
end
- it "has a Respone Body" do
+ it "has a Response Body" do
Net::HTTP::Mkcol::RESPONSE_HAS_BODY.should be_true
end
end
@@ -194,7 +194,7 @@ describe "Net::HTTP::Copy" do
Net::HTTP::Copy::REQUEST_HAS_BODY.should be_false
end
- it "has a Respone Body" do
+ it "has a Response Body" do
Net::HTTP::Copy::RESPONSE_HAS_BODY.should be_true
end
end
@@ -212,7 +212,7 @@ describe "Net::HTTP::Move" do
Net::HTTP::Move::REQUEST_HAS_BODY.should be_false
end
- it "has a Respone Body" do
+ it "has a Response Body" do
Net::HTTP::Move::RESPONSE_HAS_BODY.should be_true
end
end
@@ -230,7 +230,7 @@ describe "Net::HTTP::Lock" do
Net::HTTP::Lock::REQUEST_HAS_BODY.should be_true
end
- it "has a Respone Body" do
+ it "has a Response Body" do
Net::HTTP::Lock::RESPONSE_HAS_BODY.should be_true
end
end
@@ -248,7 +248,7 @@ describe "Net::HTTP::Unlock" do
Net::HTTP::Unlock::REQUEST_HAS_BODY.should be_true
end
- it "has a Respone Body" do
+ it "has a Response Body" do
Net::HTTP::Unlock::RESPONSE_HAS_BODY.should be_true
end
end
diff --git a/spec/ruby/library/net/http/httpheader/content_length_spec.rb b/spec/ruby/library/net/http/httpheader/content_length_spec.rb
index 009eafde85..d93eb3a608 100644
--- a/spec/ruby/library/net/http/httpheader/content_length_spec.rb
+++ b/spec/ruby/library/net/http/httpheader/content_length_spec.rb
@@ -36,7 +36,7 @@ describe "Net::HTTPHeader#content_length=" do
it "removes the 'Content-Length' entry if passed false or nil" do
@headers["Content-Length"] = "123"
@headers.content_length = nil
- @headers["Content-Lenght"].should be_nil
+ @headers["Content-Length"].should be_nil
end
it "sets the 'Content-Length' entry to the passed value" do