strelka 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +1 -3
  4. data/History.rdoc +19 -0
  5. data/Rakefile +6 -5
  6. data/lib/strelka.rb +2 -2
  7. data/lib/strelka/app.rb +8 -21
  8. data/lib/strelka/app/auth.rb +1 -1
  9. data/lib/strelka/app/restresources.rb +72 -20
  10. data/lib/strelka/app/sessions.rb +6 -4
  11. data/lib/strelka/authprovider.rb +1 -1
  12. data/lib/strelka/cookie.rb +2 -1
  13. data/lib/strelka/httprequest.rb +47 -43
  14. data/lib/strelka/httprequest/acceptparams.rb +3 -3
  15. data/lib/strelka/httprequest/negotiation.rb +4 -0
  16. data/lib/strelka/mixins.rb +27 -28
  17. data/lib/strelka/multipartparser.rb +1 -3
  18. data/lib/strelka/plugins.rb +1 -2
  19. data/lib/strelka/router.rb +2 -2
  20. data/lib/strelka/session.rb +3 -2
  21. data/lib/strelka/session/db.rb +1 -0
  22. data/spec/strelka/app/auth_spec.rb +48 -48
  23. data/spec/strelka/app/filters_spec.rb +8 -8
  24. data/spec/strelka/app/parameters_spec.rb +1 -1
  25. data/spec/strelka/app/restresources_spec.rb +69 -35
  26. data/spec/strelka/app/routing_spec.rb +1 -1
  27. data/spec/strelka/app/templating_spec.rb +1 -1
  28. data/spec/strelka/authprovider/basic_spec.rb +1 -1
  29. data/spec/strelka/authprovider/hostaccess_spec.rb +3 -3
  30. data/spec/strelka/cookie_spec.rb +6 -5
  31. data/spec/strelka/cookieset_spec.rb +1 -1
  32. data/spec/strelka/discovery_spec.rb +2 -2
  33. data/spec/strelka/httprequest/acceptparams_spec.rb +16 -16
  34. data/spec/strelka/httprequest/negotiation_spec.rb +73 -67
  35. data/spec/strelka/httprequest/session_spec.rb +2 -2
  36. data/spec/strelka/httprequest_spec.rb +38 -6
  37. data/spec/strelka/httpresponse/session_spec.rb +3 -3
  38. data/spec/strelka/mixins_spec.rb +3 -3
  39. data/spec/strelka/multipartparser_spec.rb +2 -2
  40. data/spec/strelka/paramvalidator_spec.rb +22 -22
  41. data/spec/strelka/plugins_spec.rb +1 -1
  42. data/spec/strelka/session/default_spec.rb +4 -4
  43. data/spec/strelka/websocketserver/routing_spec.rb +1 -1
  44. metadata +29 -15
  45. metadata.gz.sig +0 -0
@@ -50,9 +50,9 @@ class Strelka::HTTPRequest
50
50
  # * Mahlon E. Smith <mahlon@martini.nu>
51
51
  #
52
52
  class AcceptParam
53
- extend Loggability
54
- include Comparable,
55
- Strelka::AbstractClass
53
+ extend Loggability,
54
+ Strelka::AbstractClass
55
+ include Comparable
56
56
 
57
57
 
58
58
  # Loggability API -- set up logging under the 'strelka' log host
@@ -98,6 +98,10 @@ module Strelka::HTTPRequest::Negotiation
98
98
  return self.parse_negotiation_header( :accept, Strelka::HTTPRequest::MediaType ) do
99
99
  Strelka::HTTPRequest::MediaType.new( '*', '*' )
100
100
  end
101
+ rescue => err
102
+ self.log.error "%p while parsing the Accept header: %s" % [ err.class, err.message ]
103
+ self.log.debug " %s" % [ err.backtrace.join("\n ") ]
104
+ finish_with HTTP::BAD_REQUEST, "Malformed Accept header"
101
105
  end
102
106
 
103
107
 
@@ -2,6 +2,7 @@
2
2
  # vim: set nosta noet ts=4 sw=4:
3
3
  # encoding: utf-8
4
4
 
5
+
5
6
  require 'tempfile'
6
7
 
