cookiejar 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,244 +1,236 @@
1
- require 'cookiejar'
2
- require 'rubygems'
1
+ require 'spec_helper'
3
2
 
4
3
  include CookieJar
5
4
  describe CookieValidation do
6
- describe "#validate_cookie" do
5
+ describe '#validate_cookie' do
7
6
  localaddr = 'http://localhost/foo/bar/'
8
- it "should fail if version unset" do
9
- lambda do
7
+ it 'should fail if version unset' do
8
+ expect(lambda do
10
9
  unversioned = Cookie.from_set_cookie localaddr, 'foo=bar'
11
10
  unversioned.instance_variable_set :@version, nil
12
11
  CookieValidation.validate_cookie localaddr, unversioned
13
- end.should raise_error InvalidCookieError
14
- end
15
- it "should fail if the path is more specific" do
16
- lambda do
17
- subdirred = Cookie.from_set_cookie localaddr, 'foo=bar;path=/foo/bar/baz'
18
- # validate_cookie localaddr, subdirred
19
- end.should raise_error InvalidCookieError
20
- end
21
- it "should fail if the path is different than the request" do
22
- lambda do
23
- difdirred = Cookie.from_set_cookie localaddr, 'foo=bar;path=/baz/'
24
- # validate_cookie localaddr, difdirred
25
- end.should raise_error InvalidCookieError
26
- end
27
- it "should fail if the domain has no dots" do
28
- lambda do
29
- nodot = Cookie.from_set_cookie 'http://zero/', 'foo=bar;domain=zero'
30
- # validate_cookie 'http://zero/', nodot
31
- end.should raise_error InvalidCookieError
32
- end
33
- it "should fail for explicit localhost" do
34
- lambda do
35
- localhost = Cookie.from_set_cookie localaddr, 'foo=bar;domain=localhost'
36
- # validate_cookie localaddr, localhost
37
- end.should raise_error InvalidCookieError
38
- end
39
- it "should fail for mismatched domains" do
40
- lambda do
41
- foobar = Cookie.from_set_cookie 'http://www.foo.com/', 'foo=bar;domain=bar.com'
42
- # validate_cookie 'http://www.foo.com/', foobar
43
- end.should raise_error InvalidCookieError
44
- end
45
- it "should fail for domains more than one level up" do
46
- lambda do
47
- xyz = Cookie.from_set_cookie 'http://x.y.z.com/', 'foo=bar;domain=z.com'
48
- # validate_cookie 'http://x.y.z.com/', xyz
49
- end.should raise_error InvalidCookieError
50
- end
51
- it "should fail for setting subdomain cookies" do
52
- lambda do
53
- subdomain = Cookie.from_set_cookie 'http://foo.com/', 'foo=bar;domain=auth.foo.com'
54
- # validate_cookie 'http://foo.com/', subdomain
55
- end.should raise_error InvalidCookieError
56
- end
57
- it "should handle a normal implicit internet cookie" do
12
+ end).to raise_error InvalidCookieError
13
+ end
14
+ it 'should fail if the path is more specific' do
15
+ expect(lambda do
16
+ Cookie.from_set_cookie localaddr, 'foo=bar;path=/foo/bar/baz'
17
+ end).to raise_error InvalidCookieError
18
+ end
19
+ it 'should fail if the path is different than the request' do
20
+ expect(lambda do
21
+ Cookie.from_set_cookie localaddr, 'foo=bar;path=/baz/'
22
+ end).to raise_error InvalidCookieError
23
+ end
24
+ it 'should fail if the domain has no dots' do
25
+ expect(lambda do
26
+ Cookie.from_set_cookie 'http://zero/', 'foo=bar;domain=zero'
27
+ end).to raise_error InvalidCookieError
28
+ end
29
+ it 'should fail for explicit localhost' do
30
+ expect(lambda do
31
+ Cookie.from_set_cookie localaddr, 'foo=bar;domain=localhost'
32
+ end).to raise_error InvalidCookieError
33
+ end
34
+ it 'should fail for mismatched domains' do
35
+ expect(lambda do
36
+ Cookie.from_set_cookie 'http://www.foo.com/', 'foo=bar;domain=bar.com'
37
+ end).to raise_error InvalidCookieError
38
+ end
39
+ it 'should fail for domains more than one level up' do
40
+ expect(lambda do
41
+ Cookie.from_set_cookie 'http://x.y.z.com/', 'foo=bar;domain=z.com'
42
+ end).to raise_error InvalidCookieError
43
+ end
44
+ it 'should fail for setting subdomain cookies' do
45
+ expect(lambda do
46
+ Cookie.from_set_cookie 'http://foo.com/', 'foo=bar;domain=auth.foo.com'
47
+ end).to raise_error InvalidCookieError
48
+ end
49
+ it 'should handle a normal implicit internet cookie' do
58
50
  normal = Cookie.from_set_cookie 'http://foo.com/', 'foo=bar'
59
- CookieValidation.validate_cookie('http://foo.com/', normal).should be_true
51
+ expect(CookieValidation.validate_cookie('http://foo.com/', normal)).to be_truthy
60
52
  end
61
- it "should handle a normal implicit localhost cookie" do
53
+ it 'should handle a normal implicit localhost cookie' do
62
54
  localhost = Cookie.from_set_cookie 'http://localhost/', 'foo=bar'
63
- CookieValidation.validate_cookie('http://localhost/', localhost).should be_true
55
+ expect(CookieValidation.validate_cookie('http://localhost/', localhost)).to be_truthy
64
56
  end
