cookiejar 0.3.2 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/cookiejar.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'cookiejar/cookie'
2
- require 'cookiejar/jar'
2
+ require 'cookiejar/jar'
3
+ require 'cookiejar/version'
data/spec/cookie_spec.rb CHANGED
@@ -1,176 +1,176 @@
1
- require 'cookiejar'
2
- require 'rubygems'
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
3
 
4
4
  include CookieJar
5
5
 
6
- FOO_URL = 'http://localhost/foo'
7
- AMMO_URL = 'http://localhost/ammo'
6
+ FOO_URL = 'http://localhost/foo'.freeze
7
+ AMMO_URL = 'http://localhost/ammo'.freeze
8
8
  NETSCAPE_SPEC_SET_COOKIE_HEADERS =
9
- [['CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday, 09-Nov-99 23:12:40 GMT',
9
+ [['CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday, 09-Nov-99 23:12:40 GMT',
10
10
  FOO_URL],
11
- ['PART_NUMBER=ROCKET_LAUNCHER_0001; path=/',
11
+ ['PART_NUMBER=ROCKET_LAUNCHER_0001; path=/',
12
12
  FOO_URL],
13
- ['SHIPPING=FEDEX; path=/foo',
13
+ ['SHIPPING=FEDEX; path=/foo',
14
14
  FOO_URL],
15
- ['PART_NUMBER=ROCKET_LAUNCHER_0001; path=/',
15
+ ['PART_NUMBER=ROCKET_LAUNCHER_0001; path=/',
16
16
  FOO_URL],
17
- ['PART_NUMBER=RIDING_ROCKET_0023; path=/ammo',
18
- AMMO_URL]]
17
+ ['PART_NUMBER=RIDING_ROCKET_0023; path=/ammo',
18
+ AMMO_URL]].freeze
19
19
 
20
20
  describe Cookie do
21
- describe "#from_set_cookie" do
22
- it "should handle cookies from the netscape spec" do
21
+ describe '#from_set_cookie' do
22
+ it 'should handle cookies from the netscape spec' do
23
23
  NETSCAPE_SPEC_SET_COOKIE_HEADERS.each do |value|
24
24
  header, url = *value
25
- cookie = Cookie.from_set_cookie url, header
25
+ Cookie.from_set_cookie url, header
26
26
  end
27
27
  end
28
- it "should give back the input names and values" do
28
+ it 'should give back the input names and values' do
29
29
  cookie = Cookie.from_set_cookie 'http://localhost/', 'foo=bar'
30
- cookie.name.should == 'foo'
31
- cookie.value.should == 'bar'
30
+ expect(cookie.name).to eq 'foo'
31
+ expect(cookie.value).to eq 'bar'
32
32
  end
33
- it "should normalize domain names" do
33
+ it 'should normalize domain names' do
34
34
  cookie = Cookie.from_set_cookie 'http://localhost/', 'foo=Bar;domain=LoCaLHoSt.local'
35
- cookie.domain.should == '.localhost.local'
35
+ expect(cookie.domain).to eq '.localhost.local'
36
36
  end
37
- it "should accept non-normalized .local" do
37
+ it 'should accept non-normalized .local' do
38
38
  cookie = Cookie.from_set_cookie 'http://localhost/', 'foo=bar;domain=.local'
39
- cookie.domain.should == '.local'
39
+ expect(cookie.domain).to eq '.local'
40
40
  end
41
- it "should accept secure cookies" do
41
+ it 'should accept secure cookies' do
42
42
  cookie = Cookie.from_set_cookie 'https://www.google.com/a/blah', 'GALX=RgmSftjnbPM;Path=/a/;Secure'
43
- cookie.name.should == 'GALX'
44
- cookie.secure.should be_true
43
+ expect(cookie.name).to eq 'GALX'
44
+ expect(cookie.secure).to be_truthy
45
45
  end
46
46
  end
47
- describe "#from_set_cookie2" do
48
- it "should give back the input names and values" do
47
+ describe '#from_set_cookie2' do
48
+ it 'should give back the input names and values' do
49
49
  cookie = Cookie.from_set_cookie2 'http://localhost/', 'foo=bar;Version=1'
50
- cookie.name.should == 'foo'
51
- cookie.value.should == 'bar'
50
+ expect(cookie.name).to eq 'foo'
51
+ expect(cookie.value).to eq 'bar'
52
52
  end
53
- it "should normalize domain names" do
53
+ it 'should normalize domain names' do
54
54
  cookie = Cookie.from_set_cookie2 'http://localhost/', 'foo=Bar;domain=LoCaLHoSt.local;Version=1'
55
- cookie.domain.should == '.localhost.local'
55
+ expect(cookie.domain).to eq '.localhost.local'
56
56
  end
57
- it "should accept non-normalized .local" do
57
+ it 'should accept non-normalized .local' do
58
58
  cookie = Cookie.from_set_cookie2 'http://localhost/', 'foo=bar;domain=.local;Version=1'
59
- cookie.domain.should == '.local'
59
+ expect(cookie.domain).to eq '.local'
60
60
  end
61
- it "should accept secure cookies" do
61
+ it 'should accept secure cookies' do
62
62
  cookie = Cookie.from_set_cookie2 'https://www.google.com/a/blah', 'GALX=RgmSftjnbPM;Path="/a/";Secure;Version=1'
63
- cookie.name.should == 'GALX'
64
- cookie.path.should == '/a/'
65
- cookie.secure.should be_true
63
+ expect(cookie.name).to eq 'GALX'
64
+ expect(cookie.path).to eq '/a/'
65
+ expect(cookie.secure).to be_truthy
66
66
  end
67
- it "should fail on unquoted paths" do
68
- lambda do
69
- Cookie.from_set_cookie2 'https://www.google.com/a/blah',
70
- 'GALX=RgmSftjnbPM;Path=/a/;Secure;Version=1'
71
- end.should raise_error InvalidCookieError
67
+ it 'should fail on unquoted paths' do
68
+ expect {
69
+ Cookie.from_set_cookie2 'https://www.google.com/a/blah',
70
+ 'GALX=RgmSftjnbPM;Path=/a/;Secure;Version=1'
71
+ }.to raise_error InvalidCookieError
72
72
  end
73
- it "should accept quoted values" do
73
+ it 'should accept quoted values' do
74
74
  cookie = Cookie.from_set_cookie2 'http://localhost/', 'foo="bar";Version=1'
75
- cookie.name.should == 'foo'
76
- cookie.value.should == '"bar"'
75
+ expect(cookie.name).to eq 'foo'
76
+ expect(cookie.value).to eq '"bar"'
77
77
  end
78
- it "should accept poorly chosen names" do
78
+ it 'should accept poorly chosen names' do
79
79
  cookie = Cookie.from_set_cookie2 'http://localhost/', 'Version=mine;Version=1'
80
- cookie.name.should == 'Version'
81
- cookie.value.should == 'mine'
80
+ expect(cookie.name).to eq 'Version'
81
+ expect(cookie.value).to eq 'mine'
82
82
  end
83
- it "should accept quoted parameter values" do
84
- cookie = Cookie.from_set_cookie2 'http://localhost/', 'foo=bar;Version="1"'
83
+ it 'should accept quoted parameter values' do
84
+ Cookie.from_set_cookie2 'http://localhost/', 'foo=bar;Version="1"'
85
85
  end
86
- it "should honor the discard and max-age parameters" do
86
+ it 'should honor the discard and max-age parameters' do
87
87
  cookie = Cookie.from_set_cookie2 'http://localhost/', 'f=b;max-age=100;discard;Version=1'
88
- cookie.should be_session
89
- cookie.should_not be_expired
90
-
88
+ expect(cookie).to be_session
89
+ expect(cookie).to_not be_expired
90
+
91
91
  cookie = Cookie.from_set_cookie2 'http://localhost/', 'f=b;max-age=100;Version=1'
92
- cookie.should_not be_session
92
+ expect(cookie).to_not be_session
93
93
 
94
94
  cookie = Cookie.from_set_cookie2 'http://localhost/', 'f=b;Version=1'
95
- cookie.should be_session
95
+ expect(cookie).to be_session
96
96
  end
97
- it "should handle quotable quotes" do
97
+ it 'should handle quotable quotes' do
98
98
  cookie = Cookie.from_set_cookie2 'http://localhost/', 'f="\"";Version=1'
99
- cookie.value.should eql '"\""'
99
+ expect(cookie.value).to eq '"\""'
100
100
  end
101
- it "should handle quotable apostrophes" do
101
+ it 'should handle quotable apostrophes' do
102
102
  cookie = Cookie.from_set_cookie2 'http://localhost/', 'f="\;";Version=1'
103
- cookie.value.should eql '"\;"'
103
+ expect(cookie.value).to eq '"\;"'
104
104
  end
105
105
  end
106
106
  describe '#decoded_value' do
107
- it "should leave normal values alone" do
107
+ it 'should leave normal values alone' do
108
108
  cookie = Cookie.from_set_cookie2 'http://localhost/', 'f=b;Version=1'
109
- cookie.decoded_value.should eql 'b'
109
+ expect(cookie.decoded_value).to eq 'b'
110
110
  end
111
- it "should attempt to unencode quoted values" do
111
+ it 'should attempt to unencode quoted values' do
112
112
  cookie = Cookie.from_set_cookie2 'http://localhost/', 'f="\"b";Version=1'
113
- cookie.value.should eql '"\"b"'
114
- cookie.decoded_value.should eql '"b'
113
+ expect(cookie.value).to eq '"\"b"'
114
+ expect(cookie.decoded_value).to eq '"b'
115
115
  end
116
116
  end
117
117
  describe '#to_s' do
118
- it "should handle a simple cookie" do
118
+ it 'should handle a simple cookie' do
119
119
  cookie = Cookie.from_set_cookie 'http://localhost/', 'f=b'
120
- cookie.to_s.should == 'f=b'
121
- cookie.to_s(1).should == '$Version=0;f=b;$Path="/"'
120
+ expect(cookie.to_s).to eq 'f=b'
121
+ expect(cookie.to_s(1)).to eq '$Version=0;f=b;$Path="/"'
122
122
  end
123
- it "should report an explicit domain" do
123
+ it 'should report an explicit domain' do
124
124
  cookie = Cookie.from_set_cookie2 'http://localhost/', 'f=b;Version=1;Domain=.local'
125
- cookie.to_s(1).should == '$Version=1;f=b;$Path="/";$Domain=.local'
125
+ expect(cookie.to_s(1)).to eq '$Version=1;f=b;$Path="/";$Domain=.local'
126
126
  end
127
- it "should return specified ports" do
127
+ it 'should return specified ports' do
128
128
  cookie = Cookie.from_set_cookie2 'http://localhost/', 'f=b;Version=1;Port="80,443"'
129
- cookie.to_s(1).should == '$Version=1;f=b;$Path="/";$Port="80,443"'
129
+ expect(cookie.to_s(1)).to eq '$Version=1;f=b;$Path="/";$Port="80,443"'
130
130
  end
131
- it "should handle specified paths" do
131
+ it 'should handle specified paths' do
132
132
  cookie = Cookie.from_set_cookie 'http://localhost/bar/', 'f=b;path=/bar/'
133
- cookie.to_s.should == 'f=b'
134
- cookie.to_s(1).should == '$Version=0;f=b;$Path="/bar/"'
133
+ expect(cookie.to_s).to eq 'f=b'
134
+ expect(cookie.to_s(1)).to eq '$Version=0;f=b;$Path="/bar/"'
135
135
  end
136
- it "should omit $Version header when asked" do
136
+ it 'should omit $Version header when asked' do
137
137
  cookie = Cookie.from_set_cookie 'http://localhost/', 'f=b'
138
- cookie.to_s(1,false).should == 'f=b;$Path="/"'
138
+ expect(cookie.to_s(1, false)).to eq 'f=b;$Path="/"'
139
139
  end
140
140
  end
141
141
  describe '#should_send?' do
142
- it "should not send if ports do not match" do
142
+ it 'should not send if ports do not match' do
143
143
  cookie = Cookie.from_set_cookie2 'http://localhost/', 'f=b;Version=1;Port="80"'
144
- cookie.should_send?("http://localhost/", false).should be_true
145
- cookie.should_send?("https://localhost/", false).should be_false
144
+ expect(cookie.should_send?('http://localhost/', false)).to be_truthy
145
+ expect(cookie.should_send?('https://localhost/', false)).to be_falsey
146
146
  end
147
147
  end
148
148
  begin
149
149
  require 'json'
150
- describe ".to_json" do
151
- it "should serialize a cookie to JSON" do
150
+ describe '.to_json' do
151
+ it 'should serialize a cookie to JSON' do
152
152
  c = Cookie.from_set_cookie 'https://localhost/', 'foo=bar;secure;expires=Fri, September 11 2009 18:10:00 -0700'
153
153
  json = c.to_json
154
- json.should be_a String
154
+ expect(json).to be_a String
155
155
  end
156
156
  end
157
- describe ".json_create" do
158
- it "should deserialize JSON to a cookie" do
159
- json = "{\"name\":\"foo\",\"value\":\"bar\",\"domain\":\"localhost.local\",\"path\":\"\\/\",\"created_at\":\"2009-09-11 12:51:03 -0600\",\"expiry\":\"2009-09-11 19:10:00 -0600\",\"secure\":true}"
157
+ describe '.json_create' do
158
+ it 'should deserialize JSON to a cookie' do
159
+ json = '{"name":"foo","value":"bar","domain":"localhost.local","path":"\\/","created_at":"2009-09-11 12:51:03 -0600","expiry":"2009-09-11 19:10:00 -0600","secure":true}'
160
160
  hash = JSON.parse json
161
161
  c = Cookie.json_create hash
162
162
  CookieValidation.validate_cookie 'https://localhost/', c
163
163
  end
164
- it "should automatically deserialize to a cookie" do
165
- json = "{\"json_class\":\"CookieJar::Cookie\",\"name\":\"foo\",\"value\":\"bar\",\"domain\":\"localhost.local\",\"path\":\"\\/\",\"created_at\":\"2009-09-11 12:51:03 -0600\",\"expiry\":\"2009-09-11 19:10:00 -0600\",\"secure\":true}"
166
- c = JSON.parse json, :create_additions => true
167
- c.should be_a Cookie
164
+ it 'should automatically deserialize to a cookie' do
165
+ json = '{"json_class":"CookieJar::Cookie","name":"foo","value":"bar","domain":"localhost.local","path":"\\/","created_at":"2009-09-11 12:51:03 -0600","expiry":"2009-09-11 19:10:00 -0600","secure":true}'
166
+ c = JSON.parse json, create_additions: true
167
+ expect(c).to be_a Cookie
168
168
  CookieValidation.validate_cookie 'https://localhost/', c
169
169
  end
170
170
  end
171
171
  rescue LoadError
172
- it "does not appear the JSON library is installed" do
173
- raise "please install the JSON library"
172
+ it 'does not appear the JSON library is installed' do
173
+ raise 'please install the JSON library'
174
174
  end
175
175
  end
176
176
  end