strelka 0.0.1.pre.257 → 0.0.1.pre.262

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.
data.tar.gz.sig CHANGED
Binary file
data/ChangeLog CHANGED
@@ -1,9 +1,34 @@
1
+ 2012-06-20 Michael Granger <ged@FaerieMUD.org>
2
+
3
+ * lib/strelka/httprequest/session.rb,
4
+ lib/strelka/httpresponse/session.rb, lib/strelka/session.rb,
5
+ lib/strelka/session/default.rb,
6
+ spec/strelka/httprequest/session_spec.rb,
7
+ spec/strelka/httpresponse/session_spec.rb,
8
+ spec/strelka/session/default_spec.rb:
9
+ Fix session expiration for cookie-based persistance
10
+ * * * Conversion to stream-based Mongrel2 API
11
+ [7389c2f1e8e3] [tip]
12
+
13
+ 2012-06-20 Mahlon E. Smith <mahlon@martini.nu>
14
+
15
+ * lib/strelka/httprequest.rb:
16
+ Ignore possible Content-Type charsets when parsing form data.
17
+ [432d88e45c15]
18
+
19
+ 2012-06-19 Mahlon E. Smith <mahlon@laika.com>
20
+
21
+ * lib/strelka/paramvalidator.rb, spec/strelka/paramvalidator_spec.rb:
22
+ Don't use the raw_form to determine if the ParamValidator required
23
+ revalidation, just keep track of that ourselves.
24
+ [4d71cc097677]
25
+
1
26
  2012-06-04 Mahlon E. Smith <mahlon@martini.nu>
2
27
 
3
28
  * lib/strelka/app/auth.rb, lib/strelka/authprovider/hostaccess.rb,
4
29
  spec/strelka/authprovider/hostaccess_spec.rb:
5
30
  Fix required arguments for the hostaccess auth provider.
6
- [4a20533a0551] [tip]
31
+ [4a20533a0551]
7
32
 
8
33
  2012-06-01 Michael Granger <ged@FaerieMUD.org>
9
34
 
@@ -126,7 +151,7 @@
126
151
  * bin/strelka:
127
152
  Load the apps in bin/strelka before dumping the config so
128
153
  Configurability defaults for them show up
129
- [726ed30cb34e] [github/master]
154
+ [726ed30cb34e]
130
155
 
131
156
  * .rvm.gems, Rakefile:
132
157
  Add dependency on Foreman
@@ -738,7 +763,7 @@
738
763
 
739
764
  * lib/strelka/app/errors.rb, spec/strelka/app/errors_spec.rb:
740
765
  Add documentation for the Errors plugin, improve test coverage.
741
- [ff3ef6e5a7a1] [github/master@default]
766
+ [ff3ef6e5a7a1]
742
767
 
743
768
  * Manifest.txt:
744
769
  Add session files to the manifest
@@ -24,6 +24,7 @@ require 'strelka/httpresponse/negotiation'
24
24
  # add_content_type :tnetstring, 'text/x-tnetstring' do |response|
25
25
  # tnetstr = nil
26
26
  # begin
27
+ # response.body.rewind
27
28
  # tnetstr = TNetString.dump( response.body )
28
29
  # rescue => err
29
30
  # self.log.error "%p while transforming entity body to a TNetString: %s" %
@@ -177,11 +177,15 @@ class Strelka::HTTPRequest < Mongrel2::HTTPRequest
177
177
 
178
178
  ### Return a Hash of request form data.
179
179
  def parse_form_data
180
- case self.headers.content_type
181
- when nil
180
+ unless self.headers.content_type
182
181
  finish_with( HTTP::BAD_REQUEST, "Malformed request (no content type?)" )
182
+ end
183
+
184
+ self.body.rewind
185
+
186
+ case self.headers.content_type.split( ';' ).first
183
187
  when 'application/x-www-form-urlencoded'
184
- return merge_query_args( URI.decode_www_form(self.body) )
188
+ return merge_query_args( URI.decode_www_form(self.body.read) )
185
189
  when 'application/json', 'text/javascript'
186
190
  return Yajl.load( self.body )
187
191
  when 'text/x-yaml', 'application/x-yaml'
@@ -67,17 +67,9 @@ module Strelka::HTTPRequest::Session
67
67
  end
68
68
 
69
69
 
70
- ### Purge the request's session from the session store.
71
- def destroy_session
72
- self.log.debug "Removing session id %s" % [ self.session.session_id ]
73
- Strelka::App::Sessions.session_class.delete_session_data( self.session.session_id )
74
- @session = nil
75
- end
76
-
77
-
78
70
  ### Set the request's session object.