7
8
  require 'strelka' unless defined?( Strelka )
@@ -16,7 +17,7 @@ module Strelka
16
17
  #
17
18
  # # AbstractClass
18
19
  # class MyBaseClass
19
- # include Strelka::AbstractClass
20
+ # extend Strelka::AbstractClass
20
21
  #
21
22
  # # Define a method that will raise a NotImplementedError if called
22
23
  # pure_virtual :api_method
@@ -24,41 +25,39 @@ module Strelka
24
25
  #
25
26
  module AbstractClass
26
27
 
27
- ### Methods to be added to including classes
28
- module ClassMethods
29
-
30
- ### Define one or more "virtual" methods which will raise
31
- ### NotImplementedErrors when called via a concrete subclass.
32
- def pure_virtual( *syms )
33
- syms.each do |sym|
34
- define_method( sym ) do |*args|
35
- raise ::NotImplementedError,
36
- "%p does not provide an implementation of #%s" % [ self.class, sym ],
37
- caller(1)
38
- end
39
- end
40
- end
41
-
42
-
43
- ### Turn subclasses' new methods back to public.
44
- def inherited( subclass )
45
- subclass.module_eval { public_class_method :new }
46
- super
47
- end
48
-
49
- end # module ClassMethods
28
+ ### Extension callback -- mark the extended object's .new as private
29
+ def self::extended( mod )
30
+ super
31
+ mod.class_eval { private_class_method :new }
32
+ end
50
33
 
51
34
 
52
- ### Inclusion callback
35
+ ### Inclusion callback -- support backward-compatible inclusion.
53
36
  def self::included( mod )
37
+ mod.extend( self )
54
38
  super
55
- if mod.respond_to?( :new )
56
- mod.extend( ClassMethods )
57
- mod.module_eval { private_class_method :new }
39
+ end
40
+
41
+
42
+ ### Define one or more "virtual" methods which will raise
43
+ ### NotImplementedErrors when called via a concrete subclass.
44
+ def pure_virtual( *syms )
45
+ syms.each do |sym|
46
+ define_method( sym ) do |*args|
47
+ raise ::NotImplementedError,
48
+ "%p does not provide an implementation of #%s" % [ self.class, sym ],
49
+ caller(1)
50
+ end
58
51
  end
59
52
  end
60
53
 
61
54
 
55
+ ### Inheritance callback -- Turn subclasses' .new methods back to public.
56
+ def inherited( subclass )
57
+ subclass.module_eval { public_class_method :new }
58
+ super
59
+ end
60
+
62
61
  end # module AbstractClass
63
62
 
64
63
 
@@ -126,9 +126,7 @@ class Strelka::MultipartParser
126
126
  raise Strelka::ParseError, "No initial boundary"
127
127
 
128
128
  # Now scan until we see the ending boundary (the one with the trailing '--')
129
- begin
130
- key, val = self.scan_part
131
- end until @buffer.start_with?( '--' )
129
+ self.scan_part until @buffer.start_with?( '--' )
132
130
 
133
131
  self.log.debug "Finished parse. %d fields" % [ self.fields.length ]
134
132
  return self.fields
@@ -228,7 +228,6 @@ module Strelka
228
228
 
229
229
  self.log.debug " copying class instance variable %s (%p)" % [ ivar, copy ]
230
230
 
231
- # Don't duplicate modules/classes or immediates
232
231
  instance_variable_set( ivar, copy )
233
232
  self.log.debug " instance variable %p set to %p in %p" %
234
233
  [ ivar, self.instance_variable_get(ivar), self ]
@@ -268,7 +267,7 @@ module Strelka
268
267
  next
269
268
  end
270
269
 
271
- self.log.info " including %p." % [ mod ]
270
+ self.log.info " including %p in %p." % [ mod, self ]
272
271
  include( mod )
273
272
  end
274
273
 
@@ -25,8 +25,8 @@ require 'strelka/mixins'
25
25
  # #add_route and #route_request methods.
26
26
  class Strelka::Router
27
27
  extend Loggability,
28
- Pluggability
29
- include Strelka::AbstractClass
28
+ Pluggability,
29
+ Strelka::AbstractClass
30
30
 
