glebtv-httpclient 3.2.3 → 3.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -0
- data/Gemfile.lock +14 -17
- data/httpclient.gemspec +8 -8
- data/lib/httpclient/version.rb +1 -1
- data/spec/cookie_spec.rb +398 -0
- data/spec/support/ht_helpers.rb +1 -0
- metadata +27 -29
- data/CHANGELOG.rdoc +0 -653
- data/test/test_cookie.rb +0 -412
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67da2be91a12b0b8e107d865eea78fca6118bf5c
|
4
|
+
data.tar.gz: 9ffc63296d22b328aab17af7832060cd3894c1f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78f6a87dfda29f7ee7cf46d812b6b3af37419ebf9088898c6b994c129a2e4b4692cfd19f276dfba61c71a590a0a0795f0c50f1d702d6b8251c032014d7b805d2
|
7
|
+
data.tar.gz: 97e997886c7c72cb855783e94bd95b2cd8425af4f72e5d178c4dc1846dd6451d680cef33cfaa4d7fd632b90e22aca106dec5ec237546a03fa30a03a5a2cf6c8f
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.1.1
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -14,13 +14,13 @@ GEM
|
|
14
14
|
term-ansicolor
|
15
15
|
thor
|
16
16
|
diff-lcs (1.2.5)
|
17
|
-
docile (1.1.
|
17
|
+
docile (1.1.3)
|
18
18
|
ffi2-generators (0.1.1)
|
19
19
|
json (1.8.1)
|
20
20
|
lru_redux (0.8.1)
|
21
|
-
mime-types (2.
|
22
|
-
multi_json (1.
|
23
|
-
rake (10.
|
21
|
+
mime-types (2.2)
|
22
|
+
multi_json (1.9.2)
|
23
|
+
rake (10.2.2)
|
24
24
|
rdoc (4.1.1)
|
25
25
|
json (~> 1.4)
|
26
26
|
rest-client (1.6.7)
|
@@ -29,15 +29,12 @@ GEM
|
|
29
29
|
rspec-core (~> 2.14.0)
|
30
30
|
rspec-expectations (~> 2.14.0)
|
31
31
|
rspec-mocks (~> 2.14.0)
|
32
|
-
rspec-core (2.14.
|
32
|
+
rspec-core (2.14.8)
|
33
33
|
rspec-expectations (2.14.5)
|
34
34
|
diff-lcs (>= 1.1.3, < 2.0)
|
35
|
-
rspec-mocks (2.14.
|
36
|
-
rubinius-compiler (2.0.4)
|
35
|
+
rspec-mocks (2.14.6)
|
37
36
|
rubinius-coverage (2.0.3)
|
38
|
-
rubinius-debugger (2.0.
|
39
|
-
rubinius-compiler (~> 2.0)
|
40
|
-
rubysl-readline (~> 2.0)
|
37
|
+
rubinius-debugger (2.0.3)
|
41
38
|
rubinius-developer_tools (2.0.0)
|
42
39
|
rubinius-coverage (~> 2.0)
|
43
40
|
rubinius-debugger (~> 2.0)
|
@@ -206,7 +203,7 @@ GEM
|
|
206
203
|
rubysl-shellwords (~> 2.0)
|
207
204
|
rubysl-ostruct (2.0.4)
|
208
205
|
rubysl-pathname (2.0.0)
|
209
|
-
rubysl-prettyprint (2.0.
|
206
|
+
rubysl-prettyprint (2.0.3)
|
210
207
|
rubysl-prime (2.0.1)
|
211
208
|
rubysl-profile (2.0.0)
|
212
209
|
rubysl-profiler (2.0.1)
|
@@ -214,7 +211,7 @@ GEM
|
|
214
211
|
rubysl-pty (2.0.2)
|
215
212
|
rubysl-rational (2.0.1)
|
216
213
|
rubysl-readline (2.0.2)
|
217
|
-
rubysl-resolv (2.
|
214
|
+
rubysl-resolv (2.1.0)
|
218
215
|
rubysl-rexml (2.0.2)
|
219
216
|
rubysl-rinda (2.0.1)
|
220
217
|
rubysl-rss (2.0.0)
|
@@ -234,7 +231,7 @@ GEM
|
|
234
231
|
rubysl-thwait (2.0.0)
|
235
232
|
rubysl-time (2.0.3)
|
236
233
|
rubysl-timeout (2.0.0)
|
237
|
-
rubysl-tmpdir (2.0.
|
234
|
+
rubysl-tmpdir (2.0.1)
|
238
235
|
rubysl-tsort (2.0.1)
|
239
236
|
rubysl-un (2.0.0)
|
240
237
|
rubysl-fileutils (~> 2.0)
|
@@ -250,11 +247,11 @@ GEM
|
|
250
247
|
multi_json
|
251
248
|
simplecov-html (~> 0.8.0)
|
252
249
|
simplecov-html (0.8.0)
|
253
|
-
term-ansicolor (1.
|
254
|
-
tins (~> 0
|
250
|
+
term-ansicolor (1.3.0)
|
251
|
+
tins (~> 1.0)
|
255
252
|
test-unit (2.5.5)
|
256
|
-
thor (0.
|
257
|
-
tins (
|
253
|
+
thor (0.19.1)
|
254
|
+
tins (1.1.0)
|
258
255
|
|
259
256
|
PLATFORMS
|
260
257
|
ruby
|
data/httpclient.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.executables = ['httpclient']
|
12
12
|
spec.homepage = 'http://github.com/glebtv/httpclient'
|
13
13
|
spec.platform = Gem::Platform::RUBY
|
14
|
-
spec.summary = 'Fork of httpclient with some fixes and patches I needed.
|
14
|
+
spec.summary = 'Fork of httpclient with some fixes and patches I needed.'
|
15
15
|
|
16
16
|
spec.license = 'ruby'
|
17
17
|
|
@@ -20,12 +20,12 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_dependency
|
23
|
+
spec.add_dependency 'lru_redux'
|
24
24
|
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
25
|
+
spec.add_development_dependency 'bundler'
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'test-unit'
|
28
|
+
spec.add_development_dependency 'rspec'
|
29
|
+
spec.add_development_dependency 'rdoc'
|
30
|
+
spec.add_development_dependency 'coveralls'
|
31
31
|
end
|
data/lib/httpclient/version.rb
CHANGED
data/spec/cookie_spec.rb
ADDED
@@ -0,0 +1,398 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
require 'uri'
|
5
|
+
require 'httpclient/cookie'
|
6
|
+
|
7
|
+
describe 'Cookies' do
|
8
|
+
before :each do
|
9
|
+
@c = WebAgent::Cookie.new()
|
10
|
+
end
|
11
|
+
|
12
|
+
it { @c.should be_an_instance_of WebAgent::Cookie }
|
13
|
+
|
14
|
+
it '#discard' do
|
15
|
+
(!!@c.discard?).should be_false
|
16
|
+
@c.discard = true
|
17
|
+
(!!@c.discard?).should be_true
|
18
|
+
end
|
19
|
+
|
20
|
+
it '#match?' do
|
21
|
+
url = urify('http://www.rubycolor.org/hoge/funi/#919191')
|
22
|
+
|
23
|
+
@c.domain = 'www.rubycolor.org'
|
24
|
+
@c.match?(url).should be_true
|
25
|
+
|
26
|
+
@c.domain = '.rubycolor.org'
|
27
|
+
@c.match?(url).should be_true
|
28
|
+
|
29
|
+
@c.domain = 'aaa.www.rubycolor.org'
|
30
|
+
@c.match?(url).should be_false
|
31
|
+
|
32
|
+
@c.domain = 'aaa.www.rubycolor.org'
|
33
|
+
@c.match?(url).should be_false
|
34
|
+
|
35
|
+
@c.domain = 'www.rubycolor.org'
|
36
|
+
@c.path = '/'
|
37
|
+
@c.match?(url).should be_true
|
38
|
+
|
39
|
+
@c.domain = 'www.rubycolor.org'
|
40
|
+
@c.path = '/hoge'
|
41
|
+
@c.match?(url).should be_true
|
42
|
+
|
43
|
+
@c.domain = 'www.rubycolor.org'
|
44
|
+
@c.path = '/hoge/hoge'
|
45
|
+
@c.match?(url).should be_false
|
46
|
+
|
47
|
+
@c.domain = 'www.rubycolor.org'
|
48
|
+
@c.path = '/hoge'
|
49
|
+
@c.secure = true
|
50
|
+
@c.match?(url).should be_false
|
51
|
+
|
52
|
+
url2 = urify('https://www.rubycolor.org/hoge/funi/#919191')
|
53
|
+
@c.domain = 'www.rubycolor.org'
|
54
|
+
@c.path = '/hoge'
|
55
|
+
@c.secure = true
|
56
|
+
@c.match?(url2).should be_true
|
57
|
+
|
58
|
+
@c.domain = 'www.rubycolor.org'
|
59
|
+
@c.path = '/hoge'
|
60
|
+
@c.secure = nil
|
61
|
+
@c.match?(url2).should be_true
|
62
|
+
|
63
|
+
url.port = 80
|
64
|
+
@c.domain = 'www.rubycolor.org'
|
65
|
+
@c.path = '/hoge'
|
66
|
+
@c.match?(url).should be_true
|
67
|
+
|
68
|
+
url_nopath = URI.parse('http://www.rubycolor.org')
|
69
|
+
@c.domain = 'www.rubycolor.org'
|
70
|
+
@c.path = '/'
|
71
|
+
@c.match?(url_nopath).should be_true
|
72
|
+
end
|
73
|
+
|
74
|
+
it '#head_match?' do
|
75
|
+
@c.head_match?("","").should be_true
|
76
|
+
@c.head_match?("a","").should be_false
|
77
|
+
@c.head_match?("","a").should be_true
|
78
|
+
@c.head_match?("abcde","abcde").should be_true
|
79
|
+
@c.head_match?("abcde","abcdef").should be_true
|
80
|
+
@c.head_match?("abcdef","abcde").should be_false
|
81
|
+
@c.head_match?("abcde","bcde").should be_false
|
82
|
+
@c.head_match?("bcde","abcde").should be_false
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'tail_match?' do
|
86
|
+
@c.tail_match?("","").should be_true
|
87
|
+
@c.tail_match?("a","").should be_false
|
88
|
+
@c.tail_match?("","a").should be_true
|
89
|
+
@c.tail_match?("abcde","abcde").should be_true
|
90
|
+
@c.tail_match?("abcde","abcdef").should be_false
|
91
|
+
@c.tail_match?("abcdef","abcde").should be_false
|
92
|
+
@c.tail_match?("abcde","bcde").should be_false
|
93
|
+
@c.tail_match?("bcde","abcde").should be_true
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
it 'domain_match' do
|
98
|
+
extend WebAgent::CookieUtils
|
99
|
+
(!!domain_match("hoge.co.jp",".")).should be_true
|
100
|
+
(!!domain_match("192.168.10.1","192.168.10.1")).should be_true
|
101
|
+
(!!domain_match("192.168.10.1","192.168.10.2")).should be_false
|
102
|
+
(!!domain_match("hoge.co.jp",".hoge.co.jp")).should be_true
|
103
|
+
(!!domain_match("www.hoge.co.jp", "www.hoge.co.jp")).should be_true
|
104
|
+
(!!domain_match("www.hoge.co.jp", "www2.hoge.co.jp")).should be_false
|
105
|
+
(!!domain_match("www.hoge.co.jp", ".hoge.co.jp")).should be_true
|
106
|
+
(!!domain_match("www.aa.hoge.co.jp", ".hoge.co.jp")).should be_true
|
107
|
+
(!!domain_match("www.hoge.co.jp", "hoge.co.jp")).should be_false
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'join_quotedstr' do
|
111
|
+
arr1 = ['hoge=funi', 'hoge2=funi2']
|
112
|
+
arr1.should eq @c.instance_eval{join_quotedstr(arr1,';')}
|
113
|
+
arr2 = ['hoge="fu', 'ni"', 'funi=funi']
|
114
|
+
['hoge="fu;ni"','funi=funi'].should eq @c.instance_eval{join_quotedstr(arr2,';')}
|
115
|
+
arr3 = ['hoge="funi";hoge2="fu','ni2";hoge3="hoge"', 'funi="funi"']
|
116
|
+
['hoge="funi";hoge2="fu,ni2";hoge3="hoge"', 'funi="funi"'].should eq @c.instance_eval{join_quotedstr(arr3,',')}
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
describe 'CookieManager' do
|
122
|
+
before :each do
|
123
|
+
@cm = WebAgent::CookieManager.new()
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'parse' do
|
127
|
+
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=Wed, 01-Dec-2010 00:00:00 GMT; path=/"
|
128
|
+
@cm.parse(str, urify('http://www.test.jp'))
|
129
|
+
cookie = @cm.cookies[0]
|
130
|
+
cookie.should be_an_instance_of WebAgent::Cookie
|
131
|
+
cookie.name.should eq "inkid"
|
132
|
+
cookie.value.should eq "n92b0ADOgACIgUb9lsjHqAAAHu2a"
|
133
|
+
cookie.expires.should eq Time.gm(2010, 12, 1, 0,0,0)
|
134
|
+
cookie.path.should eq "/"
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'parse2' do
|
138
|
+
str = "xmen=off,0,0,1; path=/; domain=.excite.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
|
139
|
+
@cm.parse(str, urify('http://www.excite.co.jp'))
|
140
|
+
cookie = @cm.cookies[0]
|
141
|
+
cookie.should be_an_instance_of WebAgent::Cookie
|
142
|
+
cookie.name.should eq "xmen"
|
143
|
+
cookie.value.should eq "off,0,0,1"
|
144
|
+
cookie.domain.should eq ".excite.co.jp"
|
145
|
+
cookie.expires.should eq Time.gm(2037,12,31,12,0,0)
|
146
|
+
cookie.path.should eq "/"
|
147
|
+
|
148
|
+
cookie.secure?.should be_false
|
149
|
+
cookie.http_only?.should be_false
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'parse3' do
|
153
|
+
str = "xmen=off,0,0,1; path=/; domain=.excite.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT;Secure;HTTPOnly"
|
154
|
+
@cm.parse(str, urify('http://www.excite.co.jp'))
|
155
|
+
cookie = @cm.cookies[0]
|
156
|
+
cookie.should be_an_instance_of WebAgent::Cookie
|
157
|
+
cookie.name.should eq "xmen"
|
158
|
+
cookie.value.should eq "off,0,0,1"
|
159
|
+
cookie.domain.should eq ".excite.co.jp"
|
160
|
+
cookie.expires.should eq Time.gm(2037,12,31,12,0,0)
|
161
|
+
cookie.path.should eq "/"
|
162
|
+
cookie.secure?.should be_true
|
163
|
+
cookie.http_only?.should be_true
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'parse_double_semicolon' do
|
167
|
+
str = "xmen=off,0,0,1;; path=\"/;;\"; domain=.excite.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
|
168
|
+
@cm.parse(str, urify('http://www.excite.co.jp'))
|
169
|
+
cookie = @cm.cookies[0]
|
170
|
+
cookie.should be_an_instance_of WebAgent::Cookie
|
171
|
+
cookie.name.should eq "xmen"
|
172
|
+
cookie.value.should eq "off,0,0,1"
|
173
|
+
cookie.domain.should eq ".excite.co.jp"
|
174
|
+
cookie.expires.should eq Time.gm(2037,12,31,12,0,0)
|
175
|
+
cookie.path.should eq "/;;"
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'check_expired_cookies' do
|
179
|
+
c1 = WebAgent::Cookie.new()
|
180
|
+
c2 = c1.dup
|
181
|
+
c3 = c1.dup
|
182
|
+
c4 = c1.dup
|
183
|
+
c1.expires = Time.now - 100
|
184
|
+
c2.expires = Time.now + 100
|
185
|
+
c3.expires = Time.now - 10
|
186
|
+
c4.expires = nil
|
187
|
+
cookies = [c1,c2,c3,c4]
|
188
|
+
@cm.cookies = cookies
|
189
|
+
@cm.check_expired_cookies()
|
190
|
+
# expires == nil cookies (session cookie) exists.
|
191
|
+
@cm.cookies.should eq [c2,c4]
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'parse_expires' do
|
195
|
+
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=; path=/"
|
196
|
+
@cm.parse(str, urify('http://www.test.jp'))
|
197
|
+
cookie = @cm.cookies[0]
|
198
|
+
cookie.should be_an_instance_of WebAgent::Cookie
|
199
|
+
cookie.name.should eq "inkid"
|
200
|
+
cookie.value.should eq "n92b0ADOgACIgUb9lsjHqAAAHu2a"
|
201
|
+
cookie.expires.should be_nil
|
202
|
+
cookie.path.should eq "/"
|
203
|
+
|
204
|
+
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; path=/; expires="
|
205
|
+
@cm.parse(str, urify('http://www.test.jp'))
|
206
|
+
cookie = @cm.cookies[0]
|
207
|
+
cookie.should be_an_instance_of WebAgent::Cookie
|
208
|
+
cookie.name.should eq "inkid"
|
209
|
+
cookie.value.should eq "n92b0ADOgACIgUb9lsjHqAAAHu2a"
|
210
|
+
cookie.expires.should be_nil
|
211
|
+
cookie.path.should eq "/"
|
212
|
+
|
213
|
+
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; path=/; expires=\"\""
|
214
|
+
@cm.parse(str, urify('http://www.test.jp'))
|
215
|
+
cookie = @cm.cookies[0]
|
216
|
+
cookie.should be_an_instance_of WebAgent::Cookie
|
217
|
+
cookie.name.should eq "inkid"
|
218
|
+
cookie.value.should eq "n92b0ADOgACIgUb9lsjHqAAAHu2a"
|
219
|
+
cookie.expires.should be_nil
|
220
|
+
cookie.path.should eq "/"
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'parse_after_expiration' do
|
224
|
+
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=Wed, 01-Dec-2010 00:00:00 GMT; path=/"
|
225
|
+
@cm.parse(str, urify('http://www.test.jp'))
|
226
|
+
cookie = @cm.cookies[0]
|
227
|
+
cookie.should be_an_instance_of WebAgent::Cookie
|
228
|
+
cookie.name.should eq "inkid"
|
229
|
+
cookie.value.should eq "n92b0ADOgACIgUb9lsjHqAAAHu2a"
|
230
|
+
cookie.expires.should eq Time.gm(2010, 12, 1, 0,0,0)
|
231
|
+
cookie.path.should eq "/"
|
232
|
+
|
233
|
+
time = Time.now.utc.round + 60
|
234
|
+
expires = time.strftime("%a, %d-%b-%Y %H:%M:%S GMT")
|
235
|
+
str = "inkid=n92b0ADOgACIgUb9lsjHqAAAHu2a; expires=#{expires}; path=/"
|
236
|
+
@cm.parse(str, urify('http://www.test.jp'))
|
237
|
+
cookie = @cm.cookies[0]
|
238
|
+
cookie.should be_an_instance_of WebAgent::Cookie
|
239
|
+
cookie.name.should eq "inkid"
|
240
|
+
cookie.value.should eq "n92b0ADOgACIgUb9lsjHqAAAHu2a"
|
241
|
+
cookie.expires.should eq time
|
242
|
+
cookie.path.should eq "/"
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'find_cookie' do
|
246
|
+
str = "xmen=off,0,0,1; path=/; domain=.excite2.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
|
247
|
+
@cm.parse(str, urify("http://www.excite2.co.jp/"))
|
248
|
+
|
249
|
+
str = "xmen=off,0,0,2; path=/; domain=.excite.co.jp; expires=Wednesday, 31-Dec-2037 12:00:00 GMT"
|
250
|
+
@cm.parse(str, urify("http://www.excite.co.jp/"))
|
251
|
+
|
252
|
+
@cm.cookies[0].use = true
|
253
|
+
@cm.cookies[1].use = true
|
254
|
+
|
255
|
+
url = urify('http://www.excite.co.jp/hoge/funi/')
|
256
|
+
cookie_str = @cm.find(url)
|
257
|
+
cookie_str.should eq "xmen=off,0,0,2"
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'load_cookies' do
|
261
|
+
begin
|
262
|
+
File.open("tmp_test.tmp","w") {|f|
|
263
|
+
f.write <<EOF
|
264
|
+
http://www.zdnet.co.jp/news/0106/08/e_gibson.html NGUserID d29b8f49-10875-992421294-1 2145801600 www.zdnet.co.jp / 9 0
|
265
|
+
http://www.zdnet.co.jp/news/0106/08/e_gibson.html PACK zd3-992421294-7436 1293839999 .zdnet.co.jp / 13 0
|
266
|
+
http://example.org/ key value 0 .example.org / 13 0
|
267
|
+
http://example.org/ key value .example.org / 13 0
|
268
|
+
EOF
|
269
|
+
}
|
270
|
+
|
271
|
+
@cm.cookies_file = 'tmp_test.tmp'
|
272
|
+
@cm.load_cookies()
|
273
|
+
c0, c1, c2, c3 = @cm.cookies
|
274
|
+
c0.url.to_s.should eq 'http://www.zdnet.co.jp/news/0106/08/e_gibson.html'
|
275
|
+
c0.name.should eq 'NGUserID'
|
276
|
+
c0.value.should eq 'd29b8f49-10875-992421294-1'
|
277
|
+
c0.expires.should eq Time.at(2145801600)
|
278
|
+
c0.domain.should eq 'www.zdnet.co.jp'
|
279
|
+
c0.path.should eq '/'
|
280
|
+
c0.flag.should eq 9
|
281
|
+
|
282
|
+
c1.url.to_s.should eq 'http://www.zdnet.co.jp/news/0106/08/e_gibson.html'
|
283
|
+
c1.name.should eq 'PACK'
|
284
|
+
c1.value.should eq 'zd3-992421294-7436'
|
285
|
+
c1.expires.should eq Time.at(1293839999)
|
286
|
+
c1.domain.should eq '.zdnet.co.jp'
|
287
|
+
c1.path.should eq '/'
|
288
|
+
c1.flag.should eq 13
|
289
|
+
#
|
290
|
+
c2.expires.should be_nil
|
291
|
+
c3.expires.should be_nil
|
292
|
+
ensure
|
293
|
+
File.unlink("tmp_test.tmp")
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'save_cookies' do
|
298
|
+
str = <<EOF
|
299
|
+
http://www.zdnet.co.jp/news/0106/08/e_gibson.html NGUserID d29b8f49-10875-992421294-1 2145801600 www.zdnet.co.jp / 9
|
300
|
+
http://www.zdnet.co.jp/news/0106/08/e_gibson.html PACK zd3-992421294-7436 2145801600 .zdnet.co.jp / 13
|
301
|
+
EOF
|
302
|
+
begin
|
303
|
+
File.open("tmp_test.tmp","w") {|f|
|
304
|
+
f.write str
|
305
|
+
}
|
306
|
+
@cm.cookies_file = 'tmp_test.tmp'
|
307
|
+
@cm.load_cookies()
|
308
|
+
@cm.instance_eval{@is_saved = false}
|
309
|
+
@cm.cookies_file = 'tmp_test2.tmp'
|
310
|
+
@cm.save_cookies()
|
311
|
+
str2 = ''
|
312
|
+
File.open("tmp_test2.tmp","r") {|f|
|
313
|
+
str2 = f.read()
|
314
|
+
}
|
315
|
+
str.should eq str2
|
316
|
+
#
|
317
|
+
File.exist?('tmp_test2.tmp').should be_true
|
318
|
+
File.unlink("tmp_test2.tmp")
|
319
|
+
@cm.save_cookies()
|
320
|
+
File.exist?('tmp_test2.tmp').should be_false
|
321
|
+
@cm.save_cookies(true)
|
322
|
+
File.exist?('tmp_test2.tmp').should be_true
|
323
|
+
ensure
|
324
|
+
File.unlink("tmp_test.tmp")
|
325
|
+
if FileTest.exist?("tmp_test2.tmp")
|
326
|
+
File.unlink("tmp_test2.tmp")
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
it 'not saved expired cookies' do
|
332
|
+
begin
|
333
|
+
@cm.cookies_file = 'tmp_test.tmp'
|
334
|
+
uri = urify('http://www.example.org')
|
335
|
+
@cm.parse("foo=1; path=/", uri)
|
336
|
+
@cm.parse("bar=2; path=/; expires=", uri)
|
337
|
+
@cm.parse("baz=3; path=/; expires=\"\"", uri)
|
338
|
+
@cm.parse("qux=4; path=/; expires=#{(Time.now + 10).asctime}", uri)
|
339
|
+
@cm.parse("quxx=5; path=/; expires=#{(Time.now - 10).asctime}", uri)
|
340
|
+
@cm.save_cookies()
|
341
|
+
@cm.load_cookies
|
342
|
+
@cm.cookies.size.should eq 1
|
343
|
+
ensure
|
344
|
+
File.unlink("tmp_test.tmp") if File.exist?("tmp_test.tmp")
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
it 'add' do
|
349
|
+
c = WebAgent::Cookie.new()
|
350
|
+
c.name = "hoge"
|
351
|
+
c.value = "funi"
|
352
|
+
c.url = urify("http://www.inac.co.jp/hoge")
|
353
|
+
@cm.add(c)
|
354
|
+
c = @cm.cookies[0]
|
355
|
+
c.name.should eq 'hoge'
|
356
|
+
c.value.should eq 'funi'
|
357
|
+
c.expires.should be_nil
|
358
|
+
end
|
359
|
+
|
360
|
+
it 'add2' do
|
361
|
+
c = WebAgent::Cookie.new()
|
362
|
+
c.name = "hoge"
|
363
|
+
c.value = "funi"
|
364
|
+
c.path = ''
|
365
|
+
c.url = urify("http://www.inac.co.jp/hoge/hoge2/hoge3")
|
366
|
+
@cm.add(c)
|
367
|
+
#
|
368
|
+
c = WebAgent::Cookie.new()
|
369
|
+
c.name = "hoge"
|
370
|
+
c.value = "funi"
|
371
|
+
#c.path = '' NO path given -> same as URL
|
372
|
+
c.url = urify("http://www.inac.co.jp/hoge/hoge2/hoge3")
|
373
|
+
@cm.add(c)
|
374
|
+
#
|
375
|
+
c1, c2 = @cm.cookies
|
376
|
+
c1.path.should eq ''
|
377
|
+
c2.path.should eq '/hoge/hoge2'
|
378
|
+
end
|
379
|
+
|
380
|
+
it 'test_check_cookie_accept_domain' do
|
381
|
+
@cm.accept_domains = [".example1.co.jp", "www1.example.jp"]
|
382
|
+
@cm.reject_domains = [".example2.co.jp", "www2.example.jp"]
|
383
|
+
check1 = @cm.check_cookie_accept_domain("www.example1.co.jp")
|
384
|
+
check1.should be_true
|
385
|
+
check2 = @cm.check_cookie_accept_domain("www.example2.co.jp")
|
386
|
+
check2.should be_false
|
387
|
+
check3 = @cm.check_cookie_accept_domain("www1.example.jp")
|
388
|
+
check3.should be_true
|
389
|
+
check4 = @cm.check_cookie_accept_domain("www2.example.jp")
|
390
|
+
check4.should be_false
|
391
|
+
check5 = @cm.check_cookie_accept_domain("aa.www2.example.jp")
|
392
|
+
check5.should be_true
|
393
|
+
check6 = @cm.check_cookie_accept_domain("aa.www2.example.jp")
|
394
|
+
check6.should be_true
|
395
|
+
@cm.check_cookie_accept_domain(nil).should be_false
|
396
|
+
end
|
397
|
+
|
398
|
+
end
|