strelka 0.0.1.pre.308 → 0.0.1.pre.309
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +10 -3
- data/lib/strelka/constants.rb +66 -0
- data/lib/strelka/cookie.rb +91 -119
- data/lib/strelka/exceptions.rb +3 -0
- data/spec/strelka/cookie_spec.rb +41 -89
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
data/ChangeLog
CHANGED
@@ -1,10 +1,17 @@
|
|
1
|
+
2012-09-25 Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
* lib/strelka/constants.rb, lib/strelka/cookie.rb,
|
4
|
+
lib/strelka/exceptions.rb, spec/strelka/cookie_spec.rb:
|
5
|
+
Updating Strelka::Cookie to adhere to rfc6265
|
6
|
+
[04568539aa83] [tip]
|
7
|
+
|
1
8
|
2012-09-21 Michael Granger <ged@FaerieMUD.org>
|
2
9
|
|
3
10
|
* Manifest.txt, lib/strelka/testing.rb, spec/lib/helpers.rb:
|
4
11
|
Split out some testing helper functions and RSpec matchers.
|
5
12
|
|
6
13
|
Put them into 'strelka/testing' ala 'mongrel2/testing'.
|
7
|
-
[c58b05ad837b]
|
14
|
+
[c58b05ad837b]
|
8
15
|
|
9
16
|
* lib/strelka/constants.rb:
|
10
17
|
Header fix
|
@@ -58,7 +65,7 @@
|
|
58
65
|
|
59
66
|
Got most of the default plugins covered at least minimally. Split
|
60
67
|
out the rest of the manual into RDoc pages.
|
61
|
-
[41ef7a20e7cb]
|
68
|
+
[41ef7a20e7cb]
|
62
69
|
|
63
70
|
2012-08-24 Mahlon E. Smith <mahlon@martini.nu>
|
64
71
|
|
@@ -1065,7 +1072,7 @@
|
|
1065
1072
|
|
1066
1073
|
* lib/strelka/app/errors.rb, spec/strelka/app/errors_spec.rb:
|
1067
1074
|
Add documentation for the Errors plugin, improve test coverage.
|
1068
|
-
[ff3ef6e5a7a1]
|
1075
|
+
[ff3ef6e5a7a1]
|
1069
1076
|
|
1070
1077
|
* Manifest.txt:
|
1071
1078
|
Add session files to the manifest
|
data/lib/strelka/constants.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
3
3
|
# encoding: utf-8
|
4
4
|
|
5
|
+
require 'uri'
|
5
6
|
require 'mongrel2/constants'
|
6
7
|
require 'strelka' unless defined?( Strelka )
|
7
8
|
|
@@ -30,5 +31,70 @@ module Strelka::Constants
|
|
30
31
|
|
31
32
|
end # module HTTP
|
32
33
|
|
34
|
+
|
35
|
+
# Constants for parsing Cookie headers, mostly taken from
|
36
|
+
# RFC6265 - HTTP State Management Mechanism
|
37
|
+
#
|
38
|
+
# http://tools.ietf.org/html/rfc6265
|
39
|
+
#
|
40
|
+
module CookieHeader
|
41
|
+
|
42
|
+
# Literals
|
43
|
+
CRLF = "\r\n"
|
44
|
+
WSP = '[\\x20\\t]'
|
45
|
+
|
46
|
+
# OWS = *( [ obs-fold ] WSP )
|
47
|
+
# ; "optional" whitespace
|
48
|
+
# obs-fold = CRLF
|
49
|
+
OBS_FOLD = CRLF
|
50
|
+
OWS = /(#{OBS_FOLD}#{WSP})*/
|
51
|
+
|
52
|
+
# CTL = <any US-ASCII control character
|
53
|
+
# (octets 0 - 31) and DEL (127)>
|
54
|
+
CTL = '[:cntrl:]'
|
55
|
+
|
56
|
+
# separators = "(" | ")" | "<" | ">" | "@"
|
57
|
+
# | "," | ";" | ":" | "\" | <">
|
58
|
+
# | "/" | "[" | "]" | "?" | "="
|
59
|
+
# | "{" | "}" | SP | HT
|
60
|
+
SEPARATORS = '\\x28\\x29\\x3c\\x3e\\x40' +
|
61
|
+
'\\x2c\\x3b\\x3a\\x5c\\x22' +
|
62
|
+
'\\x2f\\x5b\\x5d\\x3f\\x3d' +
|
63
|
+
'\\x7b\\x7d\x20\x09'
|
64
|
+
|
65
|
+
# Double-quote
|
66
|
+
DQUOTE = '"'
|
67
|
+
|
68
|
+
# token = 1*<any CHAR except CTLs or separators>
|
69
|
+
TOKEN = %r{ [^#{CTL}#{SEPARATORS}]+ }x
|
70
|
+
|
71
|
+
# cookie-name = token
|
72
|
+
COOKIE_NAME = /(?<cookie_name>#{TOKEN})/
|
73
|
+
|
74
|
+
# cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
|
75
|
+
# ; US-ASCII characters excluding CTLs,
|
76
|
+
# ; whitespace DQUOTE, comma, semicolon,
|
77
|
+
# ; and backslash
|
78
|
+
COOKIE_OCTET = '[\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]'
|
79
|
+
|
80
|
+
# cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
|
81
|
+
COOKIE_VALUE = %r{(?<cookie_value>
|
82
|
+
#{COOKIE_OCTET}*
|
83
|
+
|
|
84
|
+
#{DQUOTE} #{COOKIE_OCTET}*? #{DQUOTE}
|
85
|
+
)}x
|
86
|
+
|
87
|
+
# cookie-pair = cookie-name "=" cookie-value
|
88
|
+
COOKIE_PAIR = %r{(?<cookie_pair>
|
89
|
+
#{COOKIE_NAME}
|
90
|
+
=
|
91
|
+
#{COOKIE_VALUE}
|
92
|
+
)}x
|
93
|
+
|
94
|
+
# Version option (not part of RFC6265)
|
95
|
+
COOKIE_VERSION = /;\s*Version=(?<version>\d+)/i
|
96
|
+
|
97
|
+
end # module Cookie
|
98
|
+
|
33
99
|
end # module Strelka::Constants
|
34
100
|
|
data/lib/strelka/cookie.rb
CHANGED
@@ -4,10 +4,11 @@
|
|
4
4
|
|
5
5
|
require 'date'
|
6
6
|
require 'time'
|
7
|
-
require 'uri'
|
8
7
|
require 'loggability'
|
9
8
|
|
10
9
|
require 'strelka' unless defined?( Strelka )
|
10
|
+
require 'strelka/exceptions'
|
11
|
+
require 'strelka/constants'
|
11
12
|
require 'strelka/mixins'
|
12
13
|
|
13
14
|
# The Strelka::Cookie class, a class for parsing and generating HTTP cookies.
|
@@ -26,6 +27,7 @@ require 'strelka/mixins'
|
|
26
27
|
# * http://tools.ietf.org/html/rfc6265
|
27
28
|
#
|
28
29
|
class Strelka::Cookie
|
30
|
+
include Strelka::Constants::CookieHeader
|
29
31
|
extend Loggability
|
30
32
|
|
31
33
|
# Loggability API -- set up logging under the 'strelka' log host
|
@@ -35,47 +37,6 @@ class Strelka::Cookie
|
|
35
37
|
# The format of the date field
|
36
38
|
COOKIE_DATE_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
|
37
39
|
|
38
|
-
### RFC 2109: HTTP State Management Mechanism
|
39
|
-
# When it sends a request to an origin server, the user agent sends a
|
40
|
-
# Cookie request header to the origin server if it has cookies that are
|
41
|
-
# applicable to the request, based on
|
42
|
-
#
|
43
|
-
# * the request-host;
|
44
|
-
# * the request-URI;
|
45
|
-
# * the cookie's age.
|
46
|
-
#
|
47
|
-
# The syntax for the header is:
|
48
|
-
#
|
49
|
-
# cookie = "Cookie:" cookie-version
|
50
|
-
# 1*((";" | ",") cookie-value)
|
51
|
-
# cookie-value = NAME "=" VALUE [";" path] [";" domain]
|
52
|
-
# cookie-version = "$Version" "=" value
|
53
|
-
# NAME = attr
|
54
|
-
# VALUE = value
|
55
|
-
# path = "$Path" "=" value
|
56
|
-
# domain = "$Domain" "=" value
|
57
|
-
|
58
|
-
# Parser constants
|
59
|
-
COOKIE_VERSION = /\$Version\s*=\s*(.+)\s*[,;]/
|
60
|
-
COOKIE_PATH = /\$Path/i
|
61
|
-
COOKIE_DOMAIN = /\$Domain/i
|
62
|
-
|
63
|
-
### RFC2068: Hypertext Transfer Protocol -- HTTP/1.1
|
64
|
-
# CTL = <any US-ASCII control character
|
65
|
-
# (octets 0 - 31) and DEL (127)>
|
66
|
-
# token = 1*<any CHAR except CTLs or tspecials>
|
67
|
-
#
|
68
|
-
# tspecials = "(" | ")" | "<" | ">" | "@"
|
69
|
-
# | "," | ";" | ":" | "\" | <">
|
70
|
-
# | "/" | "[" | "]" | "?" | "="
|
71
|
-
# | "{" | "}" | SP | HT
|
72
|
-
|
73
|
-
# Cookie-value parser constants
|
74
|
-
CTLs = "[:cntrl:]"
|
75
|
-
TSPECIALS = Regexp.quote( ' "(),/:;<=>?@[\\]{}' )
|
76
|
-
NON_TOKEN_CHAR = /[#{CTLs}#{TSPECIALS}]/s
|
77
|
-
HTTP_TOKEN = /\A[^#{CTLs}#{TSPECIALS}]+\z/s
|
78
|
-
|
79
40
|
# Number of seconds in the various offset types
|
80
41
|
UNIT_SECONDS = {
|
81
42
|
's' => 1,
|
@@ -90,16 +51,7 @@ class Strelka::Cookie
|
|
90
51
|
### Strip surrounding double quotes from a copy of the specified string
|
91
52
|
### and return it.
|
92
53
|
def self::dequote( string )
|
93
|
-
/^"
|
94
|
-
end
|
95
|
-
|
96
|
-
|
97
|
-
### Parse a cookie value string, returning an Array of Strings
|
98
|
-
def self::parse_valuestring( valstr )
|
99
|
-
return [] unless valstr
|
100
|
-
valstr = dequote( valstr )
|
101
|
-
|
102
|
-
return valstr.split('&').collect{|str| URI.decode_www_form_component(str) }
|
54
|
+
return string.gsub( /^"|"$/, '' )
|
103
55
|
end
|
104
56
|
|
105
57
|
|
@@ -108,49 +60,33 @@ class Strelka::Cookie
|
|
108
60
|
def self::parse( header )
|
109
61
|
return {} if header.nil? or header.empty?
|
110
62
|
self.log.debug "Parsing cookie header: %p" % [ header ]
|
111
|
-
cookies =
|
63
|
+
cookies = {}
|
112
64
|
version = 0
|
113
65
|
header = header.strip
|
114
66
|
|
115
67
|
# "$Version" = value
|
116
|
-
if COOKIE_VERSION.match( header )
|
117
|
-
self.log.debug " Found cookie version %p" % [
|
118
|
-
version = Integer( dequote(
|
68
|
+
if m = COOKIE_VERSION.match( header )
|
69
|
+
self.log.debug " Found cookie version %p" % [ m[:version] ]
|
70
|
+
version = Integer( dequote(m[:version]) )
|
119
71
|
header.slice!( COOKIE_VERSION )
|
120
72
|
end
|
121
73
|
|
122
|
-
#
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
case key
|
128
|
-
when COOKIE_PATH
|
129
|
-
self.log.debug " -> cookie-path %p" % [ valstr ]
|
130
|
-
cookies.last.path = dequote( valstr ) unless cookies.empty?
|
131
|
-
|
132
|
-
when COOKIE_DOMAIN
|
133
|
-
self.log.debug " -> cookie-domain %p" % [ valstr ]
|
134
|
-
cookies.last.domain = dequote( valstr ) unless cookies.empty?
|
135
|
-
|
136
|
-
when HTTP_TOKEN
|
137
|
-
values = parse_valuestring( valstr )
|
138
|
-
self.log.debug " -> cookie-values %p" % [ values ]
|
139
|
-
cookies << new( key, values, :version => version )
|
140
|
-
|
141
|
-
else
|
142
|
-
self.log.warn \
|
143
|
-
"Malformed cookie header %p: %p is not a valid token; ignoring" %
|
144
|
-
[ header, key ]
|
145
|
-
end
|
146
|
-
end
|
74
|
+
# cookie-header = "Cookie:" OWS cookie-string OWS
|
75
|
+
# cookie-string = cookie-pair *( ";" SP cookie-pair )
|
76
|
+
header.split( /;\x20/ ).each do |cookie_pair|
|
77
|
+
self.log.debug " parsing cookie-pair: %p" % [ cookie_pair ]
|
78
|
+
next unless match = cookie_pair.match( COOKIE_PAIR )
|
147
79
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
80
|
+
self.log.debug " matched cookie: %p" % [ match ]
|
81
|
+
name = match[:cookie_name].untaint
|
82
|
+
value = match[:cookie_value]
|
83
|
+
value = self.dequote( value ) if value.start_with?( DQUOTE )
|
84
|
+
value = nil if value.empty?
|
85
|
+
|
86
|
+
cookies[ name.to_sym ] = new( name, value, :version => version )
|
153
87
|
end
|
88
|
+
|
89
|
+
return cookies
|
154
90
|
end
|
155
91
|
|
156
92
|
|
@@ -161,33 +97,33 @@ class Strelka::Cookie
|
|
161
97
|
### Create a new Strelka::Cookie object with the specified +name+ and
|
162
98
|
### +values+. Valid options are:
|
163
99
|
###
|
164
|
-
###
|
100
|
+
### \version::
|
165
101
|
### The cookie version. 0 (the default) is fine for most uses
|
166
|
-
###
|
102
|
+
### \domain::
|
167
103
|
### The domain the cookie belongs to.
|
168
|
-
###
|
104
|
+
### \path::
|
169
105
|
### The path the cookie applies to.
|
170
|
-
###
|
106
|
+
### \secure::
|
171
107
|
### The cookie's 'secure' flag.
|
172
|
-
###
|
108
|
+
### \expires::
|
173
109
|
### The cookie's expiration (a Time object). See expires= for valid
|
174
110
|
### values.
|
175
|
-
###
|
111
|
+
### \max_age::
|
176
112
|
### The lifetime of the cookie, in seconds.
|
177
|
-
###
|
178
|
-
###
|
179
|
-
def initialize( name,
|
180
|
-
|
181
|
-
@name
|
182
|
-
@
|
183
|
-
|
184
|
-
@domain
|
185
|
-
@path
|
186
|
-
@secure
|
187
|
-
@
|
188
|
-
@max_age
|
189
|
-
@expires
|
190
|
-
@version
|
113
|
+
### \httponly::
|
114
|
+
### HttpOnly flag.
|
115
|
+
def initialize( name, value, options={} )
|
116
|
+
self.log.debug "New cookie: %p = %p (%p)" % [ name, value, options ]
|
117
|
+
@name = name
|
118
|
+
@value = value
|
119
|
+
|
120
|
+
@domain = nil
|
121
|
+
@path = nil
|
122
|
+
@secure = false
|
123
|
+
@httponly = false
|
124
|
+
@max_age = nil
|
125
|
+
@expires = nil
|
126
|
+
@version = 0
|
191
127
|
|
192
128
|
options.each do |meth, val|
|
193
129
|
self.__send__( "#{meth}=", val )
|
@@ -203,8 +139,8 @@ class Strelka::Cookie
|
|
203
139
|
# The name of the cookie
|
204
140
|
attr_accessor :name
|
205
141
|
|
206
|
-
# The
|
207
|
-
|
142
|
+
# The string value of the cookie
|
143
|
+
attr_reader :value
|
208
144
|
|
209
145
|
# The cookie version. 0 (the default) is fine for most uses
|
210
146
|
attr_accessor :version
|
@@ -218,30 +154,66 @@ class Strelka::Cookie
|
|
218
154
|
# The cookie's 'secure' flag.
|
219
155
|
attr_writer :secure
|
220
156
|
|
157
|
+
# The cookie's HttpOnly flag
|
158
|
+
attr_accessor :httponly
|
159
|
+
|
221
160
|
# The cookie's expiration (a Time object)
|
222
161
|
attr_reader :expires
|
223
162
|
|
224
163
|
# The lifetime of the cookie, in seconds.
|
225
164
|
attr_reader :max_age
|
226
165
|
|
227
|
-
# Because cookies can contain private information about a
|
228
|
-
# user, the Cookie attribute allows an origin server to document its
|
229
|
-
# intended use of a cookie. The user can inspect the information to
|
230
|
-
# decide whether to initiate or continue a session with this cookie.
|
231
|
-
attr_accessor :comment
|
232
166
|
|
167
|
+
### Set the new value of the cookie to +cookie_octets+. This raises an exception
|
168
|
+
### if +cookie_octets+ contains any invalid characters. If your value contains
|
169
|
+
### non-US-ASCII characters; control characters; or comma, semicolon, or backslash.
|
170
|
+
def value=( cookie_octets )
|
171
|
+
self.log.debug "Setting cookie value to: %p" % [ cookie_octets ]
|
172
|
+
raise Strelka::CookieError,
|
173
|
+
"invalid cookie value; value must be composed of non-control us-ascii characters " +
|
174
|
+
"other than SPACE, double-quote, comma, semi-colon, and backslash. " +
|
175
|
+
"Use #base64_value= for storing arbitrary data." unless
|
176
|
+
cookie_octets =~ /^#{COOKIE_VALUE}$/
|
233
177
|
|
234
|
-
|
235
|
-
def value
|
236
|
-
return @values.first
|
178
|
+
@value = cookie_octets
|
237
179
|
end
|
238
180
|
|
239
181
|
|
182
|
+
### Store the base64'ed +data+ as the cookie value. This is just a convenience
|
183
|
+
### method for:
|
184
|
+
###
|
185
|
+
### cookie.value = [data].pack('m').strip
|
186
|
+
###
|
187
|
+
def binary_value=( data )
|
188
|
+
self.log.debug "Setting cookie value to base64ed %p" % [ data ]
|
189
|
+
self.value = [ data ].pack( 'm' ).strip
|
190
|
+
end
|
191
|
+
alias_method :wrapped_value=, :binary_value=
|
192
|
+
|
193
|
+
|
194
|
+
### Fetch the cookie's data after un-base64ing it. This is just a convenience
|
195
|
+
### method for:
|
196
|
+
###
|
197
|
+
### cookie.value.unpack( 'm' ).first
|
198
|
+
###
|
199
|
+
def binary_value
|
200
|
+
return self.value.unpack( 'm' ).first
|
201
|
+
end
|
202
|
+
alias_method :wrapped_value, :binary_value
|
203
|
+
|
204
|
+
|
240
205
|
### Returns +true+ if the secure flag is set
|
241
206
|
def secure?
|
242
207
|
return @secure ? true : false
|
243
208
|
end
|
244
209
|
|
210
|
+
|
211
|
+
### Returns +true+ if the 'httponly' flag is set
|
212
|
+
def httponly?
|
213
|
+
return @httponly ? true : false
|
214
|
+
end
|
215
|
+
|
216
|
+
|
245
217
|
# Set the lifetime of the cookie. The value is a decimal non-negative
|
246
218
|
# integer. After +delta_seconds+ seconds elapse, the client should
|
247
219
|
# discard the cookie. A value of zero means the cookie should be
|
@@ -307,10 +279,10 @@ class Strelka::Cookie
|
|
307
279
|
rval << make_field( "Domain", self.domain )
|
308
280
|
rval << make_field( "Expires", make_cookiedate(self.expires) ) if self.expires
|
309
281
|
rval << make_field( "Max-Age", self.max_age )
|
310
|
-
rval << make_field( "Comment", self.comment )
|
311
282
|
rval << make_field( "Path", self.path )
|
312
283
|
|
313
|
-
rval <<
|
284
|
+
rval << '; ' << 'HttpOnly' if self.httponly?
|
285
|
+
rval << '; ' << 'Secure' if self.secure?
|
314
286
|
|
315
287
|
return rval
|
316
288
|
end
|
@@ -335,7 +307,7 @@ class Strelka::Cookie
|
|
335
307
|
|
336
308
|
### Make a uri-escaped value string for the cookie's current +values+.
|
337
309
|
def make_valuestring
|
338
|
-
return self.
|
310
|
+
return self.value
|
339
311
|
end
|
340
312
|
|
341
313
|
|
data/lib/strelka/exceptions.rb
CHANGED
@@ -28,5 +28,8 @@ module Strelka
|
|
28
28
|
# An exception raised when there is a problem with an application plugin.
|
29
29
|
class PluginError < Error; end
|
30
30
|
|
31
|
+
# An exception raised when there is a problem parsing or creating a cookie
|
32
|
+
class CookieError < Error; end
|
33
|
+
|
31
34
|
end # module Strelka
|
32
35
|
|
data/spec/strelka/cookie_spec.rb
CHANGED
@@ -42,89 +42,18 @@ describe Strelka::Cookie do
|
|
42
42
|
|
43
43
|
result.should be_a( Hash )
|
44
44
|
result.should have(1).member
|
45
|
-
result[
|
46
|
-
result[
|
47
|
-
result[
|
48
|
-
result['a'].values.should == ['b']
|
49
|
-
end
|
50
|
-
|
51
|
-
it "parses a cookie header field with a cookie with multiple values as a cookie with multiple values" do
|
52
|
-
result = Strelka::Cookie.parse( 'a=b&c' )
|
53
|
-
|
54
|
-
result.should be_a( Hash )
|
55
|
-
result.should have(1).member
|
56
|
-
result['a'].should be_a( Strelka::Cookie )
|
57
|
-
result['a'].name.should == 'a'
|
58
|
-
result['a'].value.should == 'b'
|
59
|
-
result['a'].values.should == ['b', 'c']
|
60
|
-
end
|
61
|
-
|
62
|
-
it "parses a cookie header field with multiple cookies and multiple values correctly" do
|
63
|
-
result = Strelka::Cookie.parse( 'a=b&c; f=o&o' )
|
64
|
-
|
65
|
-
result.should be_a( Hash )
|
66
|
-
result.should have(2).members
|
67
|
-
|
68
|
-
result['a'].should be_a( Strelka::Cookie )
|
69
|
-
result['a'].name.should == 'a'
|
70
|
-
result['a'].value.should == 'b'
|
71
|
-
result['a'].values.should == ['b', 'c']
|
72
|
-
|
73
|
-
result['f'].should be_a( Strelka::Cookie )
|
74
|
-
result['f'].name.should == 'f'
|
75
|
-
result['f'].value.should == 'o'
|
76
|
-
result['f'].values.should == ['o', 'o']
|
45
|
+
result[:a].should be_a( Strelka::Cookie )
|
46
|
+
result[:a].name.should == 'a'
|
47
|
+
result[:a].value.should == 'b'
|
77
48
|
end
|
78
49
|
|
79
50
|
it "parses a cookie header field with an empty value as a cookie with a nil value" do
|
80
51
|
result = Strelka::Cookie.parse( 'a=' )
|
81
52
|
|
82
53
|
result.should have( 1 ).member
|
83
|
-
result[
|
84
|
-
result[
|
85
|
-
result[
|
86
|
-
result['a'].values.should == []
|
87
|
-
end
|
88
|
-
|
89
|
-
it "parses a cookie header field with a version as a cookie with a version" do
|
90
|
-
result = Strelka::Cookie.parse( %{$Version=1; a="b"} )
|
91
|
-
|
92
|
-
result.should be_a( Hash )
|
93
|
-
result.should have( 1 ).member
|
94
|
-
|
95
|
-
result['a'].should be_a( Strelka::Cookie )
|
96
|
-
result['a'].name.should == 'a'
|
97
|
-
result['a'].value.should == 'b'
|
98
|
-
result['a'].values.should == ['b']
|
99
|
-
result['a'].version.should == 1
|
100
|
-
end
|
101
|
-
|
102
|
-
it "parses a cookie header field with a path as a cookie with a path" do
|
103
|
-
result = Strelka::Cookie.parse( %{a=b; $Path=/Strelka} )
|
104
|
-
|
105
|
-
result.should be_a( Hash )
|
106
|
-
result.should have( 1 ).member
|
107
|
-
|
108
|
-
result['a'].should be_a( Strelka::Cookie )
|
109
|
-
result['a'].name.should == 'a'
|
110
|
-
result['a'].value.should == 'b'
|
111
|
-
result['a'].values.should == ['b']
|
112
|
-
|
113
|
-
result['a'].path.should == "/Strelka"
|
114
|
-
end
|
115
|
-
|
116
|
-
it "parses a cookie header field with a domain as a cookie with a domain" do
|
117
|
-
result = Strelka::Cookie.parse( %{a=b; $domain=rubycrafters.com} )
|
118
|
-
|
119
|
-
result.should be_a( Hash )
|
120
|
-
result.should have( 1 ).member
|
121
|
-
|
122
|
-
result['a'].should be_a( Strelka::Cookie )
|
123
|
-
result['a'].name.should == 'a'
|
124
|
-
result['a'].value.should == 'b'
|
125
|
-
result['a'].values.should == ['b']
|
126
|
-
|
127
|
-
result['a'].domain.should == '.rubycrafters.com'
|
54
|
+
result[:a].should be_a( Strelka::Cookie )
|
55
|
+
result[:a].name.should == 'a'
|
56
|
+
result[:a].value.should be_nil()
|
128
57
|
end
|
129
58
|
|
130
59
|
it "doesn't raise an error if asked to parse an invalid cookie header" do
|
@@ -143,30 +72,31 @@ describe Strelka::Cookie do
|
|
143
72
|
@cookie.to_s.should == 'by_rickirac=9917eb'
|
144
73
|
end
|
145
74
|
|
146
|
-
it "still stringifies correctly with two values" do
|
147
|
-
@cookie.values += ['brer lapin']
|
148
|
-
@cookie.to_s.should == "by_rickirac=9917eb&brer+lapin"
|
149
|
-
end
|
150
|
-
|
151
75
|
it "stringifies with a version number if its version is set to something other than 0" do
|
152
76
|
@cookie.version = 1
|
153
|
-
@cookie.to_s.should
|
77
|
+
@cookie.to_s.should =~ /; Version=1/i
|
154
78
|
end
|
155
79
|
|
156
80
|
it "stringifies with a domain if one is set" do
|
157
81
|
@cookie.domain = '.example.com'
|
158
|
-
@cookie.to_s.should
|
82
|
+
@cookie.to_s.should =~ /; Domain=.example.com/
|
159
83
|
end
|
160
84
|
|
161
85
|
it "stringifies with a dot prepended to the domain if the set doesn't have one" do
|
162
86
|
@cookie.domain = 'example.com'
|
163
|
-
@cookie.to_s.should
|
87
|
+
@cookie.to_s.should =~ /; Domain=.example.com/i
|
164
88
|
end
|
165
89
|
|
166
|
-
it "
|
167
|
-
|
168
|
-
|
169
|
-
|
90
|
+
it "raises an exception if the cookie value would be invalid when serialized" do
|
91
|
+
expect {
|
92
|
+
@cookie.value = %{"modern technology"; ain't it a paradox?}
|
93
|
+
}.to raise_error( Strelka::CookieError, /invalid cookie value/i )
|
94
|
+
end
|
95
|
+
|
96
|
+
it "provides a convenience mechanism for setting the value to binary data" do
|
97
|
+
@cookie.binary_value = %{"modern technology"; ain't it a paradox?}
|
98
|
+
@cookie.to_s.should == 'by_rickirac=Im1vZGVybiB0ZWNobm9sb2d5IjsgYWluJ3Qg' +
|
99
|
+
'aXQgYSBwYXJhZG94Pw=='
|
170
100
|
end
|
171
101
|
|
172
102
|
it "stringifies with an expires date if one is set" do
|
@@ -174,6 +104,28 @@ describe Strelka::Cookie do
|
|
174
104
|
@cookie.to_s.should == 'by_rickirac=9917eb; Expires=Wed, 14 Mar 2012 21:39:44 GMT'
|
175
105
|
end
|
176
106
|
|
107
|
+
it "stringifies with a max age if the 'max age' is set" do
|
108
|
+
@cookie.max_age = 3600
|
109
|
+
@cookie.to_s.should == 'by_rickirac=9917eb; Max-age=3600'
|
110
|
+
end
|
111
|
+
|
112
|
+
it "stringifies with a Secure flag if secure is set" do
|
113
|
+
@cookie.secure = true
|
114
|
+
@cookie.to_s.should =~ /; Secure/i
|
115
|
+
end
|
116
|
+
|
117
|
+
it "stringifies with an HttpOnly flag if httponly is set" do
|
118
|
+
@cookie.httponly = true
|
119
|
+
@cookie.to_s.should =~ /; HttpOnly/i
|
120
|
+
end
|
121
|
+
|
122
|
+
it "stringifies with both Secure and HttpOnly flags if they're both set" do
|
123
|
+
@cookie.httponly = true
|
124
|
+
@cookie.secure = true
|
125
|
+
@cookie.to_s.should =~ /; HttpOnly/i
|
126
|
+
@cookie.to_s.should =~ /; Secure/i
|
127
|
+
end
|
128
|
+
|
177
129
|
it "hashes the same as another cookie with the same name, regardless of value" do
|
178
130
|
@cookie.hash.should == Strelka::Cookie.new('by_rickirac', 'something_else').hash
|
179
131
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strelka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.pre.
|
4
|
+
version: 0.0.1.pre.309
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
YUhDS0xaZFNLai9SSHVUT3QrZ2JsUmV4OEZBaDhOZUEKY21saFhlNDZwWk5K
|
37
37
|
Z1dLYnhaYWg4NWpJang5NWhSOHZPSStOQU01aUg5a09xSzEzRHJ4YWNUS1Bo
|
38
38
|
cWo1UGp3RgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
|
39
|
-
date: 2012-09-
|
39
|
+
date: 2012-09-26 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: configurability
|
metadata.gz.sig
CHANGED
Binary file
|