79
71
  def session=( new_session )
80
- new_session.namespace = self.session_namespace
72
+ new_session.namespace = self.session_namespace if new_session.respond_to?( :namespace )
81
73
  @session = new_session
82
74
  end
83
75
 
@@ -122,12 +122,14 @@ class Strelka::HTTPResponse < Mongrel2::HTTPResponse
122
122
 
123
123
  ### Try to find a character set for the request, using the #charset attribute first,
124
124
  ### then the 'charset' parameter from the content-type header, then the Encoding object
125
- ### associated with the entity body, then the default external encoding (if it's set). If
126
- ### none of those are found, this method returns ISO-8859-1.
125
+ ### associated with the entity body, then the default internal and external encodings
126
+ ### (if they're set, in that order). If none of those are found, this method returns
127
+ ### ISO-8859-1.
127
128
  def find_header_charset
128
129
  return ( self.charset ||
129
130
  self.content_type_charset ||
130
- self.entity_body_charset ||
131
+ self.entity_body_charset ||
132
+ Encoding.default_internal ||
131
133
  Encoding.default_external ||
132
134
  Encoding::ISO_8859_1 )
133
135
  end
@@ -150,20 +152,13 @@ class Strelka::HTTPResponse < Mongrel2::HTTPResponse
150
152
  ### couldn't be determined.
151
153
  def entity_body_charset
152
154
  self.log.debug "Deriving charset from the entity body..."
155
+ enc = nil
153
156
 
154
- # Have to use the instance variable instead of #body because plugins can
155
- # override #body
157
+ enc ||= @body.internal_encoding if @body.respond_to?( :internal_encoding )
158
+ enc ||= @body.external_encoding if @body.respond_to?( :external_encoding )
156
159
 
157
- if @body.respond_to?( :encoding )
158
- self.log.debug " String-ish API. Encoding is: %p" % [ @body.encoding ]
159
- return @body.encoding
160
- elsif @body.respond_to?( :external_encoding )
161
- self.log.debug " IO-ish API. Encoding is: %p" % [ @body.external_encoding ]
162
- return @body.external_encoding
163
- end
164
-
165
- self.log.debug " Body didn't respond to either #encoding or #external_encoding."
166
- return nil
160
+ self.log.debug " Body didn't respond to either #internal_encoding or #external_encoding." unless enc
161
+ return enc
167
162
  end
168
163
 
169
164
 
@@ -51,6 +51,15 @@ module Strelka::HTTPResponse::Negotiation
51
51
  'application/json' => Yajl.method( :dump ),
52
52
  }
53
53
 
54
+ # Transcoding to Unicode is likely enough to work to warrant auto-transcoding. These
55
+ # are the charsets that will be used for auto-transcoding in the case where the whole
56
+ # entity body isn't in memory
57
+ UNICODE_CHARSETS = [
58
+ Encoding::UTF_8,
59
+ Encoding::UTF_16BE,
60
+ Encoding::UTF_32BE,
61
+ ]
62
+
54
63
 
55
64
  ### Add some instance variables for negotiation.
56
65
  def initialize( * )
@@ -127,7 +136,7 @@ module Strelka::HTTPResponse::Negotiation
127
136
  def negotiated_body
128
137
  return '' if self.bodiless?
129
138
 
130
- self.negotiate
139
+ self.negotiate
131
140
  return self.body
132
141
  end
133
142
 
@@ -460,45 +469,65 @@ module Strelka::HTTPResponse::Negotiation
460
469
  ### if it
461
470
  def transform_charset
462
471
  self.log.debug "Looking for charset transformations."
463
- self.better_charsets.each do |charset|
464
- self.log.debug " trying to transcode to: %s" % [ charset ]
472
+ if self.body.respond_to?( :string ) || self.body.respond_to?( :fileno )
473
+
474
+ # Try each charset that's better than what we have already
475
+ self.better_charsets.each do |charset|
476
+ self.log.debug " trying to transcode to: %s" % [ charset ]
465
477
 
466
- if self.body.respond_to?( :encode )
467
- self.log.debug " body is a string; trying direct transcoding"
468
- if self.transcode_body_string( charset )
469
- self.log.debug " success; body is now %p" % [ self.body.encoding ]
478
+ # If it succeeds, indicate that transcoding took place in the Vary header
479
+ if self.transcode_body( charset )
480
+ self.log.debug " success; body is now %p" % [ charset ]
470
481
  self.vary_fields.add( 'accept-charset' )
