strelka 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/ChangeLog +156 -9
- data/History.rdoc +15 -0
- data/IDEAS.rdoc +17 -1
- data/MILESTONES.rdoc +1 -1
- data/Manifest.txt +10 -2
- data/Plugins.rdoc +4 -4
- data/README.rdoc +3 -3
- data/Rakefile +5 -4
- data/bin/strelka +19 -10
- data/contrib/hoetemplate/data/project/apps/file_name_app +1 -0
- data/contrib/hoetemplate/lib/file_name.rb.erb +3 -2
- data/examples/apps/hello-world +1 -0
- data/examples/apps/ws-chat +69 -0
- data/examples/apps/ws-echo +61 -0
- data/examples/gen-config.rb +6 -5
- data/lib/strelka/app/auth.rb +2 -2
- data/lib/strelka/app/errors.rb +1 -1
- data/lib/strelka/app/filters.rb +3 -2
- data/lib/strelka/app/negotiation.rb +2 -2
- data/lib/strelka/app/parameters.rb +1 -2
- data/lib/strelka/app/restresources.rb +3 -2
- data/lib/strelka/app/routing.rb +1 -1
- data/lib/strelka/app/sessions.rb +2 -2
- data/lib/strelka/app/templating.rb +7 -3
- data/lib/strelka/app.rb +5 -145
- data/lib/strelka/behavior/plugin.rb +4 -4
- data/lib/strelka/discovery.rb +211 -0
- data/lib/strelka/httprequest.rb +1 -0
- data/lib/strelka/httpresponse/negotiation.rb +7 -1
- data/lib/strelka/mixins.rb +4 -1
- data/lib/strelka/paramvalidator.rb +1 -1
- data/lib/strelka/plugins.rb +8 -6
- data/lib/strelka/websocketserver/routing.rb +116 -0
- data/lib/strelka/websocketserver.rb +147 -0
- data/lib/strelka.rb +5 -4
- data/spec/{lib/constants.rb → constants.rb} +3 -2
- data/spec/{lib/helpers.rb → helpers.rb} +15 -14
- data/spec/strelka/app/auth_spec.rb +145 -142
- data/spec/strelka/app/errors_spec.rb +20 -26
- data/spec/strelka/app/filters_spec.rb +67 -54
- data/spec/strelka/app/negotiation_spec.rb +8 -14
- data/spec/strelka/app/parameters_spec.rb +23 -29
- data/spec/strelka/app/restresources_spec.rb +98 -100
- data/spec/strelka/app/routing_spec.rb +57 -57
- data/spec/strelka/app/sessions_spec.rb +11 -17
- data/spec/strelka/app/templating_spec.rb +36 -40
- data/spec/strelka/app_spec.rb +48 -147
- data/spec/strelka/authprovider/basic_spec.rb +5 -11
- data/spec/strelka/authprovider/hostaccess_spec.rb +9 -15
- data/spec/strelka/authprovider_spec.rb +3 -9
- data/spec/strelka/cookie_spec.rb +32 -38
- data/spec/strelka/cookieset_spec.rb +31 -37
- data/spec/strelka/discovery_spec.rb +144 -0
- data/spec/strelka/exceptions_spec.rb +2 -8
- data/spec/strelka/httprequest/acceptparams_spec.rb +74 -83
- data/spec/strelka/httprequest/auth_spec.rb +5 -15
- data/spec/strelka/httprequest/negotiation_spec.rb +93 -103
- data/spec/strelka/httprequest/session_spec.rb +12 -22
- data/spec/strelka/httprequest_spec.rb +1 -7
- data/spec/strelka/httpresponse/negotiation_spec.rb +84 -76
- data/spec/strelka/httpresponse/session_spec.rb +25 -35
- data/spec/strelka/httpresponse_spec.rb +20 -26
- data/spec/strelka/mixins_spec.rb +66 -61
- data/spec/strelka/multipartparser_spec.rb +31 -37
- data/spec/strelka/paramvalidator_spec.rb +389 -373
- data/spec/strelka/plugins_spec.rb +17 -23
- data/spec/strelka/router/default_spec.rb +32 -38
- data/spec/strelka/router/exclusive_spec.rb +28 -34
- data/spec/strelka/router_spec.rb +2 -8
- data/spec/strelka/session/db_spec.rb +17 -15
- data/spec/strelka/session/default_spec.rb +22 -28
- data/spec/strelka/session_spec.rb +3 -9
- data/spec/strelka/websocketserver/routing_spec.rb +119 -0
- data/spec/strelka/websocketserver_spec.rb +149 -0
- data/spec/strelka_spec.rb +11 -13
- data.tar.gz.sig +3 -3
- metadata +22 -14
- metadata.gz.sig +0 -0
@@ -2,17 +2,11 @@
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
3
3
|
# encoding: utf-8
|
4
4
|
|
5
|
-
|
6
|
-
require 'pathname'
|
7
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
|
8
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
9
|
-
}
|
5
|
+
require_relative '../../helpers'
|
10
6
|
|
11
7
|
require 'rspec'
|
12
8
|
require 'inversion'
|
13
9
|
|
14
|
-
require 'spec/lib/helpers'
|
15
|
-
|
16
10
|
require 'strelka'
|
17
11
|
require 'strelka/plugins'
|
18
12
|
require 'strelka/app/errors'
|
@@ -36,7 +30,7 @@ describe Strelka::App::Errors do
|
|
36
30
|
end
|
37
31
|
|
38
32
|
|
39
|
-
it_should_behave_like( "A Strelka
|
33
|
+
it_should_behave_like( "A Strelka Plugin" )
|
40
34
|
|
41
35
|
|
42
36
|
describe "an including App" do
|
@@ -55,8 +49,8 @@ describe Strelka::App::Errors do
|
|
55
49
|
'blap'
|
56
50
|
end
|
57
51
|
subclass = Class.new( @app )
|
58
|
-
subclass.status_handlers.
|
59
|
-
subclass.status_handlers.
|
52
|
+
expect( subclass.status_handlers ).to eq( @app.status_handlers )
|
53
|
+
expect( subclass.status_handlers ).to_not equal( @app.status_handlers )
|
60
54
|
end
|
61
55
|
|
62
56
|
it "doesn't alter normal responses" do
|
@@ -72,9 +66,9 @@ describe Strelka::App::Errors do
|
|
72
66
|
req = @request_factory.get( '/koolaid' )
|
73
67
|
res = @app.new.handle( req )
|
74
68
|
|
75
|
-
res.status.
|
69
|
+
expect( res.status ).to eq( HTTP::OK )
|
76
70
|
res.body.rewind
|
77
|
-
res.body.read.
|
71
|
+
expect( res.body.read ).to eq( "Oh yeah! Kool-Aid!\n" )
|
78
72
|
end
|
79
73
|
|
80
74
|
it "raises an error if a handler is declared with both a template and a block" do
|
@@ -107,7 +101,7 @@ describe Strelka::App::Errors do
|
|
107
101
|
res = @app.new.handle( req )
|
108
102
|
|
109
103
|
res.body.rewind
|
110
|
-
res.body.read.
|
104
|
+
expect( res.body.read ).to match( /internal server error/i )
|
111
105
|
end
|
112
106
|
|
113
107
|
it "calls a callback-style handler for any status when finished with BAD_REQUEST" do
|
@@ -125,9 +119,9 @@ describe Strelka::App::Errors do
|
|
125
119
|
req = @request_factory.get( '/foom' )
|
126
120
|
res = @app.new.handle( req )
|
127
121
|
|
128
|
-
res.status.
|
122
|
+
expect( res.status ).to eq( HTTP::BAD_REQUEST )
|
129
123
|
res.body.rewind
|
130
|
-
res.body.read.
|
124
|
+
expect( res.body.read ).to eq( '(400) Filthy banana' )
|
131
125
|
end
|
132
126
|
|
133
127
|
|
@@ -143,7 +137,7 @@ describe Strelka::App::Errors do
|
|
143
137
|
res = @app.new.handle( req )
|
144
138
|
|
145
139
|
res.body.rewind
|
146
|
-
res.body.read.
|
140
|
+
expect( res.body.read ).to eq( 'NOPE!' )
|
147
141
|
end
|
148
142
|
|
149
143
|
|
@@ -159,7 +153,7 @@ describe Strelka::App::Errors do
|
|
159
153
|
res = @app.new.handle( req )
|
160
154
|
|
161
155
|
res.body.rewind
|
162
|
-
res.body.read.
|
156
|
+
expect( res.body.read ).to eq( 'Error: JAMBA' )
|
163
157
|
end
|
164
158
|
|
165
159
|
it "sets the error status info in the transaction notes when the response is handled by a status-handler" do
|
@@ -177,9 +171,9 @@ describe Strelka::App::Errors do
|
|
177
171
|
req = @request_factory.get( '/foom' )
|
178
172
|
res = @app.new.handle( req )
|
179
173
|
|
180
|
-
res.notes[:status_info].
|
181
|
-
res.notes[:status_info][:status].
|
182
|
-
res.notes[:status_info][:message].
|
174
|
+
expect( res.notes[:status_info] ).to include( :status, :message, :headers )
|
175
|
+
expect( res.notes[:status_info][:status] ).to eq( HTTP::BAD_REQUEST )
|
176
|
+
expect( res.notes[:status_info][:message] ).to eq( "Your sandwich is missing something." )
|
183
177
|
end
|
184
178
|
|
185
179
|
it "provides its own exception handler for the request phase" do
|
@@ -197,12 +191,12 @@ describe Strelka::App::Errors do
|
|
197
191
|
req = @request_factory.get( '/foom' )
|
198
192
|
res = @app.new.handle( req )
|
199
193
|
|
200
|
-
res.notes[:status_info].
|
201
|
-
res.notes[:status_info][:status].
|
202
|
-
res.notes[:status_info][:message].
|
203
|
-
res.notes[:status_info][:exception].
|
194
|
+
expect( res.notes[:status_info] ).to include( :status, :message, :headers, :exception )
|
195
|
+
expect( res.notes[:status_info][:status] ).to eq( HTTP::SERVER_ERROR )
|
196
|
+
expect( res.notes[:status_info][:message] ).to eq( "An uncaught exception" )
|
197
|
+
expect( res.notes[:status_info][:exception] ).to be_a( RuntimeError )
|
204
198
|
res.body.rewind
|
205
|
-
res.body.read.
|
199
|
+
expect( res.body.read ).to eq( "RuntimeError" )
|
206
200
|
end
|
207
201
|
|
208
202
|
|
@@ -235,7 +229,7 @@ describe Strelka::App::Errors do
|
|
235
229
|
res = @app.new.handle( req )
|
236
230
|
|
237
231
|
res.body.rewind
|
238
|
-
res.body.read.
|
232
|
+
expect( res.body.read ).to match( /error-handler template/i )
|
239
233
|
end
|
240
234
|
end
|
241
235
|
|
@@ -2,16 +2,10 @@
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
3
3
|
# encoding: utf-8
|
4
4
|
|
5
|
-
|
6
|
-
require 'pathname'
|
7
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
|
8
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
9
|
-
}
|
5
|
+
require_relative '../../helpers'
|
10
6
|
|
11
7
|
require 'rspec'
|
12
8
|
|
13
|
-
require 'spec/lib/helpers'
|
14
|
-
|
15
9
|
require 'strelka'
|
16
10
|
require 'strelka/plugins'
|
17
11
|
require 'strelka/app/filters'
|
@@ -35,10 +29,10 @@ describe Strelka::App::Filters do
|
|
35
29
|
end
|
36
30
|
|
37
31
|
|
38
|
-
it_should_behave_like( "A Strelka
|
32
|
+
it_should_behave_like( "A Strelka Plugin" )
|
39
33
|
|
40
34
|
|
41
|
-
|
35
|
+
context "an including App" do
|
42
36
|
|
43
37
|
before( :each ) do
|
44
38
|
@app = Class.new( Strelka::App ) do
|
@@ -55,41 +49,39 @@ describe Strelka::App::Filters do
|
|
55
49
|
end
|
56
50
|
subclass = Class.new( @app )
|
57
51
|
|
58
|
-
subclass.filters.
|
59
|
-
subclass.filters.
|
60
|
-
subclass.filters[:request].
|
61
|
-
subclass.filters[:response].
|
62
|
-
subclass.filters[:both].
|
52
|
+
expect( subclass.filters ).to eq( @app.filters )
|
53
|
+
expect( subclass.filters ).to_not equal( @app.filters )
|
54
|
+
expect( subclass.filters[:request] ).to_not equal( @app.filters[:request] )
|
55
|
+
expect( subclass.filters[:response] ).to_not equal( @app.filters[:response] )
|
56
|
+
expect( subclass.filters[:both] ).to_not equal( @app.filters[:both] )
|
63
57
|
end
|
64
58
|
|
65
59
|
it "has a Hash of filters" do
|
66
|
-
@app.filters.
|
60
|
+
expect( @app.filters ).to be_a( Hash )
|
67
61
|
end
|
68
62
|
|
69
63
|
|
70
|
-
|
64
|
+
context "that doesn't declare any filters" do
|
71
65
|
|
72
66
|
it "doesn't have any request filters" do
|
73
|
-
@app.request_filters.
|
67
|
+
expect( @app.request_filters ).to be_empty()
|
74
68
|
end
|
75
69
|
|
76
70
|
it "doesn't have any response filters" do
|
77
|
-
@app.response_filters.
|
71
|
+
expect( @app.response_filters ).to be_empty()
|
78
72
|
end
|
79
73
|
|
80
74
|
end
|
81
75
|
|
82
76
|
|
83
|
-
|
77
|
+
context "that declares a filter without a phase" do
|
84
78
|
|
85
79
|
before( :each ) do
|
86
|
-
@app.
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
reqres.notes[:saw][:response] = true
|
92
|
-
end
|
80
|
+
@app.filter do |reqres|
|
81
|
+
if reqres.is_a?( Strelka::HTTPRequest )
|
82
|
+
reqres.notes[:saw][:request] = true
|
83
|
+
else
|
84
|
+
reqres.notes[:saw][:response] = true
|
93
85
|
end
|
94
86
|
end
|
95
87
|
end
|
@@ -102,11 +94,11 @@ describe Strelka::App::Filters do
|
|
102
94
|
|
103
95
|
|
104
96
|
it "has a single request filter" do
|
105
|
-
@app.request_filters.
|
97
|
+
expect( @app.request_filters ).to have(1).member
|
106
98
|
end
|
107
99
|
|
108
100
|
it "has a single response filter" do
|
109
|
-
@app.response_filters.
|
101
|
+
expect( @app.response_filters ).to have(1).member
|
110
102
|
end
|
111
103
|
|
112
104
|
it "passes both the request and the response through it" do
|
@@ -114,22 +106,20 @@ describe Strelka::App::Filters do
|
|
114
106
|
|
115
107
|
res = @app.new.handle( req )
|
116
108
|
|
117
|
-
req.notes[:saw][:request].
|
118
|
-
res.notes[:saw][:response].
|
109
|
+
expect( req.notes[:saw][:request] ).to be_true()
|
110
|
+
expect( res.notes[:saw][:response] ).to be_true()
|
119
111
|
end
|
120
112
|
|
121
113
|
end
|
122
114
|
|
123
|
-
|
115
|
+
context "that declares a request filter" do
|
124
116
|
|
125
117
|
before( :each ) do
|
126
|
-
@app.
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
reqres.notes[:saw][:response] = true
|
132
|
-
end
|
118
|
+
@app.filter( :request ) do |reqres|
|
119
|
+
if reqres.is_a?( Strelka::HTTPRequest )
|
120
|
+
reqres.notes[:saw][:request] = true
|
121
|
+
else
|
122
|
+
reqres.notes[:saw][:response] = true
|
133
123
|
end
|
134
124
|
end
|
135
125
|
end
|
@@ -142,11 +132,11 @@ describe Strelka::App::Filters do
|
|
142
132
|
|
143
133
|
|
144
134
|
it "has a single request filter" do
|
145
|
-
@app.request_filters.
|
135
|
+
expect( @app.request_filters ).to have(1).member
|
146
136
|
end
|
147
137
|
|
148
138
|
it "has no response filters" do
|
149
|
-
@app.response_filters.
|
139
|
+
expect( @app.response_filters ).to be_empty()
|
150
140
|
end
|
151
141
|
|
152
142
|
it "passes just the request through it" do
|
@@ -154,22 +144,20 @@ describe Strelka::App::Filters do
|
|
154
144
|
|
155
145
|
res = @app.new.handle( req )
|
156
146
|
|
157
|
-
req.notes[:saw][:request].
|
158
|
-
res.notes[:saw][:response].
|
147
|
+
expect( req.notes[:saw][:request] ).to be_true()
|
148
|
+
expect( res.notes[:saw][:response] ).to be_nil()
|
159
149
|
end
|
160
150
|
|
161
151
|
end
|
162
152
|
|
163
|
-
|
153
|
+
context "that declares a response filter" do
|
164
154
|
|
165
155
|
before( :each ) do
|
166
|
-
@app.
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
reqres.notes[:saw][:response] = true
|
172
|
-
end
|
156
|
+
@app.filter( :response ) do |reqres|
|
157
|
+
if reqres.is_a?( Strelka::HTTPRequest )
|
158
|
+
reqres.notes[:saw][:request] = true
|
159
|
+
else
|
160
|
+
reqres.notes[:saw][:response] = true
|
173
161
|
end
|
174
162
|
end
|
175
163
|
end
|
@@ -182,11 +170,11 @@ describe Strelka::App::Filters do
|
|
182
170
|
|
183
171
|
|
184
172
|
it "has no request filters" do
|
185
|
-
@app.request_filters.
|
173
|
+
expect( @app.request_filters ).to be_empty()
|
186
174
|
end
|
187
175
|
|
188
176
|
it "has no response filters" do
|
189
|
-
@app.response_filters.
|
177
|
+
expect( @app.response_filters ).to have(1).member
|
190
178
|
end
|
191
179
|
|
192
180
|
it "passes just the response through it" do
|
@@ -194,10 +182,35 @@ describe Strelka::App::Filters do
|
|
194
182
|
|
195
183
|
res = @app.new.handle( req )
|
196
184
|
|
197
|
-
req.notes[:saw][:request].
|
198
|
-
res.notes[:saw][:response].
|
185
|
+
expect( req.notes[:saw][:request] ).to be_nil()
|
186
|
+
expect( res.notes[:saw][:response] ).to be_true()
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
context "that returns something other than an HTTPResponse from its handler" do
|
193
|
+
|
194
|
+
before( :each ) do
|
195
|
+
@app.class_eval do
|
196
|
+
plugin :templating
|
197
|
+
templates :main => 'spec/data/main.tmpl'
|
198
|
+
def handle_request( req )
|
199
|
+
super { :main }
|
200
|
+
end
|
201
|
+
end
|
199
202
|
end
|
200
203
|
|
204
|
+
it "still gives the response filter an HTTPResponse" do
|
205
|
+
@app.filter( :response ) do |res|
|
206
|
+
expect( res ).to be_a( Strelka::HTTPResponse )
|
207
|
+
end
|
208
|
+
|
209
|
+
req = @request_factory.get( '/account/118811' )
|
210
|
+
res = @app.new.handle( req )
|
211
|
+
|
212
|
+
expect( res.status_line ).to match( /200 ok/i )
|
213
|
+
end
|
201
214
|
end
|
202
215
|
|
203
216
|
end
|
@@ -2,16 +2,10 @@
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
3
3
|
# encoding: utf-8
|
4
4
|
|
5
|
-
|
6
|
-
require 'pathname'
|
7
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
|
8
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
9
|
-
}
|
5
|
+
require_relative '../../helpers'
|
10
6
|
|
11
7
|
require 'rspec'
|
12
8
|
|
13
|
-
require 'spec/lib/helpers'
|
14
|
-
|
15
9
|
require 'strelka'
|
16
10
|
require 'strelka/plugins'
|
17
11
|
require 'strelka/app/negotiation'
|
@@ -35,7 +29,7 @@ describe Strelka::App::Negotiation do
|
|
35
29
|
end
|
36
30
|
|
37
31
|
|
38
|
-
it_should_behave_like( "A Strelka
|
32
|
+
it_should_behave_like( "A Strelka Plugin" )
|
39
33
|
|
40
34
|
|
41
35
|
describe "an including App" do
|
@@ -70,22 +64,22 @@ describe Strelka::App::Negotiation do
|
|
70
64
|
it "gets requests that have been extended with content-negotiation" do
|
71
65
|
req = @request_factory.get( '/service/user/estark' )
|
72
66
|
@app.new.handle( req )
|
73
|
-
req.singleton_class.included_modules.
|
74
|
-
|
67
|
+
expect( req.singleton_class.included_modules ).
|
68
|
+
to include( Strelka::HTTPRequest::Negotiation )
|
75
69
|
end
|
76
70
|
|
77
71
|
it "gets responses that have been extended with content-negotiation" do
|
78
72
|
req = @request_factory.get( '/service/user/estark' )
|
79
73
|
res = @app.new.handle( req )
|
80
|
-
res.singleton_class.included_modules.
|
81
|
-
|
74
|
+
expect( res.singleton_class.included_modules ).
|
75
|
+
to include( Strelka::HTTPResponse::Negotiation )
|
82
76
|
end
|
83
77
|
|
84
78
|
it "adds custom content-type transforms to outgoing responses" do
|
85
79
|
req = @request_factory.get( '/service/user/astark', :accept => 'text/x-tnetstring' )
|
86
80
|
res = @app.new.handle( req )
|
87
|
-
res.content_type.
|
88
|
-
res.body.read.
|
81
|
+
expect( res.content_type ).to eq( 'text/x-tnetstring' )
|
82
|
+
expect( res.body.read ).to eq( '28:2:an,19:5:array,8:of stuff,}]' )
|
89
83
|
end
|
90
84
|
|
91
85
|
end
|
@@ -2,16 +2,10 @@
|
|
2
2
|
# vim: set nosta noet ts=4 sw=4:
|
3
3
|
# encoding: utf-8
|
4
4
|
|
5
|
-
|
6
|
-
require 'pathname'
|
7
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent.parent
|
8
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
9
|
-
}
|
5
|
+
require_relative '../../helpers'
|
10
6
|
|
11
7
|
require 'rspec'
|
12
8
|
|
13
|
-
require 'spec/lib/helpers'
|
14
|
-
|
15
9
|
require 'strelka'
|
16
10
|
require 'strelka/plugins'
|
17
11
|
require 'strelka/app/parameters'
|
@@ -34,7 +28,7 @@ describe Strelka::App::Parameters do
|
|
34
28
|
end
|
35
29
|
|
36
30
|
|
37
|
-
it_should_behave_like( "A Strelka
|
31
|
+
it_should_behave_like( "A Strelka Plugin" )
|
38
32
|
|
39
33
|
|
40
34
|
describe "an including App" do
|
@@ -56,12 +50,12 @@ describe Strelka::App::Parameters do
|
|
56
50
|
@app.param :string
|
57
51
|
subclass = Class.new( @app )
|
58
52
|
|
59
|
-
subclass.paramvalidator.param_names.
|
60
|
-
subclass.paramvalidator.
|
53
|
+
expect( subclass.paramvalidator.param_names ).to eq( @app.paramvalidator.param_names )
|
54
|
+
expect( subclass.paramvalidator ).to_not equal( @app.paramvalidator )
|
61
55
|
end
|
62
56
|
|
63
57
|
it "has a ParamValidator" do
|
64
|
-
@app.paramvalidator.
|
58
|
+
expect( @app.paramvalidator ).to be_a( Strelka::ParamValidator )
|
65
59
|
end
|
66
60
|
|
67
61
|
it "can declare a parameter with a regular-expression constraint" do
|
@@ -69,7 +63,7 @@ describe Strelka::App::Parameters do
|
|
69
63
|
param :username, /\w+/i
|
70
64
|
end
|
71
65
|
|
72
|
-
@app.paramvalidator.param_names.
|
66
|
+
expect( @app.paramvalidator.param_names ).to eq( [ 'username' ] )
|
73
67
|
end
|
74
68
|
|
75
69
|
it "can declare a parameter with a builtin constraint" do
|
@@ -77,7 +71,7 @@ describe Strelka::App::Parameters do
|
|
77
71
|
param :comment_body, :printable
|
78
72
|
end
|
79
73
|
|
80
|
-
@app.paramvalidator.param_names.
|
74
|
+
expect( @app.paramvalidator.param_names ).to eq( [ 'comment_body' ] )
|
81
75
|
end
|
82
76
|
|
83
77
|
it "can declare a parameter with a Proc constraint" do
|
@@ -87,7 +81,7 @@ describe Strelka::App::Parameters do
|
|
87
81
|
end
|
88
82
|
end
|
89
83
|
|
90
|
-
@app.paramvalidator.param_names.
|
84
|
+
expect( @app.paramvalidator.param_names ).to eq( [ 'start_time' ] )
|
91
85
|
end
|
92
86
|
|
93
87
|
|
@@ -98,7 +92,7 @@ describe Strelka::App::Parameters do
|
|
98
92
|
end
|
99
93
|
end
|
100
94
|
|
101
|
-
@app.paramvalidator.param_names.
|
95
|
+
expect( @app.paramvalidator.param_names ).to eq( [ 'created_at' ] )
|
102
96
|
end
|
103
97
|
|
104
98
|
|
@@ -108,7 +102,7 @@ describe Strelka::App::Parameters do
|
|
108
102
|
end
|
109
103
|
subapp = Class.new( @app )
|
110
104
|
|
111
|
-
subapp.paramvalidator.param_names.
|
105
|
+
expect( subapp.paramvalidator.param_names ).to eq( [ 'username' ] )
|
112
106
|
end
|
113
107
|
|
114
108
|
describe "instance" do
|
@@ -124,20 +118,20 @@ describe Strelka::App::Parameters do
|
|
124
118
|
req = @request_factory.get( '/user/search' )
|
125
119
|
@app.new.handle( req )
|
126
120
|
|
127
|
-
req.params.
|
128
|
-
req.params.
|
129
|
-
req.params.error_messages.
|
121
|
+
expect( req.params ).to be_a( Strelka::ParamValidator )
|
122
|
+
expect( req.params ).to have_errors()
|
123
|
+
expect( req.params.error_messages ).to eq( ["Missing value for 'Username'"] )
|
130
124
|
end
|
131
125
|
|
132
126
|
it "validates parameters from the request" do
|
133
127
|
req = @request_factory.get( '/user/search?username=anheptoh'.taint )
|
134
128
|
@app.new.handle( req )
|
135
129
|
|
136
|
-
req.params.
|
137
|
-
req.params.
|
138
|
-
req.params.
|
139
|
-
req.params[:username].
|
140
|
-
req.params[:username].
|
130
|
+
expect( req.params ).to be_a( Strelka::ParamValidator )
|
131
|
+
expect( req.params ).to be_okay()
|
132
|
+
expect( req.params ).to_not have_errors()
|
133
|
+
expect( req.params[:username] ).to eq( 'anheptoh' )
|
134
|
+
expect( req.params[:username] ).to be_tainted()
|
141
135
|
end
|
142
136
|
|
143
137
|
it "untaints all parameters if global untainting is enabled" do
|
@@ -145,12 +139,12 @@ describe Strelka::App::Parameters do
|
|
145
139
|
untaint_all_constraints true
|
146
140
|
end
|
147
141
|
|
148
|
-
@app.untaint_all_constraints.
|
142
|
+
expect( @app.untaint_all_constraints ).to be_true()
|
149
143
|
req = @request_factory.get( '/user/search?username=shereshnaheth'.taint )
|
150
144
|
@app.new.handle( req )
|
151
145
|
|
152
|
-
req.params[:username].
|
153
|
-
req.params[:username].
|
146
|
+
expect( req.params[:username] ).to eq( 'shereshnaheth' )
|
147
|
+
expect( req.params[:username] ).to_not be_tainted()
|
154
148
|
end
|
155
149
|
|
156
150
|
it "untaints parameters flagged for untainting" do
|
@@ -161,8 +155,8 @@ describe Strelka::App::Parameters do
|
|
161
155
|
req = @request_factory.get( '/user/search?message=I+love+the+circus.'.taint )
|
162
156
|
@app.new.handle( req )
|
163
157
|
|
164
|
-
req.params[:message].
|
165
|
-
req.params[:message].
|
158
|
+
expect( req.params[:message] ).to_not be_tainted()
|
159
|
+
expect( req.params[:message] ).to eq( 'I love the circus.' )
|
166
160
|
end
|
167
161
|
|
168
162
|
end
|