65
- it "should handle an implicit IP address cookie" do
66
- ipaddr = Cookie.from_set_cookie 'http://127.0.0.1/', 'foo=bar'
67
- CookieValidation.validate_cookie('http://127.0.0.1/', ipaddr).should be_true
57
+ it 'should handle an implicit IP address cookie' do
58
+ ipaddr = Cookie.from_set_cookie 'http://127.0.0.1/', 'foo=bar'
59
+ expect(CookieValidation.validate_cookie('http://127.0.0.1/', ipaddr)).to be_truthy
68
60
  end
69
- it "should handle an explicit domain on an internet site" do
61
+ it 'should handle an explicit domain on an internet site' do
70
62
  explicit = Cookie.from_set_cookie 'http://foo.com/', 'foo=bar;domain=.foo.com'
71
- CookieValidation.validate_cookie('http://foo.com/', explicit).should be_true
63
+ expect(CookieValidation.validate_cookie('http://foo.com/', explicit)).to be_truthy
72
64
  end
73
- it "should handle setting a cookie explicitly on a superdomain" do
65
+ it 'should handle setting a cookie explicitly on a superdomain' do
74
66
  superdomain = Cookie.from_set_cookie 'http://auth.foo.com/', 'foo=bar;domain=.foo.com'
75
- CookieValidation.validate_cookie('http://foo.com/', superdomain).should be_true
67
+ expect(CookieValidation.validate_cookie('http://foo.com/', superdomain)).to be_truthy
76
68
  end
77
- it "should handle explicitly setting a cookie" do
69
+ it 'should handle explicitly setting a cookie' do
78
70
  explicit = Cookie.from_set_cookie 'http://foo.com/bar/', 'foo=bar;path=/bar/'
79
71
  CookieValidation.validate_cookie('http://foo.com/bar/', explicit)
80
72
  end
81
- it "should handle setting a cookie on a higher path" do
73
+ it 'should handle setting a cookie on a higher path' do
82
74
  higher = Cookie.from_set_cookie 'http://foo.com/bar/baz/', 'foo=bar;path=/bar/'
83
75
  CookieValidation.validate_cookie('http://foo.com/bar/baz/', higher)
84
- end
76
+ end
85
77
  end
86
78
  describe '#cookie_base_path' do
87
79
  it "should leave '/' alone" do
88
- CookieValidation.cookie_base_path('/').should == '/'
80
+ expect(CookieValidation.cookie_base_path('/')).to eq '/'
89
81
  end
90
82
  it "should strip off everything after the last '/'" do
91
- CookieValidation.cookie_base_path('/foo/bar/baz').should == '/foo/bar/'
83
+ expect(CookieValidation.cookie_base_path('/foo/bar/baz')).to eq '/foo/bar/'
92
84
  end
93
- it "should handle query parameters and fragments with slashes" do
94
- CookieValidation.cookie_base_path('/foo/bar?query=a/b/c#fragment/b/c').should == '/foo/'
85
+ it 'should handle query parameters and fragments with slashes' do
86
+ expect(CookieValidation.cookie_base_path('/foo/bar?query=a/b/c#fragment/b/c')).to eq '/foo/'
95
87
  end
96
- it "should handle URI objects" do
97
- CookieValidation.cookie_base_path(URI.parse('http://www.foo.com/bar/')).should == '/bar/'
88
+ it 'should handle URI objects' do
89
+ expect(CookieValidation.cookie_base_path(URI.parse('http://www.foo.com/bar/'))).to eq '/bar/'
98
90
  end
99
- it "should preserve case" do
100
- CookieValidation.cookie_base_path("/BaR/").should == '/BaR/'
91
+ it 'should preserve case' do
92
+ expect(CookieValidation.cookie_base_path('/BaR/')).to eq '/BaR/'
101
93
  end
102
94
  end
103
95
  describe '#determine_cookie_path' do
104
- it "should use the requested path when none is specified for the cookie" do
105
- CookieValidation.determine_cookie_path('http://foo.com/', nil).should == '/'
106
- CookieValidation.determine_cookie_path('http://foo.com/bar/baz', '').should == '/bar/'
96
+ it 'should use the requested path when none is specified for the cookie' do
97
+ expect(CookieValidation.determine_cookie_path('http://foo.com/', nil)).to eq '/'
98
+ expect(CookieValidation.determine_cookie_path('http://foo.com/bar/baz', '')).to eq '/bar/'
107
99
  end
108
- it "should handle URI objects" do
109
- CookieValidation.determine_cookie_path(URI.parse('http://foo.com/bar/'), '').should == '/bar/'
100
+ it 'should handle URI objects' do
101
+ expect(CookieValidation.determine_cookie_path(URI.parse('http://foo.com/bar/'), '')).to eq '/bar/'
110
102
  end
111
- it "should handle Cookie objects" do
112
- cookie = Cookie.from_set_cookie('http://foo.com/', "name=value;path=/")
113
- CookieValidation.determine_cookie_path('http://foo.com/', cookie).should == '/'
103
+ it 'should handle Cookie objects' do
104
+ cookie = Cookie.from_set_cookie('http://foo.com/', 'name=value;path=/')
105
+ expect(CookieValidation.determine_cookie_path('http://foo.com/', cookie)).to eq '/'
114
106
  end
115
- it "should ignore the request when a path is specified" do
116
- CookieValidation.determine_cookie_path('http://foo.com/ignorable/path', '/path/').should == '/path/'
107
+ it 'should ignore the request when a path is specified' do
108
+ expect(CookieValidation.determine_cookie_path('http://foo.com/ignorable/path', '/path/')).to eq '/path/'
117
109
  end