471
482
  break
472
483
  end
473
-
474
- # Can change the external_encoding if it's a File that has a #path
475
- elsif self.body.respond_to?( :external_encoding )
476
- raise NotImplementedError,
477
- "Support for transcoding %p objects isn't done." % [ self.body.class ]
478
- else
479
- self.log.warn "Don't know how to transcode a %p" % [ self.body.class ]
480
484
  end
485
+ else
486
+ self.log.warn "Don't know how to transcode a %p" % [ self.body.class ]
481
487
  end
482
488
  end
483
489
 
484
490
 
485
- ### Try to transcode the entity body String to one of the specified +charsets+. Returns
491
+ ### Try to transcode the entity body stream to one of the specified +charsets+. Returns
486
492
  ### the succesful Encoding object if transcoding succeeded, or +nil+ if transcoding
487
493
  ### failed.
488
- def transcode_body_string( charset )
494
+ def transcode_body( charset )
489
495
  unless enc = charset.encoding_object
490
496
  self.log.warn " unsupported charset: %s" % [ charset ]
491
497
  return false
492
498
  end
493
499
 
494
- succeeded = false
495
500
  begin
496
- succeeded = self.body.encode!( enc )
501
+
502
+ # StringIOs get their internal string transcoded directly
503
+ if self.body.respond_to?( :string )
504
+ self.body.string.encode!( enc )
505
+ return true
506
+
507
+ # For other IO objects, the situation is trickier -- we can't know that
508
+ # encoding will succeed for more-restrictive charsets, so we only do
509
+ # automatic transcoding if the 'wanted' one is a Unicode charset.
510
+ # This probably isn't perfect, either.
511
+ # :FIXME: Probably need a list of exceptions, i.e., charsets that don't
512
+ # always transcode nicely into Unicode.
513
+ elsif self.body.respond_to?( :fileno ) && UNICODE_CHARSETS.include?( enc )
514
+ self.log.info "Assuming %s data can be transcoded into %s" %
515
+ [ self.body.internal_encoding, enc ]
516
+
517
+ # Don't close the FD when this IO goes out of scope
518
+ oldbody = self.body
519
+ oldbody.auto_close = false
520
+
521
+ # Re-open the same file descriptor, but transcoding to the wanted encoding
522
+ self.body = IO.for_fd( oldbody.fileno, internal_encoding: enc )
523
+ return true
524
+ end
525
+
497
526
  rescue Encoding::UndefinedConversionError => err
498
527
  self.log.error "%p while transcoding: %s" % [ err.class, err.message ]
499
528
  end
500
529
 
501
- return succeeded
530
+ return false
502
531
  end
503
532
 
504
533
 
@@ -91,6 +91,18 @@ module Strelka::HTTPResponse::Session
91
91
  end
92
92
 
93
93
 
94
+ ### Purge the response's session from the session store and expire its ID.
95
+ def destroy_session
96
+ if self.session?
97
+ self.log.debug "Destroying session: %p" % [ self.session ]
98
+ self.session.destroy( self )
99
+ self.request.session = @session = nil
100
+ else
101
+ self.log.debug "No session to destroy."
102
+ end
103
+ end
104
+
105
+
94
106
  ### Tell the associated session to save itself and set up the session ID in the
95
107
  ### response, if one exists.
96
108
  def save_session
@@ -164,6 +164,7 @@ class Strelka::ParamValidator < ::FormValidator
164
164
  @filters_array = []
165
165
  @untaint_fields = []
166
166
  @untaint_all = false
167
+ @validated = false
167
168
 
168
169
  @parsed_params = nil
169
170
  end
@@ -188,6 +189,7 @@ class Strelka::ParamValidator < ::FormValidator
188
189
  @filters_array = @filters_array.clone
189
190
  @untaint_fields = @untaint_fields.clone
190
191
  @untaint_all = original.untaint_all?
192
+ @validated = original.validated?
191
193
 
192
194
  @parsed_params = @parsed_params.clone if @parsed_params
193
195
  end
@@ -358,6 +360,7 @@ class Strelka::ParamValidator < ::FormValidator
358
360
 
359
361
  self.log.debug "Calling superclass's validate: %p" % [ self ]
360
362
  super( params, profile )
363
+ @validated = true
361
364
  end
362
365
 
363
366
 
@@ -443,7 +446,7 @@ class Strelka::ParamValidator < ::FormValidator
443
446
 
