scout 5.7.1 → 5.7.2.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +5 -0
- data/lib/scout/command/run.rb +1 -1
- data/lib/scout/server.rb +2 -1
- data/lib/scout/streamer.rb +3 -2
- data/lib/scout/streamer_daemon.rb +4 -4
- data/lib/scout/version.rb +1 -1
- data/test/scout_test.rb +7 -8
- data/vendor/httpclient/README.txt +759 -0
- data/vendor/httpclient/bin/httpclient +65 -0
- data/vendor/httpclient/lib/hexdump.rb +50 -0
- data/vendor/httpclient/lib/http-access2.rb +55 -0
- data/vendor/httpclient/lib/http-access2/cookie.rb +1 -0
- data/vendor/httpclient/lib/http-access2/http.rb +1 -0
- data/vendor/httpclient/lib/httpclient.rb +1156 -0
- data/vendor/httpclient/lib/httpclient/auth.rb +899 -0
- data/vendor/httpclient/lib/httpclient/cacert.p7s +1912 -0
- data/vendor/httpclient/lib/httpclient/connection.rb +88 -0
- data/vendor/httpclient/lib/httpclient/cookie.rb +438 -0
- data/vendor/httpclient/lib/httpclient/http.rb +1046 -0
- data/vendor/httpclient/lib/httpclient/include_client.rb +83 -0
- data/vendor/httpclient/lib/httpclient/session.rb +1025 -0
- data/vendor/httpclient/lib/httpclient/ssl_config.rb +403 -0
- data/vendor/httpclient/lib/httpclient/timeout.rb +140 -0
- data/vendor/httpclient/lib/httpclient/util.rb +178 -0
- data/vendor/httpclient/lib/httpclient/version.rb +3 -0
- data/vendor/httpclient/lib/oauthclient.rb +110 -0
- data/vendor/httpclient/sample/async.rb +8 -0
- data/vendor/httpclient/sample/auth.rb +11 -0
- data/vendor/httpclient/sample/cookie.rb +18 -0
- data/vendor/httpclient/sample/dav.rb +103 -0
- data/vendor/httpclient/sample/howto.rb +49 -0
- data/vendor/httpclient/sample/oauth_buzz.rb +57 -0
- data/vendor/httpclient/sample/oauth_friendfeed.rb +59 -0
- data/vendor/httpclient/sample/oauth_salesforce_10.rb +63 -0
- data/vendor/httpclient/sample/oauth_twitter.rb +61 -0
- data/vendor/httpclient/sample/ssl/0cert.pem +22 -0
- data/vendor/httpclient/sample/ssl/0key.pem +30 -0
- data/vendor/httpclient/sample/ssl/1000cert.pem +19 -0
- data/vendor/httpclient/sample/ssl/1000key.pem +18 -0
- data/vendor/httpclient/sample/ssl/htdocs/index.html +10 -0
- data/vendor/httpclient/sample/ssl/ssl_client.rb +22 -0
- data/vendor/httpclient/sample/ssl/webrick_httpsd.rb +29 -0
- data/vendor/httpclient/sample/stream.rb +21 -0
- data/vendor/httpclient/sample/thread.rb +27 -0
- data/vendor/httpclient/sample/wcat.rb +21 -0
- data/vendor/httpclient/test/ca-chain.cert +44 -0
- data/vendor/httpclient/test/ca.cert +23 -0
- data/vendor/httpclient/test/client.cert +19 -0
- data/vendor/httpclient/test/client.key +15 -0
- data/vendor/httpclient/test/helper.rb +129 -0
- data/vendor/httpclient/test/htdigest +1 -0
- data/vendor/httpclient/test/htpasswd +2 -0
- data/vendor/httpclient/test/runner.rb +2 -0
- data/vendor/httpclient/test/server.cert +19 -0
- data/vendor/httpclient/test/server.key +15 -0
- data/vendor/httpclient/test/sslsvr.rb +65 -0
- data/vendor/httpclient/test/subca.cert +21 -0
- data/vendor/httpclient/test/test_auth.rb +321 -0
- data/vendor/httpclient/test/test_cookie.rb +391 -0
- data/vendor/httpclient/test/test_hexdump.rb +14 -0
- data/vendor/httpclient/test/test_http-access2.rb +507 -0
- data/vendor/httpclient/test/test_httpclient.rb +1783 -0
- data/vendor/httpclient/test/test_include_client.rb +52 -0
- data/vendor/httpclient/test/test_ssl.rb +235 -0
- data/vendor/multi_json/.document +5 -0
- data/vendor/multi_json/.rspec +3 -0
- data/vendor/multi_json/.travis.yml +11 -0
- data/vendor/multi_json/.yardopts +6 -0
- data/vendor/multi_json/CHANGELOG.md +169 -0
- data/vendor/multi_json/CONTRIBUTING.md +46 -0
- data/vendor/multi_json/Gemfile +31 -0
- data/vendor/multi_json/LICENSE.md +20 -0
- data/vendor/multi_json/README.md +109 -0
- data/vendor/multi_json/Rakefile +12 -0
- data/vendor/multi_json/lib/multi_json.rb +157 -0
- data/vendor/multi_json/lib/multi_json/adapter.rb +48 -0
- data/vendor/multi_json/lib/multi_json/adapters/gson.rb +19 -0
- data/vendor/multi_json/lib/multi_json/adapters/jr_jackson.rb +19 -0
- data/vendor/multi_json/lib/multi_json/adapters/json_common.rb +25 -0
- data/vendor/multi_json/lib/multi_json/adapters/json_gem.rb +11 -0
- data/vendor/multi_json/lib/multi_json/adapters/json_pure.rb +11 -0
- data/vendor/multi_json/lib/multi_json/adapters/nsjsonserialization.rb +34 -0
- data/vendor/multi_json/lib/multi_json/adapters/oj.rb +24 -0
- data/vendor/multi_json/lib/multi_json/adapters/ok_json.rb +22 -0
- data/vendor/multi_json/lib/multi_json/adapters/yajl.rb +19 -0
- data/vendor/multi_json/lib/multi_json/convertible_hash_keys.rb +43 -0
- data/vendor/multi_json/lib/multi_json/load_error.rb +11 -0
- data/vendor/multi_json/lib/multi_json/options.rb +48 -0
- data/vendor/multi_json/lib/multi_json/vendor/okjson.rb +606 -0
- data/vendor/multi_json/lib/multi_json/version.rb +20 -0
- data/vendor/multi_json/multi_json.gemspec +22 -0
- data/vendor/multi_json/spec/adapter_shared_example.rb +235 -0
- data/vendor/multi_json/spec/has_options.rb +119 -0
- data/vendor/multi_json/spec/helper.rb +35 -0
- data/vendor/multi_json/spec/json_common_shared_example.rb +30 -0
- data/vendor/multi_json/spec/multi_json_spec.rb +226 -0
- data/vendor/{signature → pusher}/.document +0 -0
- data/vendor/{json_pure/diagrams/.keep → pusher/.gemtest} +0 -0
- data/vendor/pusher/.gitignore +23 -0
- data/vendor/pusher/.travis.yml +15 -0
- data/vendor/pusher/Gemfile +2 -0
- data/vendor/{pusher-gem → pusher}/LICENSE +1 -1
- data/vendor/pusher/README.md +186 -0
- data/vendor/{pusher-gem → pusher}/Rakefile +0 -0
- data/vendor/{pusher-gem → pusher}/examples/async_message.rb +0 -0
- data/vendor/pusher/lib/pusher.rb +60 -0
- data/vendor/{pusher-gem → pusher}/lib/pusher/channel.rb +47 -54
- data/vendor/pusher/lib/pusher/client.rb +306 -0
- data/vendor/pusher/lib/pusher/request.rb +107 -0
- data/vendor/pusher/lib/pusher/resource.rb +36 -0
- data/vendor/pusher/lib/pusher/webhook.rb +110 -0
- data/vendor/{pusher-gem → pusher}/pusher.gemspec +6 -5
- data/vendor/pusher/spec/channel_spec.rb +127 -0
- data/vendor/pusher/spec/client_spec.rb +464 -0
- data/vendor/{pusher-gem → pusher}/spec/spec_helper.rb +12 -0
- data/vendor/pusher/spec/web_hook_spec.rb +117 -0
- data/vendor/signature/.travis.yml +15 -0
- data/vendor/signature/Gemfile +1 -1
- data/vendor/signature/README.md +38 -28
- data/vendor/signature/lib/signature.rb +97 -15
- data/vendor/signature/lib/signature/query_encoder.rb +47 -0
- data/vendor/signature/lib/signature/version.rb +1 -1
- data/vendor/signature/signature.gemspec +3 -2
- data/vendor/signature/spec/signature_spec.rb +164 -55
- data/vendor/signature/spec/spec_helper.rb +2 -3
- metadata +120 -145
- data/vendor/json_pure/.gitignore +0 -12
- data/vendor/json_pure/.travis.yml +0 -20
- data/vendor/json_pure/CHANGES +0 -282
- data/vendor/json_pure/COPYING +0 -58
- data/vendor/json_pure/COPYING-json-jruby +0 -57
- data/vendor/json_pure/GPL +0 -340
- data/vendor/json_pure/Gemfile +0 -11
- data/vendor/json_pure/README-json-jruby.markdown +0 -33
- data/vendor/json_pure/README.rdoc +0 -358
- data/vendor/json_pure/Rakefile +0 -412
- data/vendor/json_pure/TODO +0 -1
- data/vendor/json_pure/VERSION +0 -1
- data/vendor/json_pure/data/example.json +0 -1
- data/vendor/json_pure/data/index.html +0 -38
- data/vendor/json_pure/data/prototype.js +0 -4184
- data/vendor/json_pure/ext/json/ext/fbuffer/fbuffer.h +0 -181
- data/vendor/json_pure/ext/json/ext/generator/depend +0 -1
- data/vendor/json_pure/ext/json/ext/generator/extconf.rb +0 -14
- data/vendor/json_pure/ext/json/ext/generator/generator.c +0 -1435
- data/vendor/json_pure/ext/json/ext/generator/generator.h +0 -148
- data/vendor/json_pure/ext/json/ext/parser/depend +0 -1
- data/vendor/json_pure/ext/json/ext/parser/extconf.rb +0 -13
- data/vendor/json_pure/ext/json/ext/parser/parser.c +0 -2204
- data/vendor/json_pure/ext/json/ext/parser/parser.h +0 -77
- data/vendor/json_pure/ext/json/ext/parser/parser.rl +0 -927
- data/vendor/json_pure/install.rb +0 -23
- data/vendor/json_pure/java/src/json/ext/ByteListTranscoder.java +0 -167
- data/vendor/json_pure/java/src/json/ext/Generator.java +0 -444
- data/vendor/json_pure/java/src/json/ext/GeneratorMethods.java +0 -232
- data/vendor/json_pure/java/src/json/ext/GeneratorService.java +0 -43
- data/vendor/json_pure/java/src/json/ext/GeneratorState.java +0 -543
- data/vendor/json_pure/java/src/json/ext/OptionsReader.java +0 -114
- data/vendor/json_pure/java/src/json/ext/Parser.java +0 -2644
- data/vendor/json_pure/java/src/json/ext/Parser.rl +0 -968
- data/vendor/json_pure/java/src/json/ext/ParserService.java +0 -35
- data/vendor/json_pure/java/src/json/ext/RuntimeInfo.java +0 -121
- data/vendor/json_pure/java/src/json/ext/StringDecoder.java +0 -167
- data/vendor/json_pure/java/src/json/ext/StringEncoder.java +0 -106
- data/vendor/json_pure/java/src/json/ext/Utils.java +0 -89
- data/vendor/json_pure/json-java.gemspec +0 -23
- data/vendor/json_pure/json.gemspec +0 -37
- data/vendor/json_pure/json_pure.gemspec +0 -39
- data/vendor/json_pure/lib/json.rb +0 -62
- data/vendor/json_pure/lib/json/add/bigdecimal.rb +0 -28
- data/vendor/json_pure/lib/json/add/complex.rb +0 -22
- data/vendor/json_pure/lib/json/add/core.rb +0 -11
- data/vendor/json_pure/lib/json/add/date.rb +0 -34
- data/vendor/json_pure/lib/json/add/date_time.rb +0 -50
- data/vendor/json_pure/lib/json/add/exception.rb +0 -31
- data/vendor/json_pure/lib/json/add/ostruct.rb +0 -31
- data/vendor/json_pure/lib/json/add/range.rb +0 -29
- data/vendor/json_pure/lib/json/add/rational.rb +0 -22
- data/vendor/json_pure/lib/json/add/regexp.rb +0 -30
- data/vendor/json_pure/lib/json/add/struct.rb +0 -30
- data/vendor/json_pure/lib/json/add/symbol.rb +0 -25
- data/vendor/json_pure/lib/json/add/time.rb +0 -38
- data/vendor/json_pure/lib/json/common.rb +0 -487
- data/vendor/json_pure/lib/json/ext.rb +0 -21
- data/vendor/json_pure/lib/json/ext/.keep +0 -0
- data/vendor/json_pure/lib/json/generic_object.rb +0 -70
- data/vendor/json_pure/lib/json/pure.rb +0 -21
- data/vendor/json_pure/lib/json/pure/generator.rb +0 -522
- data/vendor/json_pure/lib/json/pure/parser.rb +0 -359
- data/vendor/json_pure/lib/json/version.rb +0 -8
- data/vendor/json_pure/tests/fixtures/fail1.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail10.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail11.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail12.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail13.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail14.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail18.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail19.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail2.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail20.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail21.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail22.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail23.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail24.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail25.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail27.json +0 -2
- data/vendor/json_pure/tests/fixtures/fail28.json +0 -2
- data/vendor/json_pure/tests/fixtures/fail3.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail4.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail5.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail6.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail7.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail8.json +0 -1
- data/vendor/json_pure/tests/fixtures/fail9.json +0 -1
- data/vendor/json_pure/tests/fixtures/pass1.json +0 -56
- data/vendor/json_pure/tests/fixtures/pass15.json +0 -1
- data/vendor/json_pure/tests/fixtures/pass16.json +0 -1
- data/vendor/json_pure/tests/fixtures/pass17.json +0 -1
- data/vendor/json_pure/tests/fixtures/pass2.json +0 -1
- data/vendor/json_pure/tests/fixtures/pass26.json +0 -1
- data/vendor/json_pure/tests/fixtures/pass3.json +0 -6
- data/vendor/json_pure/tests/setup_variant.rb +0 -11
- data/vendor/json_pure/tests/test_json.rb +0 -545
- data/vendor/json_pure/tests/test_json_addition.rb +0 -196
- data/vendor/json_pure/tests/test_json_encoding.rb +0 -65
- data/vendor/json_pure/tests/test_json_fixtures.rb +0 -35
- data/vendor/json_pure/tests/test_json_generate.rb +0 -322
- data/vendor/json_pure/tests/test_json_generic_object.rb +0 -75
- data/vendor/json_pure/tests/test_json_string_matching.rb +0 -39
- data/vendor/json_pure/tests/test_json_unicode.rb +0 -72
- data/vendor/json_pure/tools/fuzz.rb +0 -139
- data/vendor/json_pure/tools/server.rb +0 -62
- data/vendor/pusher-gem/Gemfile +0 -2
- data/vendor/pusher-gem/README.md +0 -80
- data/vendor/pusher-gem/lib/pusher.rb +0 -107
- data/vendor/pusher-gem/lib/pusher/request.rb +0 -107
- data/vendor/pusher-gem/spec/channel_spec.rb +0 -274
- data/vendor/pusher-gem/spec/pusher_spec.rb +0 -87
- data/vendor/ruby-hmac/History.txt +0 -15
- data/vendor/ruby-hmac/Manifest.txt +0 -11
- data/vendor/ruby-hmac/README.md +0 -41
- data/vendor/ruby-hmac/Rakefile +0 -23
- data/vendor/ruby-hmac/lib/hmac-md5.rb +0 -11
- data/vendor/ruby-hmac/lib/hmac-rmd160.rb +0 -11
- data/vendor/ruby-hmac/lib/hmac-sha1.rb +0 -11
- data/vendor/ruby-hmac/lib/hmac-sha2.rb +0 -25
- data/vendor/ruby-hmac/lib/hmac.rb +0 -118
- data/vendor/ruby-hmac/lib/ruby_hmac.rb +0 -2
- data/vendor/ruby-hmac/ruby-hmac.gemspec +0 -33
- data/vendor/ruby-hmac/test/test_hmac.rb +0 -89
- data/vendor/signature/VERSION +0 -1
@@ -0,0 +1,391 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
require 'httpclient/cookie'
|
5
|
+
|
6
|
+
class TestCookie < Test::Unit::TestCase
|
7
|
+
include HTTPClient::Util
|
8
|
+
|
9
|
+
def setup()
|
10
|
+
@c = WebAgent::Cookie.new()
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_s_new()
|
14
|
+
assert_instance_of(WebAgent::Cookie, @c)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_discard?
|
18
|
+
assert_equal(false, !!(@c.discard?))
|
19
|
+
@c.discard = true
|
20
|
+
assert_equal(true, !!(@c.discard?))
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_match()
|
24
|
+
url = urify('http://www.rubycolor.org/hoge/funi/#919191')
|
25
|
+
|
26
|
+
@c.domain = 'www.rubycolor.org'
|
27
|
+
assert_equal(true, @c.match?(url))
|
28
|
+
|
29
|
+
@c.domain = '.rubycolor.org'
|
30
|
+
assert_equal(true, @c.match?(url))
|
31
|
+
|
32
|
+
@c.domain = 'aaa.www.rubycolor.org'
|
33
|
+
assert_equal(false, @c.match?(url))
|
34
|
+
|
35
|
+
@c.domain = 'aaa.www.rubycolor.org'
|
36
|
+
assert_equal(false, @c.match?(url))
|
37
|
+
|
38
|
+
@c.domain = 'www.rubycolor.org'
|
39
|
+
@c.path = '/'
|
40
|
+
assert_equal(true, @c.match?(url))
|
41
|
+
|
42
|
+
@c.domain = 'www.rubycolor.org'
|
43
|
+
@c.path = '/hoge'
|
44
|
+
assert_equal(true, @c.match?(url))
|
45
|
+
|
46
|
+
@c.domain = 'www.rubycolor.org'
|
47
|
+
@c.path = '/hoge/hoge'
|
48
|
+
assert_equal(false, @c.match?(url))
|
49
|
+
|
50
|
+
@c.domain = 'www.rubycolor.org'
|
51
|
+
@c.path = '/hoge'
|
52
|
+
@c.secure = true
|
53
|
+
assert_equal(false, @c.match?(url))
|
54
|
+
|
55
|
+
url2 = urify('https://www.rubycolor.org/hoge/funi/#919191')
|
56
|
+
@c.domain = 'www.rubycolor.org'
|
57
|
+
@c.path = '/hoge'
|
58
|
+
@c.secure = true
|
59
|
+
assert_equal(true, @c.match?(url2))
|
60
|
+
|
61
|
+
@c.domain = 'www.rubycolor.org'
|
62
|
+
@c.path = '/hoge'
|
63
|
+
@c.secure = nil
|
64
|
+
assert_equal(true, @c.match?(url2)) ## not false!
|
65
|
+
|
66
|
+
url.port = 80
|
67
|
+
@c.domain = 'www.rubycolor.org'
|
68
|
+
@c.path = '/hoge'
|
69
|
+
# @c.port = [80,8080]
|
70
|
+
assert_equal(true, @c.match?(url))
|
71
|
+
|
72
|
+
url_nopath = URI.parse('http://www.rubycolor.org')
|
73
|
+
@c.domain = 'www.rubycolor.org'
|
74
|
+
@c.path = '/'
|
75
|
+
assert_equal(true, @c.match?(url_nopath))
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_head_match?()
|
80
|
+
assert_equal(true, @c.head_match?("",""))
|
81
|
+
assert_equal(false, @c.head_match?("a",""))
|
82
|
+
assert_equal(true, @c.head_match?("","a"))
|
83
|
+
assert_equal(true, @c.head_match?("abcde","abcde"))
|
84
|
+
assert_equal(true, @c.head_match?("abcde","abcdef"))
|
85
|
+
assert_equal(false, @c.head_match?("abcdef","abcde"))
|
86
|
+
assert_equal(false, @c.head_match?("abcde","bcde"))
|
87
|
+
assert_equal(false, @c.head_match?("bcde","abcde"))
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_tail_match?()
|
91
|
+
assert_equal(true, @c.tail_match?("",""))
|
92
|
+
assert_equal(false, @c.tail_match?("a",""))
|
93
|
+
assert_equal(true, @c.tail_match?("","a"))
|
94
|
+
assert_equal(true, @c.tail_match?("abcde","abcde"))
|
95
|
+
assert_equal(false, @c.tail_match?("abcde","abcdef"))
|
96
|
+
assert_equal(false, @c.tail_match?("abcdef","abcde"))
|
97
|
+
assert_equal(false, @c.tail_match?("abcde","bcde"))
|
98
|
+
assert_equal(true, @c.tail_match?("bcde","abcde"))
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
def test_domain_match()
|
103
|
+
extend WebAgent::CookieUtils
|
104
|
+
assert_equal(true, !!domain_match("hoge.co.jp","."))
|
105
|
+
# assert_equal(true, !!domain_match("locahost",".local"))
|
106
|
+
assert_equal(true, !!domain_match("192.168.10.1","192.168.10.1"))
|
107
|
+
assert_equal(false, !!domain_match("192.168.10.1","192.168.10.2"))
|
108
|
+
# assert_equal(false, !!domain_match("hoge.co.jp",".hoge.co.jp"))
|
109
|
+
# allows; host == rubyforge.org, domain == .rubyforge.org
|
110
|
+
assert_equal(true, !!domain_match("hoge.co.jp",".hoge.co.jp"))
|
111
|
+
assert_equal(true, !!domain_match("www.hoge.co.jp", "www.hoge.co.jp"))
|
112
|
+
assert_equal(false, !!domain_match("www.hoge.co.jp", "www2.hoge.co.jp"))
|
113
|
+
assert_equal(true, !!domain_match("www.hoge.co.jp", ".hoge.co.jp"))
|
114
|
+
assert_equal(true, !!domain_match("www.aa.hoge.co.jp", ".hoge.co.jp"))
|
115
|
+
assert_equal(false, !!domain_match("www.hoge.co.jp", "hoge.co.jp"))
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_join_quotedstr()
|
119
|
+
arr1 = ['hoge=funi', 'hoge2=funi2']
|
120
|
+
assert_equal(arr1, @c.instance_eval{join_quotedstr(arr1,';')})
|
121
|
+
arr2 = ['hoge="fu', 'ni"', 'funi=funi']
|
122
|
+
assert_equal(['hoge="fu;ni"','funi=funi'],
|
123
|
+
@c.instance_eval{join_quotedstr(arr2,';')})
|
124
|
+
arr3 = ['hoge="funi";hoge2="fu','ni2";hoge3="hoge"', 'funi="funi"']
|
125
|
+
assert_equal(['hoge="funi";hoge2="fu,ni2";hoge3="hoge"', 'funi="funi"'],
|
126
|
+
@c.instance_eval{join_quotedstr(arr3,',')})
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
class TestCookieManager < Test::Unit::TestCase
|
132
|
+
include HTTPClient::Util
|
133
|
+
|
134
|
+
def setup()
|
135
|
+
@cm = WebAgent::CookieManager.new()
|
136
|
+
end
|
137
|
+
|
138
|
+
def teardown()
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_parse()
|
142
|
+
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=Wed, 01-Dec-2010 00:00:00 GMT; path=/"
|
143
|
+
@cm.parse(str, urify('http://www.test.jp'))
|
144
|
+
cookie = @cm.cookies[0]
|
145
|
+
assert_instance_of(WebAgent::Cookie, cookie)
|
146
|
+
assert_equal("inkid", cookie.name)
|
147
|
+
assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
|
148
|
+
assert_equal(Time.gm(2010, 12, 1, 0,0,0), cookie.expires)
|
149
|
+
assert_equal("/", cookie.path)
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_parse2()
|
153
|
+
str = "xmen=off,0,0,1; path=/; domain=.excite.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
|
154
|
+
@cm.parse(str, urify('http://www.excite.co.jp'))
|
155
|
+
cookie = @cm.cookies[0]
|
156
|
+
assert_instance_of(WebAgent::Cookie, cookie)
|
157
|
+
assert_equal("xmen", cookie.name)
|
158
|
+
assert_equal("off,0,0,1", cookie.value)
|
159
|
+
assert_equal("/", cookie.path)
|
160
|
+
assert_equal(".excite.co.jp", cookie.domain)
|
161
|
+
assert_equal(Time.gm(2037,12,31,12,0,0), cookie.expires)
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_parse3()
|
165
|
+
str = "xmen=off,0,0,1; path=/; domain=.excite.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT;Secure;HTTPOnly"
|
166
|
+
@cm.parse(str, urify('http://www.excite.co.jp'))
|
167
|
+
cookie = @cm.cookies[0]
|
168
|
+
assert_instance_of(WebAgent::Cookie, cookie)
|
169
|
+
assert_equal("xmen", cookie.name)
|
170
|
+
assert_equal("off,0,0,1", cookie.value)
|
171
|
+
assert_equal("/", cookie.path)
|
172
|
+
assert_equal(".excite.co.jp", cookie.domain)
|
173
|
+
assert_equal(Time.gm(2037,12,31,12,0,0), cookie.expires)
|
174
|
+
assert_equal(true, cookie.secure?)
|
175
|
+
assert_equal(true, cookie.http_only?)
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_parse_double_semicolon()
|
179
|
+
str = "xmen=off,0,0,1;; path=\"/;;\"; domain=.excite.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
|
180
|
+
@cm.parse(str, urify('http://www.excite.co.jp'))
|
181
|
+
cookie = @cm.cookies[0]
|
182
|
+
assert_instance_of(WebAgent::Cookie, cookie)
|
183
|
+
assert_equal("xmen", cookie.name)
|
184
|
+
assert_equal("off,0,0,1", cookie.value)
|
185
|
+
assert_equal("/;;", cookie.path)
|
186
|
+
assert_equal(".excite.co.jp", cookie.domain)
|
187
|
+
assert_equal(Time.gm(2037,12,31,12,0,0), cookie.expires)
|
188
|
+
end
|
189
|
+
|
190
|
+
# def test_make_portlist()
|
191
|
+
# assert_equal([80,8080], @cm.instance_eval{make_portlist("80,8080")})
|
192
|
+
# assert_equal([80], @cm.instance_eval{make_portlist("80")})
|
193
|
+
# assert_equal([80,8080,10080], @cm.instance_eval{make_portlist(" 80, 8080, 10080 \n")})
|
194
|
+
# end
|
195
|
+
|
196
|
+
def test_check_expired_cookies()
|
197
|
+
c1 = WebAgent::Cookie.new()
|
198
|
+
c2 = c1.dup
|
199
|
+
c3 = c1.dup
|
200
|
+
c4 = c1.dup
|
201
|
+
c1.expires = Time.now - 100
|
202
|
+
c2.expires = Time.now + 100
|
203
|
+
c3.expires = Time.now - 10
|
204
|
+
c4.expires = nil
|
205
|
+
cookies = [c1,c2,c3,c4]
|
206
|
+
@cm.cookies = cookies
|
207
|
+
@cm.check_expired_cookies()
|
208
|
+
# expires == nil cookies (session cookie) exists.
|
209
|
+
assert_equal([c2,c4], @cm.cookies)
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_parse_expires
|
213
|
+
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=; path=/"
|
214
|
+
@cm.parse(str, urify('http://www.test.jp'))
|
215
|
+
cookie = @cm.cookies[0]
|
216
|
+
assert_equal("inkid", cookie.name)
|
217
|
+
assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
|
218
|
+
assert_equal(nil, cookie.expires)
|
219
|
+
assert_equal("/", cookie.path)
|
220
|
+
#
|
221
|
+
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; path=/; expires="
|
222
|
+
@cm.parse(str, urify('http://www.test.jp'))
|
223
|
+
cookie = @cm.cookies[0]
|
224
|
+
assert_equal("inkid", cookie.name)
|
225
|
+
assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
|
226
|
+
assert_equal(nil, cookie.expires)
|
227
|
+
assert_equal("/", cookie.path)
|
228
|
+
#
|
229
|
+
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; path=/; expires=\"\""
|
230
|
+
@cm.parse(str, urify('http://www.test.jp'))
|
231
|
+
cookie = @cm.cookies[0]
|
232
|
+
assert_equal("inkid", cookie.name)
|
233
|
+
assert_equal("n92b0ADOgACIgUb9lsjHqAAAHu2a", cookie.value)
|
234
|
+
assert_equal(nil, cookie.expires)
|
235
|
+
assert_equal("/", cookie.path)
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_find_cookie()
|
239
|
+
str = "xmen=off,0,0,1; path=/; domain=.excite2.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
|
240
|
+
@cm.parse(str, urify("http://www.excite2.co.jp/"))
|
241
|
+
|
242
|
+
str = "xmen=off,0,0,2; path=/; domain=.excite.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
|
243
|
+
@cm.parse(str, urify("http://www.excite.co.jp/"))
|
244
|
+
|
245
|
+
@cm.cookies[0].use = true
|
246
|
+
@cm.cookies[1].use = true
|
247
|
+
|
248
|
+
url = urify('http://www.excite.co.jp/hoge/funi/')
|
249
|
+
cookie_str = @cm.find(url)
|
250
|
+
assert_equal("xmen=off,0,0,2", cookie_str)
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_load_cookies()
|
254
|
+
begin
|
255
|
+
File.open("tmp_test.tmp","w") {|f|
|
256
|
+
f.write <<EOF
|
257
|
+
http://www.zdnet.co.jp/news/0106/08/e_gibson.html NGUserID d29b8f49-10875-992421294-1 2145801600 www.zdnet.co.jp / 9 0
|
258
|
+
http://www.zdnet.co.jp/news/0106/08/e_gibson.html PACK zd3-992421294-7436 1293839999 .zdnet.co.jp / 13 0
|
259
|
+
http://example.org/ key value 0 .example.org / 13 0
|
260
|
+
http://example.org/ key value .example.org / 13 0
|
261
|
+
EOF
|
262
|
+
}
|
263
|
+
|
264
|
+
@cm.cookies_file = 'tmp_test.tmp'
|
265
|
+
@cm.load_cookies()
|
266
|
+
c0, c1, c2, c3 = @cm.cookies
|
267
|
+
assert_equal('http://www.zdnet.co.jp/news/0106/08/e_gibson.html', c0.url.to_s)
|
268
|
+
assert_equal('NGUserID', c0.name)
|
269
|
+
assert_equal('d29b8f49-10875-992421294-1', c0.value)
|
270
|
+
assert_equal(Time.at(2145801600), c0.expires)
|
271
|
+
assert_equal('www.zdnet.co.jp', c0.domain)
|
272
|
+
assert_equal('/', c0.path)
|
273
|
+
assert_equal(9, c0.flag)
|
274
|
+
#
|
275
|
+
assert_equal('http://www.zdnet.co.jp/news/0106/08/e_gibson.html', c1.url.to_s)
|
276
|
+
assert_equal('PACK', c1.name)
|
277
|
+
assert_equal('zd3-992421294-7436', c1.value)
|
278
|
+
assert_equal(Time.at(1293839999), c1.expires)
|
279
|
+
assert_equal('.zdnet.co.jp', c1.domain)
|
280
|
+
assert_equal('/', c1.path)
|
281
|
+
assert_equal(13, c1.flag)
|
282
|
+
#
|
283
|
+
assert_equal(nil, c2.expires)
|
284
|
+
assert_equal(nil, c3.expires) # allow empty 'expires' (should not happen)
|
285
|
+
ensure
|
286
|
+
File.unlink("tmp_test.tmp")
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
def test_save_cookie()
|
291
|
+
str = <<EOF
|
292
|
+
http://www.zdnet.co.jp/news/0106/08/e_gibson.html NGUserID d29b8f49-10875-992421294-1 2145801600 www.zdnet.co.jp / 9
|
293
|
+
http://www.zdnet.co.jp/news/0106/08/e_gibson.html PACK zd3-992421294-7436 2145801600 .zdnet.co.jp / 13
|
294
|
+
EOF
|
295
|
+
begin
|
296
|
+
File.open("tmp_test.tmp","w") {|f|
|
297
|
+
f.write str
|
298
|
+
}
|
299
|
+
@cm.cookies_file = 'tmp_test.tmp'
|
300
|
+
@cm.load_cookies()
|
301
|
+
@cm.instance_eval{@is_saved = false}
|
302
|
+
@cm.cookies_file = 'tmp_test2.tmp'
|
303
|
+
@cm.save_cookies()
|
304
|
+
str2 = ''
|
305
|
+
File.open("tmp_test2.tmp","r") {|f|
|
306
|
+
str2 = f.read()
|
307
|
+
}
|
308
|
+
assert_equal(str, str2)
|
309
|
+
#
|
310
|
+
assert(File.exist?('tmp_test2.tmp'))
|
311
|
+
File.unlink("tmp_test2.tmp")
|
312
|
+
@cm.save_cookies()
|
313
|
+
assert(!File.exist?('tmp_test2.tmp'))
|
314
|
+
@cm.save_cookies(true)
|
315
|
+
assert(File.exist?('tmp_test2.tmp'))
|
316
|
+
ensure
|
317
|
+
File.unlink("tmp_test.tmp")
|
318
|
+
if FileTest.exist?("tmp_test2.tmp")
|
319
|
+
File.unlink("tmp_test2.tmp")
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_not_saved_expired_cookies
|
325
|
+
begin
|
326
|
+
@cm.cookies_file = 'tmp_test.tmp'
|
327
|
+
uri = urify('http://www.example.org')
|
328
|
+
@cm.parse("foo=1; path=/", uri)
|
329
|
+
@cm.parse("bar=2; path=/; expires=", uri)
|
330
|
+
@cm.parse("baz=3; path=/; expires=\"\"", uri)
|
331
|
+
@cm.parse("qux=4; path=/; expires=#{(Time.now + 10).asctime}", uri)
|
332
|
+
@cm.parse("quxx=5; path=/; expires=#{(Time.now - 10).asctime}", uri)
|
333
|
+
@cm.save_cookies()
|
334
|
+
@cm.load_cookies
|
335
|
+
assert_equal(1, @cm.cookies.size) # +10 cookies only
|
336
|
+
ensure
|
337
|
+
File.unlink("tmp_test.tmp") if File.exist?("tmp_test.tmp")
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
def test_add()
|
342
|
+
c = WebAgent::Cookie.new()
|
343
|
+
c.name = "hoge"
|
344
|
+
c.value = "funi"
|
345
|
+
c.url = urify("http://www.inac.co.jp/hoge")
|
346
|
+
@cm.add(c)
|
347
|
+
c = @cm.cookies[0]
|
348
|
+
assert_equal('hoge', c.name)
|
349
|
+
assert_equal('funi', c.value)
|
350
|
+
assert_equal(nil, c.expires)
|
351
|
+
end
|
352
|
+
|
353
|
+
def test_add2()
|
354
|
+
c = WebAgent::Cookie.new()
|
355
|
+
c.name = "hoge"
|
356
|
+
c.value = "funi"
|
357
|
+
c.path = ''
|
358
|
+
c.url = urify("http://www.inac.co.jp/hoge/hoge2/hoge3")
|
359
|
+
@cm.add(c)
|
360
|
+
#
|
361
|
+
c = WebAgent::Cookie.new()
|
362
|
+
c.name = "hoge"
|
363
|
+
c.value = "funi"
|
364
|
+
#c.path = '' NO path given -> same as URL
|
365
|
+
c.url = urify("http://www.inac.co.jp/hoge/hoge2/hoge3")
|
366
|
+
@cm.add(c)
|
367
|
+
#
|
368
|
+
c1, c2 = @cm.cookies
|
369
|
+
assert_equal('', c1.path)
|
370
|
+
assert_equal('/hoge/hoge2', c2.path)
|
371
|
+
end
|
372
|
+
|
373
|
+
def test_check_cookie_accept_domain()
|
374
|
+
@cm.accept_domains = [".example1.co.jp", "www1.example.jp"]
|
375
|
+
@cm.reject_domains = [".example2.co.jp", "www2.example.jp"]
|
376
|
+
check1 = @cm.check_cookie_accept_domain("www.example1.co.jp")
|
377
|
+
assert_equal(true, check1)
|
378
|
+
check2 = @cm.check_cookie_accept_domain("www.example2.co.jp")
|
379
|
+
assert_equal(false, check2)
|
380
|
+
check3 = @cm.check_cookie_accept_domain("www1.example.jp")
|
381
|
+
assert_equal(true, check3)
|
382
|
+
check4 = @cm.check_cookie_accept_domain("www2.example.jp")
|
383
|
+
assert_equal(false, check4)
|
384
|
+
check5 = @cm.check_cookie_accept_domain("aa.www2.example.jp")
|
385
|
+
assert_equal(true, check5)
|
386
|
+
check6 = @cm.check_cookie_accept_domain("aa.www2.example.jp")
|
387
|
+
assert_equal(true, check6)
|
388
|
+
assert_equal(false, @cm.check_cookie_accept_domain(nil))
|
389
|
+
end
|
390
|
+
|
391
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('helper', File.dirname(__FILE__))
|
3
|
+
require 'hexdump'
|
4
|
+
|
5
|
+
|
6
|
+
class TestHexDump < Test::Unit::TestCase
|
7
|
+
def test_encode
|
8
|
+
str = "\032l\277\370\2429\216\236\351[{\{\262\350\274\376"
|
9
|
+
str.force_encoding('BINARY') if str.respond_to?(:force_encoding)
|
10
|
+
assert_equal(["00000000 1a6cbff8 a2398e9e e95b7b7b b2e8bcfe .l...9...[{{...."], HexDump.encode(str))
|
11
|
+
end
|
12
|
+
end if defined?(RUBY_ENGINE) && RUBY_ENGINE != "rbx" && RUBY_VERSION >= "1.9.0"
|
13
|
+
# Rubinius 1.8 mode does not support Regexp.quote(raw, 'n') I don't want put
|
14
|
+
# a pressure on supporting it because 1.9 mode works fine.
|
@@ -0,0 +1,507 @@
|
|
1
|
+
require 'http-access2'
|
2
|
+
require File.expand_path('helper', File.dirname(__FILE__))
|
3
|
+
|
4
|
+
|
5
|
+
module HTTPAccess2
|
6
|
+
|
7
|
+
|
8
|
+
class TestClient < Test::Unit::TestCase
|
9
|
+
include Helper
|
10
|
+
include HTTPClient::Util
|
11
|
+
|
12
|
+
def setup
|
13
|
+
super
|
14
|
+
setup_server
|
15
|
+
setup_client
|
16
|
+
end
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_initialize
|
23
|
+
setup_proxyserver
|
24
|
+
escape_noproxy do
|
25
|
+
@proxyio.string = ""
|
26
|
+
@client = HTTPAccess2::Client.new(proxyurl)
|
27
|
+
assert_equal(urify(proxyurl), @client.proxy)
|
28
|
+
assert_equal(200, @client.head(serverurl).status)
|
29
|
+
assert(!@proxyio.string.empty?)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_agent_name
|
34
|
+
@client = HTTPAccess2::Client.new(nil, "agent_name_foo")
|
35
|
+
str = ""
|
36
|
+
@client.debug_dev = str
|
37
|
+
@client.get(serverurl)
|
38
|
+
lines = str.split(/(?:\r?\n)+/)
|
39
|
+
assert_equal("= Request", lines[0])
|
40
|
+
assert_match(/^User-Agent: agent_name_foo/, lines[4])
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_from
|
44
|
+
@client = HTTPAccess2::Client.new(nil, nil, "from_bar")
|
45
|
+
str = ""
|
46
|
+
@client.debug_dev = str
|
47
|
+
@client.get(serverurl)
|
48
|
+
lines = str.split(/(?:\r?\n)+/)
|
49
|
+
assert_equal("= Request", lines[0])
|
50
|
+
assert_match(/^From: from_bar/, lines[5])
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_debug_dev
|
54
|
+
str = ""
|
55
|
+
@client.debug_dev = str
|
56
|
+
assert(str.empty?)
|
57
|
+
@client.get(serverurl)
|
58
|
+
assert(!str.empty?)
|
59
|
+
end
|
60
|
+
|
61
|
+
def _test_protocol_version_http09
|
62
|
+
@client.protocol_version = 'HTTP/0.9'
|
63
|
+
str = ""
|
64
|
+
@client.debug_dev = str
|
65
|
+
@client.get(serverurl + 'hello')
|
66
|
+
lines = str.split(/(?:\r?\n)+/)
|
67
|
+
assert_equal("= Request", lines[0])
|
68
|
+
assert_equal("! CONNECTION ESTABLISHED", lines[2])
|
69
|
+
assert_equal("GET /hello HTTP/0.9", lines[3])
|
70
|
+
assert_equal("Connection: close", lines[5])
|
71
|
+
assert_equal("= Response", lines[6])
|
72
|
+
assert_match(/^hello/, lines[7])
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_protocol_version_http10
|
76
|
+
@client.protocol_version = 'HTTP/1.0'
|
77
|
+
str = ""
|
78
|
+
@client.debug_dev = str
|
79
|
+
@client.get(serverurl + 'hello')
|
80
|
+
lines = str.split(/(?:\r?\n)+/)
|
81
|
+
assert_equal("= Request", lines[0])
|
82
|
+
assert_equal("! CONNECTION ESTABLISHED", lines[2])
|
83
|
+
assert_equal("GET /hello HTTP/1.0", lines[3])
|
84
|
+
assert_equal("Connection: close", lines[7])
|
85
|
+
assert_equal("= Response", lines[8])
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_protocol_version_http11
|
89
|
+
str = ""
|
90
|
+
@client.debug_dev = str
|
91
|
+
@client.get(serverurl)
|
92
|
+
lines = str.split(/(?:\r?\n)+/)
|
93
|
+
assert_equal("= Request", lines[0])
|
94
|
+
assert_equal("! CONNECTION ESTABLISHED", lines[2])
|
95
|
+
assert_equal("GET / HTTP/1.1", lines[3])
|
96
|
+
assert_equal("Host: localhost:#{serverport}", lines[7])
|
97
|
+
@client.protocol_version = 'HTTP/1.1'
|
98
|
+
str = ""
|
99
|
+
@client.debug_dev = str
|
100
|
+
@client.get(serverurl)
|
101
|
+
lines = str.split(/(?:\r?\n)+/)
|
102
|
+
assert_equal("= Request", lines[0])
|
103
|
+
assert_equal("! CONNECTION ESTABLISHED", lines[2])
|
104
|
+
assert_equal("GET / HTTP/1.1", lines[3])
|
105
|
+
@client.protocol_version = 'HTTP/1.0'
|
106
|
+
str = ""
|
107
|
+
@client.debug_dev = str
|
108
|
+
@client.get(serverurl)
|
109
|
+
lines = str.split(/(?:\r?\n)+/)
|
110
|
+
assert_equal("= Request", lines[0])
|
111
|
+
assert_equal("! CONNECTION ESTABLISHED", lines[2])
|
112
|
+
assert_equal("GET / HTTP/1.0", lines[3])
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_proxy
|
116
|
+
setup_proxyserver
|
117
|
+
escape_noproxy do
|
118
|
+
begin
|
119
|
+
@client.proxy = "http://"
|
120
|
+
rescue
|
121
|
+
assert_match(/InvalidURIError/, $!.class.to_s)
|
122
|
+
end
|
123
|
+
@client.proxy = ""
|
124
|
+
assert_nil(@client.proxy)
|
125
|
+
@client.proxy = "http://foo:1234"
|
126
|
+
assert_equal(urify("http://foo:1234"), @client.proxy)
|
127
|
+
uri = urify("http://bar:2345")
|
128
|
+
@client.proxy = uri
|
129
|
+
assert_equal(uri, @client.proxy)
|
130
|
+
#
|
131
|
+
@proxyio.string = ""
|
132
|
+
@client.proxy = nil
|
133
|
+
assert_equal(200, @client.head(serverurl).status)
|
134
|
+
assert(@proxyio.string.empty?)
|
135
|
+
#
|
136
|
+
@proxyio.string = ""
|
137
|
+
@client.proxy = proxyurl
|
138
|
+
assert_equal(200, @client.head(serverurl).status)
|
139
|
+
assert(!@proxyio.string.empty?)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_noproxy_for_localhost
|
144
|
+
@proxyio.string = ""
|
145
|
+
@client.proxy = proxyurl
|
146
|
+
assert_equal(200, @client.head(serverurl).status)
|
147
|
+
assert(@proxyio.string.empty?)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_no_proxy
|
151
|
+
setup_proxyserver
|
152
|
+
escape_noproxy do
|
153
|
+
# proxy is not set.
|
154
|
+
@client.no_proxy = 'localhost'
|
155
|
+
@proxyio.string = ""
|
156
|
+
@client.proxy = nil
|
157
|
+
assert_equal(200, @client.head(serverurl).status)
|
158
|
+
assert(/accept/ !~ @proxyio.string)
|
159
|
+
#
|
160
|
+
@proxyio.string = ""
|
161
|
+
@client.proxy = proxyurl
|
162
|
+
assert_equal(200, @client.head(serverurl).status)
|
163
|
+
assert(/accept/ !~ @proxyio.string)
|
164
|
+
#
|
165
|
+
@client.no_proxy = 'foobar'
|
166
|
+
@proxyio.string = ""
|
167
|
+
@client.proxy = proxyurl
|
168
|
+
assert_equal(200, @client.head(serverurl).status)
|
169
|
+
assert(/accept/ =~ @proxyio.string)
|
170
|
+
#
|
171
|
+
@client.no_proxy = 'foobar,localhost:baz'
|
172
|
+
@proxyio.string = ""
|
173
|
+
@client.proxy = proxyurl
|
174
|
+
assert_equal(200, @client.head(serverurl).status)
|
175
|
+
assert(/accept/ !~ @proxyio.string)
|
176
|
+
#
|
177
|
+
@client.no_proxy = 'foobar,localhost:443'
|
178
|
+
@proxyio.string = ""
|
179
|
+
@client.proxy = proxyurl
|
180
|
+
assert_equal(200, @client.head(serverurl).status)
|
181
|
+
assert(/accept/ =~ @proxyio.string)
|
182
|
+
#
|
183
|
+
@client.no_proxy = "foobar,localhost:443:localhost:#{serverport},baz"
|
184
|
+
@proxyio.string = ""
|
185
|
+
@client.proxy = proxyurl
|
186
|
+
assert_equal(200, @client.head(serverurl).status)
|
187
|
+
assert(/accept/ !~ @proxyio.string)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_get_content
|
192
|
+
assert_equal('hello', @client.get_content(serverurl + 'hello'))
|
193
|
+
assert_equal('hello', @client.get_content(serverurl + 'redirect1'))
|
194
|
+
assert_equal('hello', @client.get_content(serverurl + 'redirect2'))
|
195
|
+
assert_raises(HTTPClient::Session::BadResponse) do
|
196
|
+
@client.get_content(serverurl + 'notfound')
|
197
|
+
end
|
198
|
+
assert_raises(HTTPClient::Session::BadResponse) do
|
199
|
+
@client.get_content(serverurl + 'redirect_self')
|
200
|
+
end
|
201
|
+
called = false
|
202
|
+
@client.redirect_uri_callback = lambda { |uri, res|
|
203
|
+
newuri = res.header['location'][0]
|
204
|
+
called = true
|
205
|
+
newuri
|
206
|
+
}
|
207
|
+
assert_equal('hello', @client.get_content(serverurl + 'relative_redirect'))
|
208
|
+
assert(called)
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_post_content
|
212
|
+
assert_equal('hello', @client.post_content(serverurl + 'hello'))
|
213
|
+
assert_equal('hello', @client.post_content(serverurl + 'redirect1'))
|
214
|
+
assert_equal('hello', @client.post_content(serverurl + 'redirect2'))
|
215
|
+
assert_raises(HTTPClient::Session::BadResponse) do
|
216
|
+
@client.post_content(serverurl + 'notfound')
|
217
|
+
end
|
218
|
+
assert_raises(HTTPClient::Session::BadResponse) do
|
219
|
+
@client.post_content(serverurl + 'redirect_self')
|
220
|
+
end
|
221
|
+
called = false
|
222
|
+
@client.redirect_uri_callback = lambda { |uri, res|
|
223
|
+
newuri = res.header['location'][0]
|
224
|
+
called = true
|
225
|
+
newuri
|
226
|
+
}
|
227
|
+
assert_equal('hello', @client.post_content(serverurl + 'relative_redirect'))
|
228
|
+
assert(called)
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_head
|
232
|
+
assert_equal("head", @client.head(serverurl + 'servlet').header["x-head"][0])
|
233
|
+
param = {'1'=>'2', '3'=>'4'}
|
234
|
+
res = @client.head(serverurl + 'servlet', param)
|
235
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_get
|
239
|
+
assert_equal("get", @client.get(serverurl + 'servlet').content)
|
240
|
+
param = {'1'=>'2', '3'=>'4'}
|
241
|
+
res = @client.get(serverurl + 'servlet', param)
|
242
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_post
|
246
|
+
assert_equal("post", @client.post(serverurl + 'servlet').content)
|
247
|
+
param = {'1'=>'2', '3'=>'4'}
|
248
|
+
res = @client.get(serverurl + 'servlet', param)
|
249
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_put
|
253
|
+
assert_equal("put", @client.put(serverurl + 'servlet').content)
|
254
|
+
param = {'1'=>'2', '3'=>'4'}
|
255
|
+
res = @client.get(serverurl + 'servlet', param)
|
256
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_delete
|
260
|
+
assert_equal("delete", @client.delete(serverurl + 'servlet').content)
|
261
|
+
param = {'1'=>'2', '3'=>'4'}
|
262
|
+
res = @client.get(serverurl + 'servlet', param)
|
263
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_options
|
267
|
+
assert_equal("options", @client.options(serverurl + 'servlet').content)
|
268
|
+
param = {'1'=>'2', '3'=>'4'}
|
269
|
+
res = @client.get(serverurl + 'servlet', param)
|
270
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_trace
|
274
|
+
assert_equal("trace", @client.trace(serverurl + 'servlet').content)
|
275
|
+
param = {'1'=>'2', '3'=>'4'}
|
276
|
+
res = @client.get(serverurl + 'servlet', param)
|
277
|
+
assert_equal(param, params(res.header["x-query"][0]))
|
278
|
+
end
|
279
|
+
|
280
|
+
def test_get_query
|
281
|
+
assert_equal({'1'=>'2'}, check_query_get({1=>2}))
|
282
|
+
assert_equal({'a'=>'A', 'B'=>'b'}, check_query_get({"a"=>"A", "B"=>"b"}))
|
283
|
+
assert_equal({'&'=>'&'}, check_query_get({"&"=>"&"}))
|
284
|
+
assert_equal({'= '=>' =+'}, check_query_get({"= "=>" =+"}))
|
285
|
+
assert_equal(
|
286
|
+
['=', '&'].sort,
|
287
|
+
check_query_get([["=", "="], ["=", "&"]])['='].to_ary.sort
|
288
|
+
)
|
289
|
+
assert_equal({'123'=>'45'}, check_query_get('123=45'))
|
290
|
+
assert_equal({'12 3'=>'45', ' '=>' '}, check_query_get('12+3=45&+=+'))
|
291
|
+
assert_equal({}, check_query_get(''))
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_post_body
|
295
|
+
assert_equal({'1'=>'2'}, check_query_post({1=>2}))
|
296
|
+
assert_equal({'a'=>'A', 'B'=>'b'}, check_query_post({"a"=>"A", "B"=>"b"}))
|
297
|
+
assert_equal({'&'=>'&'}, check_query_post({"&"=>"&"}))
|
298
|
+
assert_equal({'= '=>' =+'}, check_query_post({"= "=>" =+"}))
|
299
|
+
assert_equal(
|
300
|
+
['=', '&'].sort,
|
301
|
+
check_query_post([["=", "="], ["=", "&"]])['='].to_ary.sort
|
302
|
+
)
|
303
|
+
assert_equal({'123'=>'45'}, check_query_post('123=45'))
|
304
|
+
assert_equal({'12 3'=>'45', ' '=>' '}, check_query_post('12+3=45&+=+'))
|
305
|
+
assert_equal({}, check_query_post(''))
|
306
|
+
#
|
307
|
+
post_body = StringIO.new("foo=bar&foo=baz")
|
308
|
+
assert_equal(
|
309
|
+
["bar", "baz"],
|
310
|
+
check_query_post(post_body)["foo"].to_ary.sort
|
311
|
+
)
|
312
|
+
end
|
313
|
+
|
314
|
+
def test_extra_headers
|
315
|
+
str = ""
|
316
|
+
@client.debug_dev = str
|
317
|
+
@client.head(serverurl, nil, {"ABC" => "DEF"})
|
318
|
+
lines = str.split(/(?:\r?\n)+/)
|
319
|
+
assert_equal("= Request", lines[0])
|
320
|
+
assert_match("ABC: DEF", lines[4])
|
321
|
+
#
|
322
|
+
str = ""
|
323
|
+
@client.debug_dev = str
|
324
|
+
@client.get(serverurl, nil, [["ABC", "DEF"], ["ABC", "DEF"]])
|
325
|
+
lines = str.split(/(?:\r?\n)+/)
|
326
|
+
assert_equal("= Request", lines[0])
|
327
|
+
assert_match("ABC: DEF", lines[4])
|
328
|
+
assert_match("ABC: DEF", lines[5])
|
329
|
+
end
|
330
|
+
|
331
|
+
def test_timeout
|
332
|
+
assert_equal(60, @client.connect_timeout)
|
333
|
+
assert_equal(120, @client.send_timeout)
|
334
|
+
assert_equal(60, @client.receive_timeout)
|
335
|
+
end
|
336
|
+
|
337
|
+
def test_connect_timeout
|
338
|
+
# ToDo
|
339
|
+
end
|
340
|
+
|
341
|
+
def test_send_timeout
|
342
|
+
# ToDo
|
343
|
+
end
|
344
|
+
|
345
|
+
def test_receive_timeout
|
346
|
+
# this test takes 2 sec
|
347
|
+
assert_equal('hello', @client.get_content(serverurl + 'sleep?sec=2'))
|
348
|
+
@client.receive_timeout = 1
|
349
|
+
assert_equal('hello', @client.get_content(serverurl + 'sleep?sec=0'))
|
350
|
+
assert_raise(HTTPClient::ReceiveTimeoutError) do
|
351
|
+
@client.get_content(serverurl + 'sleep?sec=2')
|
352
|
+
end
|
353
|
+
@client.receive_timeout = 3
|
354
|
+
assert_equal('hello', @client.get_content(serverurl + 'sleep?sec=2'))
|
355
|
+
end
|
356
|
+
|
357
|
+
def test_cookies
|
358
|
+
cookiefile = File.join(File.dirname(File.expand_path(__FILE__)),
|
359
|
+
'test_cookies_file')
|
360
|
+
# from [ruby-talk:164079]
|
361
|
+
File.open(cookiefile, "wb") do |f|
|
362
|
+
f << "http://rubyforge.org//account/login.php session_ser LjEwMy45Ni40Ni0q%2A-fa0537de8cc31 1131676286 .rubyforge.org / 13\n"
|
363
|
+
end
|
364
|
+
cm = WebAgent::CookieManager::new(cookiefile)
|
365
|
+
cm.load_cookies
|
366
|
+
cookie = cm.cookies.first
|
367
|
+
url = cookie.url
|
368
|
+
assert(cookie.domain_match(url.host, cookie.domain))
|
369
|
+
end
|
370
|
+
|
371
|
+
private
|
372
|
+
|
373
|
+
def check_query_get(query)
|
374
|
+
WEBrick::HTTPUtils.parse_query(
|
375
|
+
@client.get(serverurl + 'servlet', query).header["x-query"][0]
|
376
|
+
)
|
377
|
+
end
|
378
|
+
|
379
|
+
def check_query_post(query)
|
380
|
+
WEBrick::HTTPUtils.parse_query(
|
381
|
+
@client.post(serverurl + 'servlet', query).header["x-query"][0]
|
382
|
+
)
|
383
|
+
end
|
384
|
+
|
385
|
+
def setup_server
|
386
|
+
@server = WEBrick::HTTPServer.new(
|
387
|
+
:BindAddress => "localhost",
|
388
|
+
:Logger => @logger,
|
389
|
+
:Port => 0,
|
390
|
+
:AccessLog => [],
|
391
|
+
:DocumentRoot => File.dirname(File.expand_path(__FILE__))
|
392
|
+
)
|
393
|
+
@serverport = @server.config[:Port]
|
394
|
+
[:hello, :sleep, :redirect1, :redirect2, :redirect3, :redirect_self, :relative_redirect].each do |sym|
|
395
|
+
@server.mount(
|
396
|
+
"/#{sym}",
|
397
|
+
WEBrick::HTTPServlet::ProcHandler.new(method("do_#{sym}").to_proc)
|
398
|
+
)
|
399
|
+
end
|
400
|
+
@server.mount('/servlet', TestServlet.new(@server))
|
401
|
+
@server_thread = start_server_thread(@server)
|
402
|
+
end
|
403
|
+
|
404
|
+
def escape_noproxy
|
405
|
+
backup = HTTPAccess2::Client::NO_PROXY_HOSTS.dup
|
406
|
+
HTTPAccess2::Client::NO_PROXY_HOSTS.clear
|
407
|
+
yield
|
408
|
+
ensure
|
409
|
+
HTTPAccess2::Client::NO_PROXY_HOSTS.replace(backup)
|
410
|
+
end
|
411
|
+
|
412
|
+
def do_hello(req, res)
|
413
|
+
res['content-type'] = 'text/html'
|
414
|
+
res.body = "hello"
|
415
|
+
end
|
416
|
+
|
417
|
+
def do_sleep(req, res)
|
418
|
+
sec = req.query['sec'].to_i
|
419
|
+
sleep sec
|
420
|
+
res['content-type'] = 'text/html'
|
421
|
+
res.body = "hello"
|
422
|
+
end
|
423
|
+
|
424
|
+
def do_redirect1(req, res)
|
425
|
+
res.set_redirect(WEBrick::HTTPStatus::MovedPermanently, serverurl + "hello")
|
426
|
+
end
|
427
|
+
|
428
|
+
def do_redirect2(req, res)
|
429
|
+
res.set_redirect(WEBrick::HTTPStatus::TemporaryRedirect, serverurl + "redirect3")
|
430
|
+
end
|
431
|
+
|
432
|
+
def do_redirect3(req, res)
|
433
|
+
res.set_redirect(WEBrick::HTTPStatus::Found, serverurl + "hello")
|
434
|
+
end
|
435
|
+
|
436
|
+
def do_redirect_self(req, res)
|
437
|
+
res.set_redirect(WEBrick::HTTPStatus::Found, serverurl + "redirect_self")
|
438
|
+
end
|
439
|
+
|
440
|
+
def do_relative_redirect(req, res)
|
441
|
+
res.set_redirect(WEBrick::HTTPStatus::Found, "hello")
|
442
|
+
end
|
443
|
+
|
444
|
+
class TestServlet < WEBrick::HTTPServlet::AbstractServlet
|
445
|
+
def get_instance(*arg)
|
446
|
+
self
|
447
|
+
end
|
448
|
+
|
449
|
+
def do_HEAD(req, res)
|
450
|
+
res["x-head"] = 'head' # use this for test purpose only.
|
451
|
+
res["x-query"] = query_response(req)
|
452
|
+
end
|
453
|
+
|
454
|
+
def do_GET(req, res)
|
455
|
+
res.body = 'get'
|
456
|
+
res["x-query"] = query_response(req)
|
457
|
+
end
|
458
|
+
|
459
|
+
def do_POST(req, res)
|
460
|
+
res.body = 'post'
|
461
|
+
res["x-query"] = body_response(req)
|
462
|
+
end
|
463
|
+
|
464
|
+
def do_PUT(req, res)
|
465
|
+
res.body = 'put'
|
466
|
+
end
|
467
|
+
|
468
|
+
def do_DELETE(req, res)
|
469
|
+
res.body = 'delete'
|
470
|
+
end
|
471
|
+
|
472
|
+
def do_OPTIONS(req, res)
|
473
|
+
# check RFC for legal response.
|
474
|
+
res.body = 'options'
|
475
|
+
end
|
476
|
+
|
477
|
+
def do_TRACE(req, res)
|
478
|
+
# client SHOULD reflect the message received back to the client as the
|
479
|
+
# entity-body of a 200 (OK) response. [RFC2616]
|
480
|
+
res.body = 'trace'
|
481
|
+
res["x-query"] = query_response(req)
|
482
|
+
end
|
483
|
+
|
484
|
+
private
|
485
|
+
|
486
|
+
def query_response(req)
|
487
|
+
query_escape(WEBrick::HTTPUtils.parse_query(req.query_string))
|
488
|
+
end
|
489
|
+
|
490
|
+
def body_response(req)
|
491
|
+
query_escape(WEBrick::HTTPUtils.parse_query(req.body))
|
492
|
+
end
|
493
|
+
|
494
|
+
def query_escape(query)
|
495
|
+
escaped = []
|
496
|
+
query.collect do |k, v|
|
497
|
+
v.to_ary.each do |ve|
|
498
|
+
escaped << CGI.escape(k) + '=' + CGI.escape(ve)
|
499
|
+
end
|
500
|
+
end
|
501
|
+
escaped.join('&')
|
502
|
+
end
|
503
|
+
end
|
504
|
+
end
|
505
|
+
|
506
|
+
|
507
|
+
end
|