118
110
  end
119
111
  describe '#compute_search_domains' do
120
- it "should handle subdomains" do
121
- CookieValidation.compute_search_domains('http://www.auth.foo.com/').should ==
122
- ['www.auth.foo.com', '.www.auth.foo.com', '.auth.foo.com']
112
+ it 'should handle subdomains' do
113
+ expect(CookieValidation.compute_search_domains('http://www.auth.foo.com/')).to eq(
114
+ ['www.auth.foo.com', '.www.auth.foo.com', '.auth.foo.com'])
123
115
  end
124
- it "should handle root domains" do
125
- CookieValidation.compute_search_domains('http://foo.com/').should ==
126
- ['foo.com', '.foo.com']
116
+ it 'should handle root domains' do
117
+ expect(CookieValidation.compute_search_domains('http://foo.com/')).to eq(
118
+ ['foo.com', '.foo.com'])
127
119
  end
128
- it "should handle hexadecimal TLDs" do
129
- CookieValidation.compute_search_domains('http://tiny.cc/').should ==
130
- ['tiny.cc', '.tiny.cc']
120
+ it 'should handle hexadecimal TLDs' do
121
+ expect(CookieValidation.compute_search_domains('http://tiny.cc/')).to eq(
122
+ ['tiny.cc', '.tiny.cc'])
131
123
  end
132
- it "should handle IP addresses" do
133
- CookieValidation.compute_search_domains('http://127.0.0.1/').should ==
134
- ['127.0.0.1']
124
+ it 'should handle IP addresses' do
125
+ expect(CookieValidation.compute_search_domains('http://127.0.0.1/')).to eq(
126
+ ['127.0.0.1'])
135
127
  end
136
- it "should handle local addresses" do
137
- CookieValidation.compute_search_domains('http://zero/').should ==
138
- ['zero.local', '.zero.local', '.local']
128
+ it 'should handle local addresses' do
129
+ expect(CookieValidation.compute_search_domains('http://zero/')).to eq(
130
+ ['zero.local', '.zero.local', '.local'])
139
131
  end
140
132
  end
141
133
  describe '#determine_cookie_domain' do
142
- it "should add a dot to the front of domains" do
143
- CookieValidation.determine_cookie_domain('http://foo.com/', 'foo.com').should == '.foo.com'
134
+ it 'should add a dot to the front of domains' do
135
+ expect(CookieValidation.determine_cookie_domain('http://foo.com/', 'foo.com')).to eq '.foo.com'
144
136
  end
145
- it "should not add a second dot if one present" do
146
- CookieValidation.determine_cookie_domain('http://foo.com/', '.foo.com').should == '.foo.com'
137
+ it 'should not add a second dot if one present' do
138
+ expect(CookieValidation.determine_cookie_domain('http://foo.com/', '.foo.com')).to eq '.foo.com'
147
139
  end
148
- it "should handle Cookie objects" do
149
- c = Cookie.from_set_cookie('http://foo.com/', "foo=bar;domain=foo.com")
150
- CookieValidation.determine_cookie_domain('http://foo.com/', c).should == '.foo.com'
140
+ it 'should handle Cookie objects' do
141
+ c = Cookie.from_set_cookie('http://foo.com/', 'foo=bar;domain=foo.com')
142
+ expect(CookieValidation.determine_cookie_domain('http://foo.com/', c)).to eq '.foo.com'
151
143
  end
152
- it "should handle URI objects" do
153
- CookieValidation.determine_cookie_domain(URI.parse('http://foo.com/'), '.foo.com').should == '.foo.com'
144
+ it 'should handle URI objects' do
145
+ expect(CookieValidation.determine_cookie_domain(URI.parse('http://foo.com/'), '.foo.com')).to eq '.foo.com'
154
146
  end
155
- it "should use an exact hostname when no domain specified" do
156
- CookieValidation.determine_cookie_domain('http://foo.com/', '').should == 'foo.com'
147
+ it 'should use an exact hostname when no domain specified' do
148
+ expect(CookieValidation.determine_cookie_domain('http://foo.com/', '')).to eq 'foo.com'
157
149
  end
158
- it "should leave IPv4 addresses alone" do
159
- CookieValidation.determine_cookie_domain('http://127.0.0.1/', '127.0.0.1').should == '127.0.0.1'
150
+ it 'should leave IPv4 addresses alone' do
151
+ expect(CookieValidation.determine_cookie_domain('http://127.0.0.1/', '127.0.0.1')).to eq '127.0.0.1'
160
152
  end
161
- it "should leave IPv6 addresses alone" do
153
+ it 'should leave IPv6 addresses alone' do
162
154
  ['2001:db8:85a3::8a2e:370:7334', '::ffff:192.0.2.128'].each do |value|
163
- CookieValidation.determine_cookie_domain("http://[#{value}]/", value).should == value
155
+ expect(CookieValidation.determine_cookie_domain("http://[#{value}]/", value)).to eq value
164
156
  end
165
157
  end
166
158
  end
167
- describe "#effective_host" do
168
- it "should leave proper domains the same" do
159
+ describe '#effective_host' do
160
+ it 'should leave proper domains the same' do
169
161
  ['google.com', 'www.google.com', 'google.com.'].each do |value|
170
- CookieValidation.effective_host(value).should == value
162
+ expect(CookieValidation.effective_host(value)).to eq value
171
163
  end
172
164
  end