444
447
  ### Returns +true+ if the parameters have been validated.
445
448
  def validated?
446
- return !@raw_form.empty?
449
+ return @validated
447
450
  end
448
451
 
449
452
 
@@ -169,6 +169,13 @@ class Strelka::Session
169
169
  pure_virtual :save
170
170
 
171
171
 
172
+ # :call-seq:
173
+ # destroy( response )
174
+ # Destroy the session and set up the specified +response+ to expire the
175
+ # session ID.
176
+ pure_virtual :destroy
177
+
178
+
172
179
  # :call-seq:
173
180
  # key?( key ) -> boolean
174
181
  #
@@ -177,7 +177,7 @@ class Strelka::Session::Default < Strelka::Session
177
177
  def save( response )
178
178
  self.log.debug "Saving session %s" % [ self.session_id ]
179
179
  self.class.save_session_data( self.session_id, @hash )
180
- self.log.debug "Adding session cookie to the request."
180
+ self.log.debug "Adding session cookie to the response."
181
181
 
182
182
  session_cookie = Strelka::Cookie.new(
183
183
  self.class.cookie_name,
@@ -189,6 +189,23 @@ class Strelka::Session::Default < Strelka::Session
189
189
  end
190
190
 
191
191
 
192
+ ### Delete the session from storage and expire the session cookie from the given +response+.
193
+ def destroy( response )
194
+ self.log.debug "Destroying session %s" % [ self.session_id ]
195
+ self.class.delete_session_data( self.session_id )
196
+
197
+ self.log.debug "Adding expired session cookie to the response"
198
+ session_cookie = Strelka::Cookie.new(
199
+ self.class.cookie_name,
200
+ self.session_id,
201
+ self.class.cookie_options || {}
202
+ )
203
+ session_cookie.expire!
204
+
205
+ response.cookies << session_cookie
206
+ end
207
+
208
+
192
209
  ### Return the Hash that corresponds with the current namespace's storage. If no
193
210
  ### namespace is currently set, returns the entire session store as a Hash of Hashes
194
211
  ### keyed by namespaces as Symbols.
@@ -73,7 +73,8 @@ describe Strelka::App::Errors do
73
73
  res = @app.new.handle( req )
74
74
 
75
75
  res.status.should == HTTP::OK
76
- res.body.should == "Oh yeah! Kool-Aid!\n"
76
+ res.body.rewind
77
+ res.body.read.should == "Oh yeah! Kool-Aid!\n"
77
78
  end
78
79
 
79
80
  it "raises an error if a handler is declared with both a template and a block" do
@@ -105,7 +106,8 @@ describe Strelka::App::Errors do
105
106
  req = @request_factory.get( '/foom' )
106
107
  res = @app.new.handle( req )
107
108
 
108
- res.body.should =~ /internal server error/i
109
+ res.body.rewind
110
+ res.body.read.should =~ /internal server error/i
109
111
  end
110
112
 
111
113
  it "calls a callback-style handler for any status when finished with BAD_REQUEST" do
@@ -124,7 +126,8 @@ describe Strelka::App::Errors do
124
126
  res = @app.new.handle( req )
125
127
 
126
128
  res.status.should == HTTP::BAD_REQUEST
127
- res.body.should == '(400) Filthy banana'
129
+ res.body.rewind
130
+ res.body.read.should == '(400) Filthy banana'
128
131
  end
129
132
 
130
133
 
@@ -139,7 +142,8 @@ describe Strelka::App::Errors do
139
142
  req = @request_factory.get( '/foom' )
140
143
  res = @app.new.handle( req )
141
144
 
142
- res.body.should == 'NOPE!'
145
+ res.body.rewind
146
+ res.body.read.should == 'NOPE!'
143
147
  end
144
148
 
145
149
 
@@ -154,7 +158,8 @@ describe Strelka::App::Errors do
154
158
  req = @request_factory.get( '/foom' )
155
159
  res = @app.new.handle( req )
156
160
 
157
- res.body.should == 'Error: JAMBA'
161
+ res.body.rewind
162
+ res.body.read.should == 'Error: JAMBA'
158
163
  end
159
164
 
160
165
  it "sets the error status info in the transaction notes when the response is handled by a status-handler" do
@@ -196,7 +201,8 @@ describe Strelka::App::Errors do
196
201
  res.notes[:status_info][:status].should == HTTP::SERVER_ERROR
197
202
  res.notes[:status_info][:message].should == "An uncaught exception"
198
203
  res.notes[:status_info][:exception].should be_a( RuntimeError )
199
- res.body.should == "RuntimeError"
204
+ res.body.rewind
205
+ res.body.read.should == "RuntimeError"
200
206
  end
201
207
 
202
208
 
@@ -228,7 +234,8 @@ describe Strelka::App::Errors do
228
234
  req = @request_factory.get( '/foom' )
229
235
  res = @app.new.handle( req )
230
236
 
231
- res.body.should =~ /error-handler template/i
237
+ res.body.rewind
238
+ res.body.read.should =~ /error-handler template/i
232
239
  end
233
240
  end
234
241
 
@@ -225,7 +225,8 @@ describe Strelka::App::RestResources do
225
225
  res = @app.new.handle( req )
226
226
 
227
227
  res.status.should == HTTP::NOT_FOUND
228
- res.body.should =~ /no such server/i
228
+ res.body.rewind
229
+ res.body.read.should =~ /no such server/i
229
230
  end
230
231
 
231
232
  it "returns a NOT FOUND response when fetching a resource with an invalid ID" do
@@ -233,7 +234,8 @@ describe Strelka::App::RestResources do
233
234
  res = @app.new.handle( req )
234
235
 
235
236
  res.status.should == HTTP::NOT_FOUND
236
- res.body.should =~ /requested resource was not found/i
237
+ res.body.rewind
238
+ res.body.read.should =~ /requested resource was not found/i
237
239
  end
238
240
 
239
241
  it "has a GET route for fetching the resource via one of its dataset methods" do
@@ -116,7 +116,8 @@ describe Strelka::App::Templating do
116
116
 
117
117
  res = @app.new.handle( @req )
118
118
 
119
- res.body.should == "A template for testing the Templating plugin.\n"
119
+ res.body.rewind
120
+ res.body.read.should == "A template for testing the Templating plugin.\n"
120
121
  res.status.should == 200
121
122
  end
122
123
 
@@ -129,7 +130,8 @@ describe Strelka::App::Templating do
129
130
 
130
131
  res = @app.new.handle( @req )
131
132
 
132
- res.body.should == "A template for testing the Templating plugin.\n"
133
+ res.body.rewind
134
+ res.body.read.should == "A template for testing the Templating plugin.\n"
133
135
  res.status.should == 200
134
136
  end
135
137
 
@@ -146,7 +148,8 @@ describe Strelka::App::Templating do
146
148
 
147
149
  res = @app.new.handle( @req )
148
150
 
149
- res.body.should == "A template for testing the Templating plugin.\n"
151
+ res.body.rewind
152
+ res.body.read.should == "A template for testing the Templating plugin.\n"
150
153
  res.status.should == 200
151
154
  end
152
155
 
@@ -167,7 +170,8 @@ describe Strelka::App::Templating do
167
170
 
168
171
  res = @app.new.handle( @req )
169
172
 
170
- res.body.should == "A minimal layout template.\n" +
173
+ res.body.rewind
174
+ res.body.read.should == "A minimal layout template.\n" +
171
175
  "A template for testing the Templating plugin.\n\n"
172
176
  res.status.should == 200
173
177
  end
@@ -188,7 +192,8 @@ describe Strelka::App::Templating do
188
192
 
189
193
  res = @app.new.handle( @req )
190
194
 
191
- res.body.should == "A template for testing the Templating plugin.\n"
195
+ res.body.rewind
196
+ res.body.read.should == "A template for testing the Templating plugin.\n"
192
197
  end
193
198
 
194
199
  end
@@ -169,7 +169,8 @@ describe Strelka::App do
169
169
 
170
170
  res.should be_a( Mongrel2::HTTPResponse )
171
171
  res.status_line.should == 'HTTP/1.1 204 No Content'
172
- res.body.should == ''
172
+ res.body.rewind
173
+ res.body.read.should == ''
173
174
  end
174
175
 
175
176
 
@@ -190,7 +191,8 @@ describe Strelka::App do
190
191
 
191
192
  res.should be_a( Mongrel2::HTTPResponse )
192
193
  res.status_line.should == 'HTTP/1.1 304 Not Modified'
193
- res.body.should == ''
194
+ res.body.rewind
195
+ res.body.read.should == ''
194
196
  end
195
197
 
196
198
 
@@ -211,7 +213,8 @@ describe Strelka::App do
211
213
  res.should be_a( Mongrel2::HTTPResponse )
212
214
  res.status_line.should == 'HTTP/1.1 403 Forbidden'
213
215
  res.content_type.should == 'text/plain'
214
- res.body.should == "You aren't allowed to look at that.\n"
216
+ res.body.rewind
217
+ res.body.read.should == "You aren't allowed to look at that.\n"
215
218
  end
216
219
 
217
220
 
@@ -233,7 +236,8 @@ describe Strelka::App do
233
236
  res.should be_a( Mongrel2::HTTPResponse )
234
237
  res.status_line.should == 'HTTP/1.1 403 Forbidden'
235
238
  res.content_type.should == 'text/html'
236
- res.body.should == "You aren't allowed to look at that.\n"
239
+ res.body.rewind
240
+ res.body.read.should == "You aren't allowed to look at that.\n"
237
241
  end
238
242
 
239
243
  it "sets the error status info in the transaction notes for error responses" do
@@ -302,7 +306,8 @@ describe Strelka::App do
302
306
 
303
307
  res.should be_a( Mongrel2::HTTPResponse )
304
308
  res.content_type.should == 'text/plain'
305
- res.body.should be_empty()
309
+ res.body.rewind
310
+ res.body.read.should == ''
306
311
  res.headers.content_length.should == "Rendered output.\n".bytesize
307
312
  end
308
313
 
@@ -347,7 +352,8 @@ describe Strelka::App do
347
352
  res.should be_a( Mongrel2::HTTPResponse )
348
353
  res.status.should == HTTP::SERVER_ERROR
349
354
  res.content_type = 'text/plain'
350
- res.body.should =~ /internal server error/i
355
+ res.body.rewind
356
+ res.body.read.should =~ /internal server error/i
351
357
  end
352
358
 
353
359
  it "isn't in 'developer mode' by default" do
@@ -415,7 +421,8 @@ describe Strelka::App do
415
421
 
416
422
  res.should be_a( Mongrel2::HTTPResponse )
417
423
  res.status_line.should == 'HTTP/1.1 200 OK'
418
- res.body.should == "Request was funted by Cragnux/1.1.3!\n"
424
+ res.body.rewind
425
+ res.body.read.should == "Request was funted by Cragnux/1.1.3!\n"
419
426
  end
420
427
 
421
428
 
@@ -96,9 +96,7 @@ describe Strelka::HTTPRequest::Session, "-extended request" do
96
96
  context "with a session ID" do
97
97
 
98
98
  before( :each ) do
99
- cookie_name = Strelka::Session::Default.cookie_name
100
99
  @sess_id = Strelka::Session::Default.get_session_id
101
- @req.header.cookie = "#{cookie_name}=#{@sess_id}"
102
100
  end
103
101
 
104
102
  it "knows that it doesn't have a session unless the ID exists" do
@@ -113,6 +111,8 @@ describe Strelka::HTTPRequest::Session, "-extended request" do
113
111
  end
114
112
 
115
113
  it "knows that it has a session" do
114
+ cookie_name = Strelka::Session::Default.cookie_name
115
+ @req.header.cookie = "#{cookie_name}=#{@sess_id}"
116
116
  @req.should have_session()
117
117
  end
118
118
 
@@ -125,11 +125,6 @@ describe Strelka::HTTPRequest::Session, "-extended request" do
125
125
  @req.session_loaded?.should be_true()
126
126
  end
127
127
 
128
- it "can purge the session from the database" do
129
- @req.should have_session()
130
- @req.destroy_session
131
- @req.should_not have_session()
132
- end
133
128
  end
134
129
 
135
130
  end
@@ -52,7 +52,8 @@ describe Strelka::HTTPResponse::Negotiation do
52
52
  @res.for( 'application/json' ) { %{["a JSON dump"]} }
53
53
  @res.for( 'application/x-yaml' ) { "---\na: YAML dump\n\n" }
54
54
 
55
- @res.negotiated_body.should == "---\na: YAML dump\n\n"
55
+ @res.negotiated_body.rewind
56
+ @res.negotiated_body.read.should == "---\na: YAML dump\n\n"
56
57
  @res.content_type.should == "application/x-yaml"
57
58
  @res.header_data.should =~ /accept(?!-)/i
58
59
  end
@@ -64,7 +65,8 @@ describe Strelka::HTTPResponse::Negotiation do
64
65
  { uuid: 'fc85e35b-c9c3-4675-a882-25bf98d11e1b', name: "Harlot's Garden" }
65
66
  end
66
67
 
67
- @res.negotiated_body.should == "{\"uuid\":\"fc85e35b-c9c3-4675-a882-25bf98d11e1b\"," +
68
+ @res.negotiated_body.rewind
69
+ @res.negotiated_body.read.should == "{\"uuid\":\"fc85e35b-c9c3-4675-a882-25bf98d11e1b\"," +
68
70
  "\"name\":\"Harlot's Garden\"}"
69
71
  @res.content_type.should == "application/json"
70
72
  @res.header_data.should =~ /accept(?!-)/i
@@ -77,7 +79,8 @@ describe Strelka::HTTPResponse::Negotiation do
77
79
  { uuid: 'fc85e35b-c9c3-4675-a882-25bf98d11e1b', name: "Harlot's Garden" }
78
80
  end
79
81
 
80
- @res.negotiated_body.should == "{\"uuid\":\"fc85e35b-c9c3-4675-a882-25bf98d11e1b\"," +
82
+ @res.negotiated_body.rewind
83
+ @res.negotiated_body.read.should == "{\"uuid\":\"fc85e35b-c9c3-4675-a882-25bf98d11e1b\"," +
81
84
  "\"name\":\"Harlot's Garden\"}"
82
85
  @res.content_type.should == "application/json"
83
86
  @res.header_data.should =~ /accept(?!-)/i
@@ -94,7 +97,7 @@ describe Strelka::HTTPResponse::Negotiation do
94
97
  @res.body = File.read( __FILE__, encoding: 'iso-8859-5' )
95
98
  @res.content_type = 'text/plain'
96
99
 
97
- @res.negotiated_body.encoding.should == Encoding::KOI8_R
100
+ @res.negotiated_body.external_encoding.should == Encoding::KOI8_R
98
101
  @res.header_data.should =~ /accept-charset(?!-)/i
99
102
  end
100
103
 
@@ -104,7 +107,7 @@ describe Strelka::HTTPResponse::Negotiation do
104
107
  @res.body = File.read( __FILE__, encoding: 'iso-8859-5' )
105
108
  @res.content_type = 'application/json'
106
109
 
107
- @res.negotiated_body.encoding.should == Encoding::UTF_8
110
+ @res.negotiated_body.external_encoding.should == Encoding::UTF_8
108
111
  @res.header_data.should =~ /accept-charset(?!-)/i
109
112
  end
110
113
 
@@ -135,7 +138,8 @@ describe Strelka::HTTPResponse::Negotiation do
135
138
  @res.for_language( :de ) { "German translation" }
136
139
  @res.for_language( :sl ) { "Slovenian translation" }
137
140
 
138
- @res.negotiated_body.should == "German translation"
141
+ @res.negotiated_body.rewind
142
+ @res.negotiated_body.read.should == "German translation"
139
143
  @res.languages.should == ["de"]
140
144
  @res.header_data.should =~ /accept-language/i
141
145
  end
@@ -150,7 +154,8 @@ describe Strelka::HTTPResponse::Negotiation do
150
154
  @res.for_language( :de ) { "German translation" }
151
155
  @res.for_language( :sl ) { "Slovenian translation" }
152
156
 
153
- @res.negotiated_body.should == "German translation"
157
+ @res.negotiated_body.rewind
158
+ @res.negotiated_body.read.should == "German translation"
154
159
  @res.languages.should == ["de"]
155
160
  @res.header_data.should =~ /accept-language/i
156
161
  end
@@ -169,7 +174,8 @@ describe Strelka::HTTPResponse::Negotiation do
169
174
  translations[ lang.to_sym ]
170
175
  end
171
176
 
172
- @res.negotiated_body.should == "Portuguese translation"
177
+ @res.negotiated_body.rewind
178
+ @res.negotiated_body.read.should == "Portuguese translation"
173
179
  @res.languages.should == ["pt"]
174
180
  @res.header_data.should =~ /accept-language/i
175
181
  end
@@ -183,7 +189,8 @@ describe Strelka::HTTPResponse::Negotiation do
183
189
  @res.for_language( :de ) { "German translation" }
184
190
  @res.for_language( :sl ) { "Slovenian translation" }
185
191
 
186
- @res.negotiated_body.should == "English translation"
192
+ @res.negotiated_body.rewind
193
+ @res.negotiated_body.read.should == "English translation"
187
194
  @res.languages.should == ["en"]
188
195
  @res.header_data.should =~ /accept-language/i
189
196
  end
@@ -198,10 +205,11 @@ describe Strelka::HTTPResponse::Negotiation do
198
205
 
199
206
  @res << "the text body"
200
207
  @res.content_type = 'text/plain'
201
- @res.for_encoding( :deflate ) { @res.body + " (deflated)" }
202
- @res.for_encoding( :gzip ) { @res.body + " (gzipped)" }
208
+ @res.for_encoding( :deflate ) { @res.body << " (deflated)" }
209
+ @res.for_encoding( :gzip ) { @res.body << " (gzipped)" }
203
210
 
204
- @res.negotiated_body.should == "the text body (gzipped)"
211
+ @res.negotiated_body.rewind
212
+ @res.negotiated_body.read.should == "the text body (gzipped)"
205
213
  @res.encodings.should include( "gzip" )
206
214
  @res.header_data.should =~ /accept-encoding/i
207
215
  @res.header_data.should_not =~ /identity/i
@@ -213,10 +221,11 @@ describe Strelka::HTTPResponse::Negotiation do
213
221
 
214
222
  @res << "the text body"
215
223
  @res.content_type = 'text/plain'
216
- @res.for_encoding( :deflate ) { @res.body + " (deflated)" }
217
- @res.for_encoding( :gzip ) { @res.body + " (gzipped)" }
224
+ @res.for_encoding( :deflate ) { @res.body << " (deflated)" }
225
+ @res.for_encoding( :gzip ) { @res.body << " (gzipped)" }
218
226
 
219
- @res.negotiated_body.should == "the text body (deflated)"
227
+ @res.negotiated_body.rewind
228
+ @res.negotiated_body.read.should == "the text body (deflated)"
220
229
  @res.encodings.should include( "deflate" )
221
230
  @res.header_data.should =~ /accept-encoding/i
222
231
  @res.header_data.should_not =~ /identity/i
@@ -157,6 +157,21 @@ describe Strelka::HTTPResponse::Session, "-extended response" do
157
157
  @res.cookies.should be_empty()
158
158
  end
159
159
 
160
+ it "destroys the session via itself if it was loaded" do
161
+ @res.cookies.should_not include( @cookie_name )
162
+ @res.session
163
+ @res.destroy_session
164
+ @res.cookies[ @cookie_name ].value.should == @sess_id
165
+ @res.cookies[ @cookie_name ].expires.should < Time.now
166
+ end
167
+
168
+ it "destroys the session via itself even if it wasn't loaded" do
169
+ @res.cookies.should_not include( @cookie_name )
170
+ @res.destroy_session
171
+ @res.cookies[ @cookie_name ].value.should == @sess_id
172
+ @res.cookies[ @cookie_name ].expires.should < Time.now
173
+ end
174
+
160
175
  end
161
176
 
162
177
  end
@@ -177,6 +177,19 @@ describe Strelka::ParamValidator do
177
177
  @validator.error_messages.should include( "Invalid value for 'A Field'" )
178
178
  end
179
179
 
180
+ it "re-validates if profile is modified, even with no parameters" do
181
+ @validator.add( :a_field, :string )
182
+ @validator.validate
183
+ @validator.should_not have_errors()
184
+ @validator.should be_okay()
185
+
186
+ @validator.override( :a_field, :string, :required )
187
+ @validator.should have_errors()
188
+ @validator.should_not be_okay()
189
+ @validator.error_messages.should include( "Missing value for 'A Field'" )
190
+ end
191
+
192
+
180
193
  end # describe "validation"
181
194
 
182
195
  describe "validation error descriptions" do
@@ -100,6 +100,19 @@ describe Strelka::Session::Default do
100
100
  response.header_data.should =~ /Set-Cookie: #{@cookie_name}=#{session_id}/i
101
101
  end
102
102
 
103
+ it "can remove itself from the store and expire the response's session ID" do
104
+ req = @request_factory.get( '/hungry/hungry/hippos' )
105
+ response = req.response
106
+ session_id = '3422067061a5790be374c81118d9ed3f'
107
+ session_data = { :namespace => {'fruit' => 'bowl'} }
108
+ session = described_class.new( session_id, session_data )
109
+
110
+ session.destroy( response )
111
+
112
+ described_class.sessions.should_not include({ session_id => session_data })
113
+ response.header_data.should =~ /Set-Cookie: #{@cookie_name}=#{session_id}/i
114
+ end
115
+
103
116
  describe "with no namespace set (the 'nil' namespace)" do
104
117
 
105
118
  subject { Strelka::Session.create('default', 'the_session_id') }
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.257
4
+ version: 0.0.1.pre.262
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-06-07 00:00:00.000000000 Z
39
+ date: 2012-06-22 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: trollop
metadata.gz.sig CHANGED
Binary file