summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-12 03:11:49 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-12 03:11:49 +0000
commit8933356469fb87136f3df28c6ad9e3cf31959cce (patch)
tree5a6367acd382450ea6276e6c4618a1df499bdb9a /test
parent433219bced8ff7a0f20c11371ffa7f32b76c5dcf (diff)
more tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24857 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/test_open-uri.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/test_open-uri.rb b/test/test_open-uri.rb
index cded05af98..2e7053fef7 100644
--- a/test/test_open-uri.rb
+++ b/test/test_open-uri.rb
@@ -25,6 +25,16 @@ class TestOpenURI < Test::Unit::TestCase
}
end
+ def setup
+ @proxies = %w[http_proxy ftp_proxy no_proxy]
+ @old_proxies = @proxies.map {|k| ENV[k] }
+ @proxies.each {|k| ENV[k] = nil }
+ end
+
+ def teardown
+ @proxies.each_with_index {|k, i| ENV[k] = @old_proxies[i] }
+ end
+
def test_200
with_http {|srv, dr, url|
open("#{dr}/foo200", "w") {|f| f << "foo200" }
@@ -312,5 +322,49 @@ class TestOpenURI < Test::Unit::TestCase
}
end
+ def with_env(h)
+ begin
+ old = {}
+ h.each_key {|k| old[k] = ENV[k] }
+ h.each {|k, v| ENV[k] = v }
+ yield
+ ensure
+ h.each_key {|k| ENV[k] = old[k] }
+ end
+ end
+
+ def test_find_proxy
+ # 192.0.2.0/24 is TEST-NET. RFC3330
+ assert_nil(URI("http://192.0.2.1/").find_proxy)
+ assert_nil(URI("ftp://192.0.2.1/").find_proxy)
+ with_env('http_proxy'=>'http://127.0.0.1:8080') {
+ assert_equal(URI('http://127.0.0.1:8080'), URI("http://192.0.2.1/").find_proxy)
+ assert_nil(URI("ftp://192.0.2.1/").find_proxy)
+ }
+ with_env('ftp_proxy'=>'http://127.0.0.1:8080') {
+ assert_nil(URI("http://192.0.2.1/").find_proxy)
+ assert_equal(URI('http://127.0.0.1:8080'), URI("ftp://192.0.2.1/").find_proxy)
+ }
+ with_env('REQUEST_METHOD'=>'GET') {
+ assert_nil(URI("http://192.0.2.1/").find_proxy)
+ }
+ with_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'192.0.2.2') {
+ assert_equal(URI('http://127.0.0.1:8080'), URI("http://192.0.2.1/").find_proxy)
+ assert_nil(URI("http://192.0.2.2/").find_proxy)
+ }
+ end
+
+ def test_find_proxy_case_sensitive_env
+ with_env('http_proxy'=>'http://127.0.0.1:8080', 'REQUEST_METHOD'=>'GET') {
+ assert_equal(URI('http://127.0.0.1:8080'), URI("http://192.0.2.1/").find_proxy)
+ }
+ with_env('HTTP_PROXY'=>'http://127.0.0.1:8081', 'REQUEST_METHOD'=>'GET') {
+ assert_nil(nil, URI("http://192.0.2.1/").find_proxy)
+ }
+ with_env('http_proxy'=>'http://127.0.0.1:8080', 'HTTP_PROXY'=>'http://127.0.0.1:8081', 'REQUEST_METHOD'=>'GET') {
+ assert_equal(URI('http://127.0.0.1:8080'), URI("http://192.0.2.1/").find_proxy)
+ }
+ end
+
end