173
- it "should handle a URI object" do
174
- CookieValidation.effective_host(URI.parse('http://example.com/')).should == 'example.com'
175
- end
176
- it "should add a local suffix on unqualified hosts" do
177
- CookieValidation.effective_host('localhost').should == 'localhost.local'
165
+ it 'should handle a URI object' do
166
+ expect(CookieValidation.effective_host(URI.parse('http://example.com/'))).to eq 'example.com'
167
+ end
168
+ it 'should add a local suffix on unqualified hosts' do
169
+ expect(CookieValidation.effective_host('localhost')).to eq 'localhost.local'
178
170
  end
179
- it "should leave IPv4 addresses alone" do
180
- CookieValidation.effective_host('127.0.0.1').should == '127.0.0.1'
171
+ it 'should leave IPv4 addresses alone' do
172
+ expect(CookieValidation.effective_host('127.0.0.1')).to eq '127.0.0.1'
181
173
  end
182
- it "should leave IPv6 addresses alone" do
174
+ it 'should leave IPv6 addresses alone' do
183
175
  ['2001:db8:85a3::8a2e:370:7334', ':ffff:192.0.2.128'].each do |value|
184
- CookieValidation.effective_host(value).should == value
176
+ expect(CookieValidation.effective_host(value)).to eq value
185
177
  end
186
178
  end
187
- it "should lowercase addresses" do
188
- CookieValidation.effective_host('FOO.COM').should == 'foo.com'
179
+ it 'should lowercase addresses' do
180
+ expect(CookieValidation.effective_host('FOO.COM')).to eq 'foo.com'
189
181
  end
190
182
  end
191
183
  describe '#match_domains' do
192
- it "should handle exact matches" do
193
- CookieValidation.domains_match('localhost.local', 'localhost.local').should == 'localhost.local'
194
- CookieValidation.domains_match('foo.com', 'foo.com').should == 'foo.com'
195
- CookieValidation.domains_match('127.0.0.1', '127.0.0.1').should == '127.0.0.1'
196
- CookieValidation.domains_match('::ffff:192.0.2.128', '::ffff:192.0.2.128').should == '::ffff:192.0.2.128'
184
+ it 'should handle exact matches' do
185
+ expect(CookieValidation.domains_match('localhost.local', 'localhost.local')).to eq 'localhost.local'
186
+ expect(CookieValidation.domains_match('foo.com', 'foo.com')).to eq 'foo.com'
187
+ expect(CookieValidation.domains_match('127.0.0.1', '127.0.0.1')).to eq '127.0.0.1'
188
+ expect(CookieValidation.domains_match('::ffff:192.0.2.128', '::ffff:192.0.2.128')).to eq '::ffff:192.0.2.128'
197
189
  end
198
- it "should handle matching a superdomain" do
199
- CookieValidation.domains_match('.foo.com', 'auth.foo.com').should == '.foo.com'
200
- CookieValidation.domains_match('.y.z.foo.com', 'x.y.z.foo.com').should == '.y.z.foo.com'
190
+ it 'should handle matching a superdomain' do
191
+ expect(CookieValidation.domains_match('.foo.com', 'auth.foo.com')).to eq '.foo.com'
192
+ expect(CookieValidation.domains_match('.y.z.foo.com', 'x.y.z.foo.com')).to eq '.y.z.foo.com'
201
193
  end
202
- it "should not match superdomains, or illegal domains" do
203
- CookieValidation.domains_match('.z.foo.com', 'x.y.z.foo.com').should be_nil
204
- CookieValidation.domains_match('foo.com', 'com').should be_nil
194
+ it 'should not match superdomains, or illegal domains' do
195
+ expect(CookieValidation.domains_match('.z.foo.com', 'x.y.z.foo.com')).to be_nil
196
+ expect(CookieValidation.domains_match('foo.com', 'com')).to be_nil
205
197
  end
206
- it "should not match domains with and without a dot suffix together" do
207
- CookieValidation.domains_match('foo.com.', 'foo.com').should be_nil
198
+ it 'should not match domains with and without a dot suffix together' do
199
+ expect(CookieValidation.domains_match('foo.com.', 'foo.com')).to be_nil
208
200
  end
209
201
  end
210
202
  describe '#hostname_reach' do
211
- it "should find the next highest subdomain" do
212
- {'www.google.com' => 'google.com', 'auth.corp.companyx.com' => 'corp.companyx.com'}.each do |entry|
213
- CookieValidation.hostname_reach(entry[0]).should == entry[1]
203
+ it 'should find the next highest subdomain' do
204
+ { 'www.google.com' => 'google.com', 'auth.corp.companyx.com' => 'corp.companyx.com' }.each do |entry|
205
+ expect(CookieValidation.hostname_reach(entry[0])).to eq entry[1]
214
206
  end
215
207
  end
216
- it "should handle domains with suffixed dots" do
217
- CookieValidation.hostname_reach('www.google.com.').should == 'google.com.'
208
+ it 'should handle domains with suffixed dots' do
209
+ expect(CookieValidation.hostname_reach('www.google.com.')).to eq 'google.com.'
218
210
  end
219
- it "should return nil for a root domain" do
220
- CookieValidation.hostname_reach('github.com').should be_nil
211
+ it 'should return nil for a root domain' do
212
+ expect(CookieValidation.hostname_reach('github.com')).to be_nil
221
213
  end
222
214
  it "should return 'local' for a local domain" do
223
215
  ['foo.local', 'foo.local.'].each do |hostname|
