http-cookie 1.0.0.pre12 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +12 -8
- data/CHANGELOG.md +29 -0
- data/README.md +28 -0
- data/http-cookie.gemspec +7 -5
- data/lib/http/cookie.rb +37 -32
- data/lib/http/cookie/ruby_compat.rb +5 -1
- data/lib/http/cookie/scanner.rb +12 -25
- data/lib/http/cookie/version.rb +1 -1
- data/lib/http/cookie_jar.rb +57 -35
- data/lib/http/cookie_jar/abstract_saver.rb +16 -2
- data/lib/http/cookie_jar/abstract_store.rb +30 -6
- data/lib/http/cookie_jar/cookiestxt_saver.rb +23 -2
- data/lib/http/cookie_jar/hash_store.rb +6 -15
- data/lib/http/cookie_jar/mozilla_store.rb +147 -33
- data/lib/http/cookie_jar/yaml_saver.rb +29 -4
- data/test/helper.rb +30 -0
- data/test/test_http_cookie.rb +76 -23
- data/test/test_http_cookie_jar.rb +130 -14
- metadata +34 -29
@@ -2,11 +2,55 @@ require File.expand_path('helper', File.dirname(__FILE__))
|
|
2
2
|
require 'tmpdir'
|
3
3
|
|
4
4
|
module TestHTTPCookieJar
|
5
|
+
class TestAutoloading < Test::Unit::TestCase
|
6
|
+
def test_nonexistent_store
|
7
|
+
assert_raises(NameError) {
|
8
|
+
HTTP::CookieJar::NonexistentStore
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_erroneous_store
|
13
|
+
Dir.mktmpdir { |dir|
|
14
|
+
Dir.mkdir(File.join(dir, 'http'))
|
15
|
+
Dir.mkdir(File.join(dir, 'http', 'cookie_jar'))
|
16
|
+
rb = File.join(dir, 'http', 'cookie_jar', 'erroneous_store.rb')
|
17
|
+
File.open(rb, 'w').close
|
18
|
+
$LOAD_PATH.unshift(dir)
|
19
|
+
|
20
|
+
assert_raises(NameError) {
|
21
|
+
HTTP::CookieJar::ErroneousStore
|
22
|
+
}
|
23
|
+
assert($LOADED_FEATURES.any? { |file| FileTest.identical?(file, rb) })
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_nonexistent_saver
|
28
|
+
assert_raises(NameError) {
|
29
|
+
HTTP::CookieJar::NonexistentSaver
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_erroneous_saver
|
34
|
+
Dir.mktmpdir { |dir|
|
35
|
+
Dir.mkdir(File.join(dir, 'http'))
|
36
|
+
Dir.mkdir(File.join(dir, 'http', 'cookie_jar'))
|
37
|
+
rb = File.join(dir, 'http', 'cookie_jar', 'erroneous_saver.rb')
|
38
|
+
File.open(rb, 'w').close
|
39
|
+
$LOAD_PATH.unshift(dir)
|
40
|
+
|
41
|
+
assert_raises(NameError) {
|
42
|
+
HTTP::CookieJar::ErroneousSaver
|
43
|
+
}
|
44
|
+
assert($LOADED_FEATURES.any? { |file| FileTest.identical?(file, rb) })
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
5
49
|
module CommonTests
|
6
50
|
def setup(options = nil, options2 = nil)
|
7
51
|
default_options = {
|
8
52
|
:store => :hash,
|
9
|
-
:gc_threshold =>
|
53
|
+
:gc_threshold => 1500, # increased by 10 for shorter test time
|
10
54
|
}
|
11
55
|
new_options = default_options.merge(options || {})
|
12
56
|
new_options2 = new_options.merge(options2 || {})
|
@@ -87,6 +131,17 @@ module TestHTTPCookieJar
|
|
87
131
|
assert_equal(0, @jar.cookies(URI('http://www.rubyforge.org/')).length)
|
88
132
|
end
|
89
133
|
|
134
|
+
def test_host_only_with_unqualified_hostname
|
135
|
+
@jar.add(HTTP::Cookie.new(cookie_values(
|
136
|
+
:origin => 'http://localhost/', :domain => 'localhost', :for_domain => false)))
|
137
|
+
|
138
|
+
assert_equal(1, @jar.cookies(URI('http://localhost/')).length)
|
139
|
+
|
140
|
+
assert_equal(1, @jar.cookies(URI('http://Localhost/')).length)
|
141
|
+
|
142
|
+
assert_equal(1, @jar.cookies(URI('https://Localhost/')).length)
|
143
|
+
end
|
144
|
+
|
90
145
|
def test_empty_value
|
91
146
|
url = URI 'http://rubyforge.org/'
|
92
147
|
values = cookie_values(:value => "")
|
@@ -303,14 +358,6 @@ module TestHTTPCookieJar
|
|
303
358
|
assert_equal(0, @jar.cookies(url).length)
|
304
359
|
end
|
305
360
|
|
306
|
-
def test_save_nonexistent_saver
|
307
|
-
Dir.mktmpdir { |dir|
|
308
|
-
assert_raises(ArgumentError) {
|
309
|
-
@jar.save(File.join(dir, "file"), :nonexistent)
|
310
|
-
}
|
311
|
-
}
|
312
|
-
end
|
313
|
-
|
314
361
|
def test_save_cookies_yaml
|
315
362
|
url = URI 'http://rubyforge.org/'
|
316
363
|
|
@@ -351,12 +398,18 @@ module TestHTTPCookieJar
|
|
351
398
|
@jar.save(filename, :format => :cookiestxt)
|
352
399
|
@jar.save(filename, :cookiestxt, :session => true)
|
353
400
|
@jar.save(filename, :cookiestxt)
|
401
|
+
@jar.save(filename, HTTP::CookieJar::CookiestxtSaver)
|
402
|
+
@jar.save(filename, HTTP::CookieJar::CookiestxtSaver.new)
|
354
403
|
@jar.save(filename, :session => true)
|
355
404
|
@jar.save(filename)
|
405
|
+
|
356
406
|
assert_raises(ArgumentError) {
|
357
407
|
@jar.save()
|
358
408
|
}
|
359
409
|
assert_raises(ArgumentError) {
|
410
|
+
@jar.save(filename, :nonexistent)
|
411
|
+
}
|
412
|
+
assert_raises(TypeError) {
|
360
413
|
@jar.save(filename, { :format => :cookiestxt }, { :session => true })
|
361
414
|
}
|
362
415
|
assert_raises(ArgumentError) {
|
@@ -366,6 +419,8 @@ module TestHTTPCookieJar
|
|
366
419
|
@jar.load(filename, :format => :cookiestxt, :linefeed => "\n")
|
367
420
|
@jar.load(filename, :format => :cookiestxt, :linefeed => "\n")
|
368
421
|
@jar.load(filename, :format => :cookiestxt)
|
422
|
+
@jar.load(filename, HTTP::CookieJar::CookiestxtSaver)
|
423
|
+
@jar.load(filename, HTTP::CookieJar::CookiestxtSaver.new)
|
369
424
|
@jar.load(filename, :cookiestxt, :linefeed => "\n")
|
370
425
|
@jar.load(filename, :cookiestxt)
|
371
426
|
@jar.load(filename, :linefeed => "\n")
|
@@ -374,6 +429,9 @@ module TestHTTPCookieJar
|
|
374
429
|
@jar.load()
|
375
430
|
}
|
376
431
|
assert_raises(ArgumentError) {
|
432
|
+
@jar.load(filename, :nonexistent)
|
433
|
+
}
|
434
|
+
assert_raises(TypeError) {
|
377
435
|
@jar.load(filename, { :format => :cookiestxt }, { :linefeed => "\n" })
|
378
436
|
}
|
379
437
|
assert_raises(ArgumentError) {
|
@@ -692,7 +750,7 @@ module TestHTTPCookieJar
|
|
692
750
|
@jar.cleanup
|
693
751
|
count = @jar.to_a.size
|
694
752
|
assert_equal limit_per_domain, count
|
695
|
-
assert_equal [*1..
|
753
|
+
assert_equal [*1..(limit_per_domain + 1)] - [42], @jar.map { |cookie|
|
696
754
|
cookie.name[/(\d+)$/].to_i
|
697
755
|
}.sort
|
698
756
|
|
@@ -749,6 +807,46 @@ module TestHTTPCookieJar
|
|
749
807
|
assert_equal %w[Akinori Japan], cookies.map { |c| c.value }
|
750
808
|
assert_equal %w[Japan Akinori], @jar.to_a.sort_by { |c| c.name }.map { |c| c.value }
|
751
809
|
end
|
810
|
+
|
811
|
+
def test_expire_by_each_and_cleanup
|
812
|
+
uri = URI('http://www.example.org/')
|
813
|
+
|
814
|
+
ts = Time.now.to_f
|
815
|
+
if ts % 1 > 0.5
|
816
|
+
sleep 0.5
|
817
|
+
ts += 0.5
|
818
|
+
end
|
819
|
+
expires = Time.at(ts.floor)
|
820
|
+
time = expires
|
821
|
+
|
822
|
+
if mozilla_store?
|
823
|
+
# MozillaStore only has the time precision of seconds.
|
824
|
+
time = expires
|
825
|
+
expires -= 1
|
826
|
+
end
|
827
|
+
|
828
|
+
0.upto(2) { |i|
|
829
|
+
c = HTTP::Cookie.new('Foo%d' % (3 - i), 'Bar', :expires => expires + i, :origin => uri)
|
830
|
+
@jar << c
|
831
|
+
@jar2 << c
|
832
|
+
}
|
833
|
+
|
834
|
+
assert_equal %w[Foo1 Foo2], @jar.cookies.map(&:name)
|
835
|
+
assert_equal %w[Foo1 Foo2], @jar2.cookies(uri).map(&:name)
|
836
|
+
|
837
|
+
sleep_until time + 1
|
838
|
+
|
839
|
+
assert_equal %w[Foo1], @jar.cookies.map(&:name)
|
840
|
+
assert_equal %w[Foo1], @jar2.cookies(uri).map(&:name)
|
841
|
+
|
842
|
+
sleep_until time + 2
|
843
|
+
|
844
|
+
@jar.cleanup
|
845
|
+
@jar2.cleanup
|
846
|
+
|
847
|
+
assert_send [@jar, :empty?]
|
848
|
+
assert_send [@jar2, :empty?]
|
849
|
+
end
|
752
850
|
end
|
753
851
|
|
754
852
|
class WithHashStore < Test::Unit::TestCase
|
@@ -758,18 +856,30 @@ module TestHTTPCookieJar
|
|
758
856
|
jar = HTTP::CookieJar.new(:store => :hash)
|
759
857
|
assert_instance_of HTTP::CookieJar::HashStore, jar.store
|
760
858
|
|
761
|
-
assert_raises(
|
859
|
+
assert_raises(ArgumentError) {
|
762
860
|
jar = HTTP::CookieJar.new(:store => :nonexistent)
|
763
861
|
}
|
764
862
|
|
765
863
|
jar = HTTP::CookieJar.new(:store => HTTP::CookieJar::HashStore.new)
|
766
864
|
assert_instance_of HTTP::CookieJar::HashStore, jar.store
|
767
865
|
|
768
|
-
|
769
|
-
jar = HTTP::CookieJar.new(:store => HTTP::CookieJar::HashStore)
|
770
|
-
}
|
866
|
+
jar = HTTP::CookieJar.new(:store => HTTP::CookieJar::HashStore)
|
771
867
|
end
|
772
868
|
|
869
|
+
def test_clone
|
870
|
+
jar = @jar.clone
|
871
|
+
assert_not_send [
|
872
|
+
@jar.store,
|
873
|
+
:equal?,
|
874
|
+
jar.store
|
875
|
+
]
|
876
|
+
assert_not_send [
|
877
|
+
@jar.store.instance_variable_get(:@jar),
|
878
|
+
:equal?,
|
879
|
+
jar.store.instance_variable_get(:@jar)
|
880
|
+
]
|
881
|
+
assert_equal @jar.cookies, jar.cookies
|
882
|
+
end
|
773
883
|
end
|
774
884
|
|
775
885
|
class WithMozillaStore < Test::Unit::TestCase
|
@@ -789,6 +899,12 @@ module TestHTTPCookieJar
|
|
789
899
|
jar.delete(HTTP::Cookie.new("name", :domain => 'rubyforge.org'))
|
790
900
|
end
|
791
901
|
|
902
|
+
def test_clone
|
903
|
+
assert_raises(TypeError) {
|
904
|
+
@jar.clone
|
905
|
+
}
|
906
|
+
end
|
907
|
+
|
792
908
|
def test_close
|
793
909
|
add_and_delete(@jar)
|
794
910
|
|
metadata
CHANGED
@@ -1,117 +1,121 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-cookie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akinori MUSHA
|
8
8
|
- Aaron Patterson
|
9
9
|
- Eric Hodel
|
10
10
|
- Mike Dalessio
|
11
|
-
autorequire:
|
11
|
+
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2021-06-07 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: domain_name
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
19
19
|
requirements:
|
20
|
-
- - ~>
|
20
|
+
- - "~>"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '0.5'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - ~>
|
27
|
+
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0.5'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: sqlite3
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
|
-
- - ~>
|
34
|
+
- - "~>"
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: 1.3.3
|
37
37
|
type: :development
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- - ~>
|
41
|
+
- - "~>"
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: 1.3.3
|
44
44
|
- !ruby/object:Gem::Dependency
|
45
45
|
name: bundler
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
|
-
- -
|
48
|
+
- - ">="
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: 1.2.0
|
51
51
|
type: :development
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
|
-
- -
|
55
|
+
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: 1.2.0
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: test-unit
|
60
60
|
requirement: !ruby/object:Gem::Requirement
|
61
61
|
requirements:
|
62
|
-
- -
|
62
|
+
- - ">="
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: 2.4.3
|
65
65
|
type: :development
|
66
66
|
prerelease: false
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
|
-
- -
|
69
|
+
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: 2.4.3
|
72
72
|
- !ruby/object:Gem::Dependency
|
73
73
|
name: rake
|
74
74
|
requirement: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
|
-
- -
|
76
|
+
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: 0.9.2.2
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
|
-
- -
|
83
|
+
- - ">="
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: 0.9.2.2
|
86
86
|
- !ruby/object:Gem::Dependency
|
87
87
|
name: rdoc
|
88
88
|
requirement: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
|
-
- -
|
90
|
+
- - ">"
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: 2.4.2
|
93
93
|
type: :development
|
94
94
|
prerelease: false
|
95
95
|
version_requirements: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
|
-
- -
|
97
|
+
- - ">"
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: 2.4.2
|
100
100
|
- !ruby/object:Gem::Dependency
|
101
101
|
name: simplecov
|
102
102
|
requirement: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
|
-
- -
|
104
|
+
- - ">="
|
105
105
|
- !ruby/object:Gem::Version
|
106
106
|
version: '0'
|
107
107
|
type: :development
|
108
108
|
prerelease: false
|
109
109
|
version_requirements: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
|
-
- -
|
111
|
+
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '0'
|
114
|
-
description:
|
114
|
+
description: HTTP::Cookie is a Ruby library to handle HTTP Cookies based on RFC 6265. It
|
115
|
+
has with security, standards compliance and compatibility in mind, to behave just
|
116
|
+
the same as today's major web browsers. It has builtin support for the legacy cookies.txt
|
117
|
+
and the latest cookies.sqlite formats of Mozilla Firefox, and its modular API makes
|
118
|
+
it easy to add support for a new backend store.
|
115
119
|
email:
|
116
120
|
- knu@idaemons.org
|
117
121
|
- aaronp@rubyforge.org
|
@@ -123,8 +127,9 @@ extra_rdoc_files:
|
|
123
127
|
- README.md
|
124
128
|
- LICENSE.txt
|
125
129
|
files:
|
126
|
-
- .gitignore
|
127
|
-
- .travis.yml
|
130
|
+
- ".gitignore"
|
131
|
+
- ".travis.yml"
|
132
|
+
- CHANGELOG.md
|
128
133
|
- Gemfile
|
129
134
|
- LICENSE.txt
|
130
135
|
- README.md
|
@@ -148,28 +153,28 @@ files:
|
|
148
153
|
- test/test_http_cookie.rb
|
149
154
|
- test/test_http_cookie_jar.rb
|
150
155
|
homepage: https://github.com/sparklemotion/http-cookie
|
151
|
-
licenses:
|
156
|
+
licenses:
|
157
|
+
- MIT
|
152
158
|
metadata: {}
|
153
|
-
post_install_message:
|
159
|
+
post_install_message:
|
154
160
|
rdoc_options: []
|
155
161
|
require_paths:
|
156
162
|
- lib
|
157
163
|
required_ruby_version: !ruby/object:Gem::Requirement
|
158
164
|
requirements:
|
159
|
-
- -
|
165
|
+
- - ">="
|
160
166
|
- !ruby/object:Gem::Version
|
161
167
|
version: '0'
|
162
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
169
|
requirements:
|
164
|
-
- -
|
170
|
+
- - ">="
|
165
171
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
172
|
+
version: '0'
|
167
173
|
requirements: []
|
168
|
-
|
169
|
-
|
170
|
-
signing_key:
|
174
|
+
rubygems_version: 3.2.11
|
175
|
+
signing_key:
|
171
176
|
specification_version: 4
|
172
|
-
summary: A Ruby library to handle HTTP Cookies
|
177
|
+
summary: A Ruby library to handle HTTP Cookies based on RFC 6265
|
173
178
|
test_files:
|
174
179
|
- test/helper.rb
|
175
180
|
- test/mechanize.yml
|