31
31
  # Loggability API -- set up logging under the 'strelka' log host
32
32
  log_to :strelka
@@ -20,6 +20,7 @@ require 'strelka/mixins'
20
20
  #
21
21
  # * self.configure
22
22
  # * self.get_session_id
23
+ # * self.get_existing_session_id
23
24
  # * self.load_session_data
24
25
  # * self.save_session_data
25
26
  # * self.delete_session_data
@@ -44,8 +45,8 @@ require 'strelka/mixins'
44
45
  #
45
46
  class Strelka::Session
46
47
  extend Loggability,
47
- Pluggability
48
- include Strelka::AbstractClass
48
+ Pluggability,
49
+ Strelka::AbstractClass
49
50
 
50
51
 
51
52
  # Loggability API -- set up logging under the 'strelka' log host
@@ -122,6 +122,7 @@ class Strelka::Session::Db < Strelka::Session::Default
122
122
  return !self.dataset.filter( :session_id => id ).empty?
123
123
  end
124
124
 
125
+
125
126
  ### Configure the session class with the given +options+, which should be a
126
127
  ### Hash or an object that has a Hash-like interface.
127
128
  ###
@@ -142,13 +142,13 @@ describe Strelka::App::Auth do
142
142
 
143
143
  req = @request_factory.get( '/api/v1/string' )
144
144
  expect( app ).to require_auth_for_request( req )
145
- expect( app.request_should_auth?(req) ).to be_true()
145
+ expect( app.request_should_auth?(req) ).to be_truthy()
146
146
  req = @request_factory.get( '/api/v1/strong' )
147
- expect( app.request_should_auth?(req) ).to be_false()
147
+ expect( app.request_should_auth?(req) ).to be_falsey()
148
148
  req = @request_factory.get( '/api/v1/stri' )
149
- expect( app.request_should_auth?(req) ).to be_false()
149
+ expect( app.request_should_auth?(req) ).to be_falsey()
150
150
  req = @request_factory.get( '/api/v1/string/long' )
151
- expect( app.request_should_auth?(req) ).to be_false()
151
+ expect( app.request_should_auth?(req) ).to be_falsey()
152
152
  end
153
153
 
154
154
  it "allows auth criteria to be declared with a regexp" do
@@ -156,17 +156,17 @@ describe Strelka::App::Auth do
156
156
  app = @app.new
157
157
 
158
158
  req = @request_factory.get( '/api/v1/stri' )
159
- expect( app.request_should_auth?(req) ).to be_true()
159
+ expect( app.request_should_auth?(req) ).to be_truthy()
160
160
  req = @request_factory.get( '/api/v1/stro' )
161
- expect( app.request_should_auth?(req) ).to be_true()
161
+ expect( app.request_should_auth?(req) ).to be_truthy()
162
162
  req = @request_factory.get( '/api/v1/string' ) # not right-bound
163
- expect( app.request_should_auth?(req) ).to be_true()
163
+ expect( app.request_should_auth?(req) ).to be_truthy()
164
164
  req = @request_factory.get( '/api/v1/string/long' )
165
- expect( app.request_should_auth?(req) ).to be_true()
165
+ expect( app.request_should_auth?(req) ).to be_truthy()
166
166
  req = @request_factory.get( '/api/v1/other/string/long' ) # Not left-bound
167
- expect( app.request_should_auth?(req) ).to be_true()
167
+ expect( app.request_should_auth?(req) ).to be_truthy()
168
168
  req = @request_factory.get( '/api/v1/chatlog' ) # Not left-bound
169
- expect( app.request_should_auth?(req) ).to be_false()
169
+ expect( app.request_should_auth?(req) ).to be_falsey()
170
170
  end
171
171
 
172
172
  it "allows auth criteria to be declared with a string and a block" do
@@ -177,15 +177,15 @@ describe Strelka::App::Auth do
177
177
  app = @app.new
178
178
 
179
179
  req = @request_factory.get( '/api/v1/string' )
180
- expect( app.request_should_auth?(req) ).to be_false()
180
+ expect( app.request_should_auth?(req) ).to be_falsey()
181
181
  req = @request_factory.post( '/api/v1/string' )
