cookie_store 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 806d7fee9bc861c73d9e390e0d3bfbc5c5ece797
4
- data.tar.gz: 7b92809c676dccebd896f876bace50256576cde7
3
+ metadata.gz: 2fa62b0946bb98fb4646dd6d5a12cf0470ccca8c
4
+ data.tar.gz: 7c60534b13a7e21151635f0985083edba439215f
5
5
  SHA512:
6
- metadata.gz: 1f7a35021d374cf51d8ac896870f15c9a97f2766edb56f1ab2dcfeb18dff50ad7224078ee616cf2f2f940968b9e14005099404373578cb424fdc1f28f228f209
7
- data.tar.gz: aec3b0876c4df351a7bf1f0c6da82a7d103dc299e9a21a67d98c4ec663499b427803220c1467de5511a3c117521e918f65fbe16a60b76848259bec8ff25a1db9
6
+ metadata.gz: 4933dd902e5701f015ffc4f8b5c95ae869311505d3d3a054027c6aa31b96bb1b5d14751f751c2b6664e5c095faf1ae3912301b7640f5f18f70a20f59d1aa5385
7
+ data.tar.gz: fec53203a8553011616023c165ca20217dad219cce3c713e22ab28f791034112aca8335502e77e66f7653ec8344b5ffa7afe6df77e6356da67f85e29ad1c0956
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cookie_store (0.1.2)
4
+ cookie_store (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -52,3 +52,6 @@ DEPENDENCIES
52
52
  mocha
53
53
  rake
54
54
  webmock
55
+
56
+ BUNDLED WITH
57
+ 1.10.4
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "cookie_store"
6
- s.version = '0.1.3'
6
+ s.version = '0.1.4'
7
7
  s.authors = ["Jon Bracy"]
8
8
  s.email = ["jonbracy@gmail.com"]
9
9
  s.homepage = "https://github.com/malomalo/cookie_store"
@@ -14,15 +14,16 @@ class CookieStore
14
14
  # Read and set the cookie from the Set-Cookie header
15
15
  def set_cookie(request_uri, set_cookie_value)
16
16
  request_uri = URI.parse(request_uri)
17
- cookie = CookieStore::Cookie.parse(request_uri, set_cookie_value)
18
-
19
- # reject as per RFC2965 Section 3.3.2
20
- return if !cookie.request_match?(request_uri) || !(cookie.domain =~ /.+\..+/ || cookie.domain == 'localhost')
21
17
 
22
- # reject cookies over the max-bytes
23
- return if cookie.to_s.size > MAX_COOKIE_LENGTH
18
+ CookieStore::Cookie.parse_cookies(request_uri, set_cookie_value).each do |cookie|
19
+ # reject as per RFC2965 Section 3.3.2
20
+ return if !cookie.request_match?(request_uri) || !(cookie.domain =~ /.+\..+/ || cookie.domain == 'localhost')
21
+
22
+ # reject cookies over the max-bytes
23
+ return if cookie.to_s.size > MAX_COOKIE_LENGTH
24
24
 
25
- add(cookie)
25
+ add(cookie)
26
+ end
26
27
  end
27
28
 
28
29
  def cookie_header_for(request_uri)
@@ -7,10 +7,11 @@ class CookieStore::Cookie
7
7
  IPADDR = /\A#{URI::REGEXP::PATTERN::IPV4ADDR}\Z|\A#{URI::REGEXP::PATTERN::IPV6ADDR}\Z/
8
8
 
9
9
  TOKEN = '[^(),\/<>@;:\\\"\[\]?={}\s]+'
10
- VALUE = "(?:#{TOKEN}|#{IPADDR}|#{QUOTED_TEXT})"
10
+ VALUE = "(?:#{TOKEN}|#{IPADDR}|[^,;\\s]+)"
11
11
  EXPIRES_AT_VALUE = '[A-Za-z]{3},\ \d{2}[-\ ][A-Za-z]{3}[-\ ]\d{4}\ \d{2}:\d{2}:\d{2}\ (?:[A-Z]{3}|[-+]\d{4})'
12
12
  NUMERICAL_TIMEZONE = /[-+]\d{4}$/
13
-
13
+
14
+
14
15
  COOKIE = /(?<name>#{TOKEN})=(?:"(?<quoted_value>#{QUOTED_TEXT})"|(?<value>#{VALUE}))(?<attributes>.*)/n
15
16
  COOKIE_AV = %r{
16
17
  ;\s+
@@ -24,6 +25,12 @@ class CookieStore::Cookie
24
25
  )
25
26
  ){0,1}
26
27
  }nx