224
- CookieValidation.hostname_reach(hostname).should == 'local'
216
+ expect(CookieValidation.hostname_reach(hostname)).to eq 'local'
225
217
  end
226
218
  end
227
219
  it "should handle mixed-case '.local'" do
228
- CookieValidation.hostname_reach('foo.LOCAL').should == 'local'
220
+ expect(CookieValidation.hostname_reach('foo.LOCAL')).to eq 'local'
229
221
  end
230
- it "should return nil for an IPv4 address" do
231
- CookieValidation.hostname_reach('127.0.0.1').should be_nil
222
+ it 'should return nil for an IPv4 address' do
223
+ expect(CookieValidation.hostname_reach('127.0.0.1')).to be_nil
232
224
  end
233
- it "should return nil for IPv6 addresses" do
225
+ it 'should return nil for IPv6 addresses' do
234
226
  ['2001:db8:85a3::8a2e:370:7334', '::ffff:192.0.2.128'].each do |value|
235
- CookieValidation.hostname_reach(value).should be_nil
227
+ expect(CookieValidation.hostname_reach(value)).to be_nil
236
228
  end
237
229
  end
238
230
  end
239
231
  describe '#parse_set_cookie' do
240
- it "should max out at 2038 on 32bit systems" do
241
- CookieValidation.parse_set_cookie("TRACK_USER_P=98237480810003948000782774;expires=Sat, 30-Jun-2040 05:39:49 GMT;path=/")[:expires_at].to_i.should >= 0x7FFFFFFF
232
+ it 'should max out at 2038 on 32bit systems' do
233
+ expect(CookieValidation.parse_set_cookie('TRACK_USER_P=98237480810003948000782774;expires=Sat, 30-Jun-2040 05:39:49 GMT;path=/')[:expires_at].to_i).to be >= 0x7FFFFFFF
242
234
  end
243
- end
244
- end
235
+ end
236
+ end
@@ -1,235 +1,232 @@
1
- require 'cookiejar'
2
- require 'yaml'
3
- require 'rubygems'
1
+ require 'spec_helper'
4
2
 
5
3
  include CookieJar
6
4
 
7
5
  describe Jar do
8
6
  describe '.setCookie' do
9
- it "should allow me to set a cookie" do
10
- jar = Jar.new
7
+ it 'should allow me to set a cookie' do
8
+ jar = Jar.new
11
9
  jar.set_cookie 'http://foo.com/', 'foo=bar'
12
10
  end
13
- it "should allow me to set multiple cookies" do
14
- jar = Jar.new
11
+ it 'should allow me to set multiple cookies' do
12
+ jar = Jar.new
15
13
  jar.set_cookie 'http://foo.com/', 'foo=bar'
16
14
  jar.set_cookie 'http://foo.com/', 'bar=baz'
17
15
  jar.set_cookie 'http://auth.foo.com/', 'foo=bar'
18
- jar.set_cookie 'http://auth.foo.com/', 'auth=135121...;domain=foo.com'
16
+ jar.set_cookie 'http://auth.foo.com/', 'auth=135121...;domain=foo.com'
19
17
  end
20
- it "should allow me to set multiple cookies in 1 header" do
18
+ it 'should allow me to set multiple cookies in 1 header' do
21
19
  jar = Jar.new
22
20
  jar.set_cookie 'http://foo.com/', 'my_cookie=123456; Domain=foo.com; expires=Thu, 31 Dec 2037 23:59:59 GMT; Path=/, other_cookie=helloworld; Domain=foo.com; expires=Thu, 31 Dec 2037 23:59:59 GMT, last_cookie=098765'
23
21
  end
24
22
  end
25
23
  describe '.get_cookies' do
26
- it "should let me read back cookies which are set" do
27
- jar = Jar.new
24
+ it 'should let me read back cookies which are set' do
25
+ jar = Jar.new
28
26
  jar.set_cookie 'http://foo.com/', 'foo=bar'
29
27
  jar.set_cookie 'http://foo.com/', 'bar=baz'
30
28
  jar.set_cookie 'http://auth.foo.com/', 'foo=bar'
31
29
  jar.set_cookie 'http://auth.foo.com/', 'auth=135121...;domain=foo.com'
32
- jar.get_cookies('http://foo.com/').should have(3).items
30
+ expect(jar.get_cookies('http://foo.com/')).to have(3).items
33
31
  end
34
- it "should let me read back a multiple cookies from 1 header" do
32
+ it 'should let me read back a multiple cookies from 1 header' do
35
33
  jar = Jar.new
36
34
  jar.set_cookie 'http://foo.com/', 'my_cookie=123456; Domain=foo.com; expires=Thu, 31 Dec 2037 23:59:59 GMT; Path=/, other_cookie=helloworld; Domain=foo.com; expires=Thu, 31 Dec 2037 23:59:59 GMT, last_cookie=098765'
37
- jar.get_cookie_header('http://foo.com/').should == 'last_cookie=098765;my_cookie=123456;other_cookie=helloworld'
35
+ expect(jar.get_cookie_header('http://foo.com/')).to eq 'last_cookie=098765;my_cookie=123456;other_cookie=helloworld'
38
36
  end
39
- it "should return cookies longest path first" do
37
+ it 'should return cookies longest path first' do
40
38
  jar = Jar.new
41
- uri = 'http://foo.com/a/b/c/d'
39
+ uri = 'http://foo.com/a/b/c/d'
42
40
  jar.set_cookie uri, 'a=bar'
43
41
  jar.set_cookie uri, 'b=baz;path=/a/b/c/d'
44
42
  jar.set_cookie uri, 'c=bar;path=/a/b'