182
- expect( app.request_should_auth?(req) ).to be_true()
182
+ expect( app.request_should_auth?(req) ).to be_truthy()
183
183
  req = @request_factory.put( '/api/v1/string' )
184
- expect( app.request_should_auth?(req) ).to be_true()
184
+ expect( app.request_should_auth?(req) ).to be_truthy()
185
185
  req = @request_factory.delete( '/api/v1/string' )
186
- expect( app.request_should_auth?(req) ).to be_true()
186
+ expect( app.request_should_auth?(req) ).to be_truthy()
187
187
  req = @request_factory.options( '/api/v1/string' )
188
- expect( app.request_should_auth?(req) ).to be_true()
188
+ expect( app.request_should_auth?(req) ).to be_truthy()
189
189
  end
190
190
 
191
191
  it "allows auth criteria to be declared with a regexp and a block" do
@@ -196,11 +196,11 @@ describe Strelka::App::Auth do
196
196
  app = @app.new
197
197
 
198
198
  req = @request_factory.get( '/api/v1/regexp' )
199
- expect( app.request_should_auth?(req) ).to be_false()
199
+ expect( app.request_should_auth?(req) ).to be_falsey()
200
200
  req = @request_factory.get( '/api/v1/regexp/a_username' )
201
- expect( app.request_should_auth?(req) ).to be_true()
201
+ expect( app.request_should_auth?(req) ).to be_truthy()
202
202
  req = @request_factory.get( '/api/v1/regexp/%20not+a+username' )
203
- expect( app.request_should_auth?(req) ).to be_false()
203
+ expect( app.request_should_auth?(req) ).to be_falsey()
204
204
  end
205
205
 
206
206
  it "allows auth criteria to be declared with just a block" do
@@ -218,21 +218,21 @@ describe Strelka::App::Auth do
218
218
  app = @app.new
219
219
 
220
220
  req = @request_factory.get( '/api/v1/strong' )
221
- expect( app.request_should_auth?(req) ).to be_true()
221
+ expect( app.request_should_auth?(req) ).to be_truthy()
222
222
  req = @request_factory.get( '/api/v1/marlon_brando' )
223
- expect( app.request_should_auth?(req) ).to be_true()
223
+ expect( app.request_should_auth?(req) ).to be_truthy()
224
224
  req = @request_factory.post( '/api/v1/somewhere' )
225
- expect( app.request_should_auth?(req) ).to be_true()
225
+ expect( app.request_should_auth?(req) ).to be_truthy()
226
226
  req = @request_factory.put( '/api/v1/somewhere' )
227
227
  req.content_type = 'application/x-www-form-urlencoded'
228
- expect( app.request_should_auth?(req) ).to be_true()
228
+ expect( app.request_should_auth?(req) ).to be_truthy()
229
229
 
230
230
  req = @request_factory.get( '/api/v1/string' )
231
- expect( app.request_should_auth?(req) ).to be_false()
231
+ expect( app.request_should_auth?(req) ).to be_falsey()
232
232
  req = @request_factory.get( '/api/v1/marlon_brando/2' )
233
- expect( app.request_should_auth?(req) ).to be_false()
233
+ expect( app.request_should_auth?(req) ).to be_falsey()
234
234
  req = @request_factory.put( '/api/v1/somewhere' )
235
- expect( app.request_should_auth?(req) ).to be_false()
235
+ expect( app.request_should_auth?(req) ).to be_falsey()
236
236
 
237
237
  end
238
238
 
@@ -241,13 +241,13 @@ describe Strelka::App::Auth do
241
241
  app = @app.new
242
242
 
243
243
  req = @request_factory.get( '/api/v1/string' )
244
- expect( app.request_should_auth?(req) ).to be_false()
244
+ expect( app.request_should_auth?(req) ).to be_falsey()
245
245
  req = @request_factory.get( '/api/v1/strong' )
246
- expect( app.request_should_auth?(req) ).to be_true()
246
+ expect( app.request_should_auth?(req) ).to be_truthy()
247
247
  req = @request_factory.get( '/api/v1/stri' )