28
+ COOKIES = %r{
29
+ #{TOKEN}=(?:"#{QUOTED_TEXT}"|#{VALUE})
30
+ (?:;\s+#{TOKEN}(?:=(?:"#{QUOTED_TEXT}"|(?:#{EXPIRES_AT_VALUE}|#{VALUE}))){0,1})*
31
+ }nx
32
+
33
+
27
34
 
28
35
  # [String] The name of the cookie.
29
36
  attr_reader :name
@@ -179,6 +186,15 @@ class CookieStore::Cookie
179
186
  ports.include?(request_port)
180
187
  end
181
188
 
189
+ def self.parse_cookies(request_uri, set_cookie_value)
190
+ uri = request_uri.is_a?(URI) ? request_uri : URI.parse(request_uri)
191
+ cookies = []
192
+ set_cookie_value.scan(COOKIES) do |cookie|
193
+ cookies << parse(uri, cookie)
194
+ end
195
+ cookies
196
+ end
197
+
182
198
  def self.parse(request_uri, set_cookie_value)
183
199
  uri = request_uri.is_a?(URI) ? request_uri : URI.parse(request_uri)
184
200
  data = COOKIE.match(set_cookie_value)
@@ -331,6 +331,28 @@ class CookieStore::CookieTest < Minitest::Test
331
331
  cookie = CookieStore::Cookie.parse('http://google.com/test/this', 'foo=bar; Max-Age=3660')
332
332
  assert_equal 3660, cookie.max_age
333
333
  end
334
+
335
+ test "::parse_cookies with one cookie" do
336
+ cookies = CookieStore::Cookie.parse_cookies("http://google.com/test/this", "current_account_id=2449; path=/")
337
+
338
+ assert_equal "current_account_id", cookies.first.name
339
+ assert_equal "2449", cookies.first.value
340
+ assert_equal "/", cookies.first.path
341
+ end
342
+
343
+ test "::parse_cookies with multiple cookies" do
344
+ cookies = CookieStore::Cookie.parse_cookies("http://google.com/test/this", "current_account_id=2449; path=/, _session=QUZwVE5jNjB; path=/test; expires=Wed, 13-Jan-2021 22:23:01 GMT; HttpOnly")
345
+
346
+ assert_equal "current_account_id", cookies.first.name
347
+ assert_equal "2449", cookies.first.value
348
+ assert_equal "/", cookies.first.path
349
+
350
+ assert_equal "_session", cookies[1].name
351
+ assert_equal "QUZwVE5jNjB", cookies[1].value
352
+ assert_equal "/test", cookies[1].path
353
+ assert_equal DateTime.new(2021, 1, 13, 22, 23, 1, 0), cookies[1].expires
354
+ assert_equal true, cookies[1].http_only
355
+ end
334
356
 
335
357
  # TODO: test expires_at, based on expires attribute
336
358
  # TODO: test expires_at, based on max-age attribute
@@ -13,6 +13,13 @@ class CookieStoreTest < Minitest::Test
13
13
  store.set_cookie('http://127.0.0.1/test/this', 'foo=bar; Max-Age=3600')
14
14
  end
15
15
 
16
+ test "#set_cookie contains multiple cookies" do
17
+ store = CookieStore.new
18
+ store.expects(:add).times(2)
19
+
20
+ store.set_cookie("http://google.com/test/this", "current_account_id=2449; path=/, _session=QUZwVE5jNjB; path=/test; expires=Wed, 13-Jan-2021 22:23:01 GMT; HttpOnly")
21
+ end
22
+
16
23
  test "#set_cookie rejects cookies where the value for the Domain attribute contains no embedded dots" do
17
24
  store = CookieStore.new
18
25
  store.expects(:add).never
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cookie_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-21 00:00:00.000000000 Z
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  requirements: []
149
149
  rubyforge_project:
150
- rubygems_version: 2.2.2
150
+ rubygems_version: 2.4.5
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: A Ruby library to handle client-side HTTP cookies