45
43
  jar.set_cookie uri, 'd=bar;path=/a/'
46
44
  cookies = jar.get_cookies(uri)
47
- cookies.should have(4).items
48
- cookies[0].name.should == 'b'
49
- cookies[1].name.should == 'a'
50
- cookies[2].name.should == 'c'
51
- cookies[3].name.should == 'd'
45
+ expect(cookies).to have(4).items
46
+ expect(cookies[0].name).to eq 'b'
47
+ expect(cookies[1].name).to eq 'a'
48
+ expect(cookies[2].name).to eq 'c'
49
+ expect(cookies[3].name).to eq 'd'
52
50
  end
53
- it "should not return expired cookies" do
51
+ it 'should not return expired cookies' do
54
52
  jar = Jar.new
55
53
  uri = 'http://localhost/'
56
54
  jar.set_cookie uri, 'foo=bar;expires=Wednesday, 09-Nov-99 23:12:40 GMT'
57
55
  cookies = jar.get_cookies(uri)
58
- cookies.should have(0).items
56
+ expect(cookies).to have(0).items
59
57
  end
60
58
  end
61
59
  describe '.get_cookie_headers' do
62
- it "should return cookie headers" do
60
+ it 'should return cookie headers' do
63
61
  jar = Jar.new
64
- uri = 'http://foo.com/a/b/c/d'
62
+ uri = 'http://foo.com/a/b/c/d'
65
63
  jar.set_cookie uri, 'a=bar'
66
64
  jar.set_cookie uri, 'b=baz;path=/a/b/c/d'
67
65
  cookie_headers = jar.get_cookie_header uri
68
- cookie_headers.should == "b=baz;a=bar"
66
+ expect(cookie_headers).to eq 'b=baz;a=bar'
69
67
  end
70
- it "should handle a version 1 cookie" do
68
+ it 'should handle a version 1 cookie' do
71
69
  jar = Jar.new
72
- uri = 'http://foo.com/a/b/c/d'
70
+ uri = 'http://foo.com/a/b/c/d'
73
71
  jar.set_cookie uri, 'a=bar'
74
72
  jar.set_cookie uri, 'b=baz;path=/a/b/c/d'
75
73
  jar.set_cookie2 uri, 'c=baz;Version=1;path="/"'
76
74
  cookie_headers = jar.get_cookie_header uri
77
- cookie_headers.should == '$Version=0;b=baz;$Path="/a/b/c/d";a=bar;$Path="/a/b/c/",$Version=1;c=baz;$Path="/"'
75
+ expect(cookie_headers).to eq '$Version=0;b=baz;$Path="/a/b/c/d";a=bar;$Path="/a/b/c/",$Version=1;c=baz;$Path="/"'
78
76
  end
79
77
  end
80
78
  describe '.add_cookie' do
81
- it "should let me add a pre-existing cookie" do
79
+ it 'should let me add a pre-existing cookie' do
82
80
  jar = Jar.new
83
81
  cookie = Cookie.from_set_cookie 'http://localhost/', 'foo=bar'
84
82
  jar.add_cookie cookie
85
83
  end
86
84
  end
87
85
  describe '.to_a' do
88
- it "should return me an array of all cookie objects" do
89
- uri = 'http://foo.com/a/b/c/d'
86
+ it 'should return me an array of all cookie objects' do
87
+ uri = 'http://foo.com/a/b/c/d'
90
88
  jar = Jar.new
91
89
  jar.set_cookie uri, 'a=bar;expires=Wednesday, 09-Nov-99 23:12:40 GMT'
92
90
  jar.set_cookie uri, 'b=baz;path=/a/b/c/d'
93
91
  jar.set_cookie uri, 'c=bar;path=/a/b'
94
92
  jar.set_cookie uri, 'd=bar;path=/a/'
95
93
  jar.set_cookie 'http://localhost/', 'foo=bar'
96
- jar.to_a.should have(5).items
94
+ expect(jar.to_a).to have(5).items
97
95
  end
98
96
  end
99
97
  describe '.expire_cookies' do
100
- it "should expire cookies which are no longer valid" do
101
- uri = 'http://foo.com/a/b/c/d'
98
+ it 'should expire cookies which are no longer valid' do
99
+ uri = 'http://foo.com/a/b/c/d'
102
100
  jar = Jar.new
103
101
  jar.set_cookie uri, 'a=bar;expires=Wednesday, 09-Nov-99 23:12:40 GMT'
104
102
  jar.set_cookie uri, 'b=baz;path=/a/b/c/d;expires=Wednesday, 01-Nov-2028 12:00:00 GMT'
105
103
  jar.set_cookie uri, 'c=bar;path=/a/b'
106
104
  jar.set_cookie uri, 'd=bar;path=/a/'
107
105
  jar.set_cookie 'http://localhost/', 'foo=bar'
108
- jar.to_a.should have(5).items
106
+ expect(jar.to_a).to have(5).items
109
107
  jar.expire_cookies
110
- jar.to_a.should have(4).items
108
+ expect(jar.to_a).to have(4).items
111
109
  end
112
- it "should let me expire all session cookies" do
113
- uri = 'http://foo.com/a/b/c/d'
110
+ it 'should let me expire all session cookies' do
111
+ uri = 'http://foo.com/a/b/c/d'
114
112
  jar = Jar.new
115
113
  jar.set_cookie uri, 'a=bar;expires=Wednesday, 09-Nov-99 23:12:40 GMT'