248
- expect( app.request_should_auth?(req) ).to be_true()
248
+ expect( app.request_should_auth?(req) ).to be_truthy()
249
249
  req = @request_factory.get( '/api/v1/string/long' )
250
- expect( app.request_should_auth?(req) ).to be_true()
250
+ expect( app.request_should_auth?(req) ).to be_truthy()
251
251
  end
252
252
 
253
253
  it "allows negative auth criteria to be declared with a regexp" do
@@ -255,17 +255,17 @@ describe Strelka::App::Auth do
255
255
  app = @app.new
256
256
 
257
257
  req = @request_factory.get( '/api/v1/stri' )
258
- expect( app.request_should_auth?(req) ).to be_false()
258
+ expect( app.request_should_auth?(req) ).to be_falsey()
259
259
  req = @request_factory.get( '/api/v1/stro' )
260
- expect( app.request_should_auth?(req) ).to be_false()
260
+ expect( app.request_should_auth?(req) ).to be_falsey()
261
261
  req = @request_factory.get( '/api/v1/string' ) # not right-bound
262
- expect( app.request_should_auth?(req) ).to be_false()
262
+ expect( app.request_should_auth?(req) ).to be_falsey()
263
263
  req = @request_factory.get( '/api/v1/string/long' )
264
- expect( app.request_should_auth?(req) ).to be_false()
264
+ expect( app.request_should_auth?(req) ).to be_falsey()
265
265
  req = @request_factory.get( '/api/v1/other/string/long' ) # Not left-bound
266
- expect( app.request_should_auth?(req) ).to be_false()
266
+ expect( app.request_should_auth?(req) ).to be_falsey()
267
267
  req = @request_factory.get( '/api/v1/chat' )
268
- expect( app.request_should_auth?(req) ).to be_true()
268
+ expect( app.request_should_auth?(req) ).to be_truthy()
269
269
  end
270
270
 
271
271
  it "allows negative auth criteria to be declared with a string and a block" do
@@ -274,17 +274,17 @@ describe Strelka::App::Auth do
274
274
  app = @app.new
275
275
 
276
276
  req = @request_factory.get( '/api/v1/string' )
277
- expect( app.request_should_auth?(req) ).to be_false()
277
+ expect( app.request_should_auth?(req) ).to be_falsey()
278
278
  req = @request_factory.get( '/api/v1/strong' )
279
- expect( app.request_should_auth?(req) ).to be_true()
279
+ expect( app.request_should_auth?(req) ).to be_truthy()
280
280
  req = @request_factory.post( '/api/v1/string' )
281
- expect( app.request_should_auth?(req) ).to be_true()
281
+ expect( app.request_should_auth?(req) ).to be_truthy()
282
282
  req = @request_factory.put( '/api/v1/string' )
283
- expect( app.request_should_auth?(req) ).to be_true()
283
+ expect( app.request_should_auth?(req) ).to be_truthy()
284
284
  req = @request_factory.delete( '/api/v1/string' )
285
- expect( app.request_should_auth?(req) ).to be_true()
285
+ expect( app.request_should_auth?(req) ).to be_truthy()
286
286
  req = @request_factory.options( '/api/v1/string' )
287
- expect( app.request_should_auth?(req) ).to be_true()
287
+ expect( app.request_should_auth?(req) ).to be_truthy()
288
288
  end
289
289
 
290
290
  it "allows negative auth criteria to be declared with a regexp and a block" do
@@ -295,13 +295,13 @@ describe Strelka::App::Auth do
295
295
  app = @app.new
296
296
 
297
297
  req = @request_factory.get( '/api/v1/regexp' )
298
- expect( app.request_should_auth?(req) ).to be_true()
298
+ expect( app.request_should_auth?(req) ).to be_truthy()
299
299
  req = @request_factory.get( '/api/v1/regexp/a_username' )
300
- expect( app.request_should_auth?(req) ).to be_true()
300
+ expect( app.request_should_auth?(req) ).to be_truthy()
301
301
  req = @request_factory.get( '/api/v1/regexp/%20not+a+username' )
302
- expect( app.request_should_auth?(req) ).to be_true()
302
+ expect( app.request_should_auth?(req) ).to be_truthy()
303
303
  req = @request_factory.get( '/api/v1/regexp/guest' )