116
114
  jar.set_cookie uri, 'b=baz;path=/a/b/c/d;expires=Wednesday, 01-Nov-2028 12:00:00 GMT'
117
115
  jar.set_cookie uri, 'c=bar;path=/a/b'
118
116
  jar.set_cookie uri, 'd=bar;path=/a/'
119
117
  jar.set_cookie 'http://localhost/', 'foo=bar'
120
- jar.to_a.should have(5).items
118
+ expect(jar.to_a).to have(5).items
121
119
  jar.expire_cookies true
122
- jar.to_a.should have(1).items
120
+ expect(jar.to_a).to have(1).items
123
121
  end
124
122
  end
125
123
  describe '#set_cookies_from_headers' do
126
- it "should handle a Set-Cookie header" do
124
+ it 'should handle a Set-Cookie header' do
127
125
  jar = Jar.new
128
- cookies = jar.set_cookies_from_headers 'http://localhost/',
129
- { 'Set-Cookie' => 'foo=bar' }
130
- cookies.should have(1).items
131
- jar.to_a.should have(1).items
126
+ cookies = jar.set_cookies_from_headers 'http://localhost/',
127
+ 'Set-Cookie' => 'foo=bar'
128
+ expect(cookies).to have(1).items
129
+ expect(jar.to_a).to have(1).items
132
130
  end
133
- it "should handle a set-cookie header" do
131
+ it 'should handle a set-cookie header' do
134
132
  jar = Jar.new
135
- cookies = jar.set_cookies_from_headers 'http://localhost/',
136
- { 'set-cookie' => 'foo=bar' }
137
- cookies.should have(1).items
138
- jar.to_a.should have(1).items
133
+ cookies = jar.set_cookies_from_headers 'http://localhost/',
134
+ 'set-cookie' => 'foo=bar'
135
+ expect(cookies).to have(1).items
136
+ expect(jar.to_a).to have(1).items
139
137
  end
140
- it "should handle multiple Set-Cookie headers" do
138
+ it 'should handle multiple Set-Cookie headers' do
141
139
  jar = Jar.new
142
- cookies = jar.set_cookies_from_headers 'http://localhost/',
143
- { 'Set-Cookie' => ['foo=bar','bar=baz'] }
144
- cookies.should have(2).items
145
- jar.to_a.should have(2).items
140
+ cookies = jar.set_cookies_from_headers 'http://localhost/',
141
+ 'Set-Cookie' => ['foo=bar', 'bar=baz']
142
+ expect(cookies).to have(2).items
143
+ expect(jar.to_a).to have(2).items
146
144
  end
147
- it "should handle a Set-Cookie2 header" do
145
+ it 'should handle a Set-Cookie2 header' do
148
146
  jar = Jar.new
149
- cookies = jar.set_cookies_from_headers 'http://localhost/',
150
- { 'Set-Cookie2' => 'foo=bar;Version=1' }
151
- cookies.should have(1).items
152
- jar.to_a.should have(1).items
147
+ cookies = jar.set_cookies_from_headers 'http://localhost/',
148
+ 'Set-Cookie2' => 'foo=bar;Version=1'
149
+ expect(cookies).to have(1).items
150
+ expect(jar.to_a).to have(1).items
153
151
  end
154
- it "should handle a set-cookie2 header" do
152
+ it 'should handle a set-cookie2 header' do
155
153
  jar = Jar.new
156
- cookies = jar.set_cookies_from_headers 'http://localhost/',
157
- { 'set-cookie2' => 'foo=bar;Version=1' }
158
- cookies.should have(1).items
159
- jar.to_a.should have(1).items
154
+ cookies = jar.set_cookies_from_headers 'http://localhost/',
155
+ 'set-cookie2' => 'foo=bar;Version=1'
156
+ expect(cookies).to have(1).items
157
+ expect(jar.to_a).to have(1).items
160
158
  end
161
- it "should handle multiple Set-Cookie2 headers" do
159
+ it 'should handle multiple Set-Cookie2 headers' do
162
160
  jar = Jar.new
163
- cookies = jar.set_cookies_from_headers 'http://localhost/',
164
- { 'Set-Cookie2' => ['foo=bar;Version=1','bar=baz;Version=1'] }
165
- cookies.should have(2).items
166
- jar.to_a.should have(2).items
161
+ cookies = jar.set_cookies_from_headers 'http://localhost/',
162
+ 'Set-Cookie2' => ['foo=bar;Version=1', 'bar=baz;Version=1']
163
+ expect(cookies).to have(2).items
164
+ expect(jar.to_a).to have(2).items
167
165
  end
168
- it "should handle mixed distinct Set-Cookie and Set-Cookie2 headers" do
166
+ it 'should handle mixed distinct Set-Cookie and Set-Cookie2 headers' do
169
167
  jar = Jar.new
170
- cookies = jar.set_cookies_from_headers 'http://localhost/',
171
- { 'Set-Cookie' => 'foo=bar',
172
- 'Set-Cookie2' => 'bar=baz;Version=1' }
173
- cookies.should have(2).items
174
- jar.to_a.should have(2).items
168
+ cookies = jar.set_cookies_from_headers 'http://localhost/',
169
+ 'Set-Cookie' => 'foo=bar',
170
+ 'Set-Cookie2' => 'bar=baz;Version=1'
171
+ expect(cookies).to have(2).items
172
+ expect(jar.to_a).to have(2).items
175
173
  end
176
- it "should handle overlapping Set-Cookie and Set-Cookie2 headers" do
174
+ it 'should handle overlapping Set-Cookie and Set-Cookie2 headers' do
177
175
  jar = Jar.new
178
- cookies = jar.set_cookies_from_headers 'http://localhost/',
179
- { 'Set-Cookie' => ['foo=bar','bar=baz'],
180
- 'Set-Cookie2' => 'foo=bar;Version=1' }
181
- cookies.should have(2).items
182
- jar.to_a.should have(2).items
176
+ cookies = jar.set_cookies_from_headers 'http://localhost/',
177
+ 'Set-Cookie' => ['foo=bar', 'bar=baz'],
178
+ 'Set-Cookie2' => 'foo=bar;Version=1'
179
+ expect(cookies).to have(2).items
180
+ expect(jar.to_a).to have(2).items
183
181
  # and has the version 1 cookie
184
- cookies.find do |cookie|
182
+ expect(cookies.find do |cookie|
185
183
  cookie.name == 'foo'
186
- end.version.should == 1
184
+ end.version).to eq 1
187
185
  end
188
- it "should silently drop invalid cookies" do
186
+ it 'should silently drop invalid cookies' do
189
187
  jar = Jar.new
190
- cookies = jar.set_cookies_from_headers 'http://localhost/',
191
- { 'Set-Cookie' => ['foo=bar','bar=baz;domain=.foo.com'] }
192
- cookies.should have(1).items
193
- jar.to_a.should have(1).items
188
+ cookies = jar.set_cookies_from_headers 'http://localhost/',
189
+ 'Set-Cookie' => ['foo=bar', 'bar=baz;domain=.foo.com']
190
+ expect(cookies).to have(1).items
191
+ expect(jar.to_a).to have(1).items
194
192
  end
195
193
  end
196
194
  begin
197
195
  require 'json'
198
- describe ".to_json" do
199
- it "should serialize cookies to JSON" do
200
-
196
+ describe '.to_json' do
197
+ it 'should serialize cookies to JSON' do
201
198
  c = Cookie.from_set_cookie 'https://localhost/', 'foo=bar;secure;expires=Wed, 01-Nov-2028 12:00:00 GMT'
202
199
  jar = Jar.new
203
200
  jar.add_cookie c
204
201
  json = jar.to_json
205
- json.should be_a String
202
+ expect(json).to be_a String
206
203
  end
207
204
  end
208
- describe ".json_create" do
209
- it "should deserialize a JSON array to a jar" do
210
- json = "[{\"name\":\"foo\",\"value\":\"bar\",\"domain\":\"localhost.local\",\"path\":\"\\/\",\"created_at\":\"2009-09-11 12:51:03 -0600\",\"expiry\":\"2028-11-01 12:00:00 GMT\",\"secure\":true}]"
205
+ describe '.json_create' do
206
+ it 'should deserialize a JSON array to a jar' do
207
+ json = '[{"name":"foo","value":"bar","domain":"localhost.local","path":"\\/","created_at":"2009-09-11 12:51:03 -0600","expiry":"2028-11-01 12:00:00 GMT","secure":true}]'
211
208
  array = JSON.parse json
212
-
209
+
213
210
  jar = Jar.json_create array
214
- jar.get_cookies('https://localhost/').should have(1).items
211
+ expect(jar.get_cookies('https://localhost/')).to have(1).items
215
212
  end
216
- it "should deserialize a JSON hash to a jar" do
217
- json = "{\"cookies\":[{\"name\":\"foo\",\"value\":\"bar\",\"domain\":\"localhost.local\",\"path\":\"\\/\",\"created_at\":\"2009-09-11 12:51:03 -0600\",\"expiry\":\"2028-11-01 12:00:00 GMT\",\"secure\":true}]}"
213
+ it 'should deserialize a JSON hash to a jar' do
214
+ json = '{"cookies":[{"name":"foo","value":"bar","domain":"localhost.local","path":"\\/","created_at":"2009-09-11 12:51:03 -0600","expiry":"2028-11-01 12:00:00 GMT","secure":true}]}'
218
215
  hash = JSON.parse json
219
-
216
+
220
217
  jar = Jar.json_create hash
221
- jar.get_cookies('https://localhost/').should have(1).items
218
+ expect(jar.get_cookies('https://localhost/')).to have(1).items
222
219
  end
223
-
224
- it "should automatically deserialize to a jar" do
225
- json = "{\"json_class\":\"CookieJar::Jar\",\"cookies\":[{\"name\":\"foo\",\"value\":\"bar\",\"domain\":\"localhost.local\",\"path\":\"\\/\",\"created_at\":\"2009-09-11 12:51:03 -0600\",\"expiry\":\"2028-11-01 12:00:00 GMT\",\"secure\":true}]}"
226
- jar = JSON.parse json, :create_additions => true
227
- jar.get_cookies('https://localhost/').should have(1).items
220
+
221
+ it 'should automatically deserialize to a jar' do
222
+ json = '{"json_class":"CookieJar::Jar","cookies":[{"name":"foo","value":"bar","domain":"localhost.local","path":"\\/","created_at":"2009-09-11 12:51:03 -0600","expiry":"2028-11-01 12:00:00 GMT","secure":true}]}'
223
+ jar = JSON.parse json, create_additions: true
224
+ expect(jar.get_cookies('https://localhost/')).to have(1).items
228
225
  end
229
226
  end
230
227
  rescue LoadError
231
- it "does not appear the JSON library is installed" do
232
- raise 'please install the JSON lirbary'
228
+ it 'does not appear the JSON library is installed' do
229
+ raise 'please install the JSON library'
233
230
  end
234
231
  end
235
232
  end