304
- expect( app.request_should_auth?(req) ).to be_false()
304
+ expect( app.request_should_auth?(req) ).to be_falsey()
305
305
  end
306
306
 
307
307
  it "allows negative auth criteria to be declared with just a block" do
@@ -314,11 +314,11 @@ describe Strelka::App::Auth do
314
314
  app = @app.new
315
315
 
316
316
  req = @request_factory.get( '/api/v1/foom' )
317
- expect( app.request_should_auth?(req) ).to be_true()
317
+ expect( app.request_should_auth?(req) ).to be_truthy()
318
318
  req = @request_factory.post( '/api/v1/foom', :accept => 'text/plain, text/html; q=0.5' )
319
- expect( app.request_should_auth?(req) ).to be_true()
319
+ expect( app.request_should_auth?(req) ).to be_truthy()
320
320
  req = @request_factory.get( '/api/v1/foom', :accept => 'text/plain, text/html; q=0.5' )
321
- expect( app.request_should_auth?(req) ).to be_false()
321
+ expect( app.request_should_auth?(req) ).to be_falsey()
322
322
 
323
323
  end
324
324
 
@@ -94,11 +94,11 @@ describe Strelka::App::Filters do
94
94
 
95
95
 
96
96
  it "has a single request filter" do
97
- expect( @app.request_filters ).to have(1).member
97
+ expect( @app.request_filters.size ).to eq( 1 )
98
98
  end
99
99
 
100
100
  it "has a single response filter" do
101
- expect( @app.response_filters ).to have(1).member
101
+ expect( @app.response_filters.size ).to eq( 1 )
102
102
  end
103
103
 
104
104
  it "passes both the request and the response through it" do
@@ -106,8 +106,8 @@ describe Strelka::App::Filters do
106
106
 
107
107
  res = @app.new.handle( req )
108
108
 
109
- expect( req.notes[:saw][:request] ).to be_true()
110
- expect( res.notes[:saw][:response] ).to be_true()
109
+ expect( req.notes[:saw][:request] ).to be_truthy()
110
+ expect( res.notes[:saw][:response] ).to be_truthy()
111
111
  end
112
112
 
113
113
  end
@@ -132,7 +132,7 @@ describe Strelka::App::Filters do
132
132
 
133
133
 
134
134
  it "has a single request filter" do
135
- expect( @app.request_filters ).to have(1).member
135
+ expect( @app.request_filters.size ).to eq( 1 )
136
136
  end
137
137
 
138
138
  it "has no response filters" do
@@ -144,7 +144,7 @@ describe Strelka::App::Filters do
144
144
 
145
145
  res = @app.new.handle( req )
146
146
 
147
- expect( req.notes[:saw][:request] ).to be_true()
147
+ expect( req.notes[:saw][:request] ).to be_truthy()
148
148
  expect( res.notes[:saw][:response] ).to be_nil()
149
149
  end
150
150
 
@@ -174,7 +174,7 @@ describe Strelka::App::Filters do
174
174
  end
175
175
 
176
176
  it "has no response filters" do
177
- expect( @app.response_filters ).to have(1).member
177
+ expect( @app.response_filters.size ).to eq( 1 )
178
178
  end
179
179
 
180
180
  it "passes just the response through it" do
@@ -183,7 +183,7 @@ describe Strelka::App::Filters do
183
183
  res = @app.new.handle( req )
184
184
 
185
185
  expect( req.notes[:saw][:request] ).to be_nil()
186
- expect( res.notes[:saw][:response] ).to be_true()
186
+ expect( res.notes[:saw][:response] ).to be_truthy()
187
187
  end
188
188
 
189
189
  end
@@ -139,7 +139,7 @@ describe Strelka::App::Parameters do
139
139
  untaint_all_constraints true
140
140
  end
141
141
 
142
- expect( @app.untaint_all_constraints ).to be_true()
142
+ expect( @app.untaint_all_constraints ).to be_truthy()
143
143
  req = @request_factory.get( '/user/search?username=shereshnaheth'.taint )
144
144
  @app.new.handle( req )
145
145