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
@@ -1,17 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
#encoding: utf-8
|
3
3
|
|
4
|
-
|
5
|
-
require 'pathname'
|
6
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
7
|
-
$LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
|
8
|
-
}
|
4
|
+
require_relative '../helpers'
|
9
5
|
|
10
6
|
require 'date'
|
11
7
|
require 'rspec'
|
12
8
|
|
13
|
-
require 'spec/lib/helpers'
|
14
|
-
|
15
9
|
require 'strelka'
|
16
10
|
require 'strelka/paramvalidator'
|
17
11
|
|
@@ -36,8 +30,8 @@ describe Strelka::ParamValidator do
|
|
36
30
|
|
37
31
|
|
38
32
|
it "starts out empty" do
|
39
|
-
@validator.
|
40
|
-
@validator.
|
33
|
+
expect( @validator ).to be_empty()
|
34
|
+
expect( @validator ).to_not have_args()
|
41
35
|
end
|
42
36
|
|
43
37
|
it "is no longer empty if at least one set of parameters has been validated" do
|
@@ -45,8 +39,8 @@ describe Strelka::ParamValidator do
|
|
45
39
|
|
46
40
|
@validator.validate( {'foo' => "1"} )
|
47
41
|
|
48
|
-
@validator.
|
49
|
-
@validator.
|
42
|
+
expect( @validator ).to_not be_empty()
|
43
|
+
expect( @validator ).to have_args()
|
50
44
|
end
|
51
45
|
|
52
46
|
|
@@ -54,20 +48,20 @@ describe Strelka::ParamValidator do
|
|
54
48
|
|
55
49
|
it "allows constraints to be added" do
|
56
50
|
@validator.add( :a_field, :string )
|
57
|
-
@validator.param_names.
|
51
|
+
expect( @validator.param_names ).to include( 'a_field' )
|
58
52
|
end
|
59
53
|
|
60
54
|
it "revalidates parameters when new constraints are added" do
|
61
55
|
@validator.validate( 'blorp' => 'true' )
|
62
|
-
@validator[ :blorp ].
|
56
|
+
expect( @validator[ :blorp ] ).to be_nil
|
63
57
|
@validator.add( :blorp, :boolean )
|
64
|
-
@validator[ :blorp ].
|
58
|
+
expect( @validator[ :blorp ] ).to be_true
|
65
59
|
end
|
66
60
|
|
67
|
-
it "ignores identical duplicate constraints
|
61
|
+
it "ignores identical duplicate constraints" do
|
68
62
|
@validator.add( :a_field, :string )
|
69
63
|
@validator.add( :a_field, :string )
|
70
|
-
@validator.param_names.
|
64
|
+
expect( @validator.param_names ).to include( 'a_field' )
|
71
65
|
end
|
72
66
|
|
73
67
|
it "throws an error if a constraint is re-added with different values" do
|
@@ -80,18 +74,18 @@ describe Strelka::ParamValidator do
|
|
80
74
|
it "allows an existing constraint to be overridden" do
|
81
75
|
@validator.add( :a_field, :string )
|
82
76
|
@validator.override( :a_field, :integer )
|
83
|
-
@validator.param_names.
|
77
|
+
expect( @validator.param_names ).to include( 'a_field' )
|
84
78
|
@validator.validate( 'a_field' => 'a string!' )
|
85
|
-
@validator.
|
86
|
-
@validator.
|
87
|
-
@validator.error_messages.
|
79
|
+
expect( @validator ).to have_errors()
|
80
|
+
expect( @validator ).to_not be_okay()
|
81
|
+
expect( @validator.error_messages ).to include( "Invalid value for 'A Field'" )
|
88
82
|
end
|
89
83
|
|
90
84
|
it "doesn't allow a non-existant constraint to be overridden" do
|
91
85
|
expect {
|
92
86
|
@validator.override( :a_field, :string )
|
93
87
|
}.to raise_error( /no parameter "a_field" defined/i )
|
94
|
-
@validator.param_names.
|
88
|
+
expect( @validator.param_names ).to_not include( 'a_field' )
|
95
89
|
end
|
96
90
|
|
97
91
|
it "raises an exception on an unknown constraint type" do
|
@@ -104,9 +98,9 @@ describe Strelka::ParamValidator do
|
|
104
98
|
@validator.add( :foo, :string, :required )
|
105
99
|
dup = @validator.dup
|
106
100
|
@validator.validate( {} )
|
107
|
-
@validator.
|
108
|
-
@validator.
|
109
|
-
@validator.error_messages.
|
101
|
+
expect( @validator ).to_not be_okay()
|
102
|
+
expect( @validator ).to have_errors()
|
103
|
+
expect( @validator.error_messages ).to eq( ["Missing value for 'Foo'"] )
|
110
104
|
end
|
111
105
|
|
112
106
|
end # describe "profile"
|
@@ -117,33 +111,33 @@ describe Strelka::ParamValidator do
|
|
117
111
|
@validator.add( :foo, /^\d+$/ )
|
118
112
|
|
119
113
|
@validator.validate( {'foo' => "1"} )
|
120
|
-
@validator[:foo].
|
114
|
+
expect( @validator[:foo] ).to eq( "1" )
|
121
115
|
|
122
116
|
@validator[:foo] = "bar"
|
123
|
-
@validator["foo"].
|
117
|
+
expect( @validator["foo"] ).to eq( "bar" )
|
124
118
|
end
|
125
119
|
|
126
120
|
it "handles multiple values for the same parameter" do
|
127
121
|
@validator.add( :foo, /^\d+$/, :multiple )
|
128
122
|
|
129
123
|
@validator.validate( {'foo' => %w[1 2]} )
|
130
|
-
@validator[:foo].
|
124
|
+
expect( @validator[:foo] ).to eq( ['1', '2'] )
|
131
125
|
end
|
132
126
|
|
133
127
|
it "always returns an Array for parameters marked as :multiple" do
|
134
128
|
@validator.add( :foo, /^\d+$/, :multiple )
|
135
129
|
|
136
130
|
@validator.validate( {'foo' => '1'} )
|
137
|
-
@validator[:foo].
|
131
|
+
expect( @validator[:foo] ).to eq( ['1'] )
|
138
132
|
end
|
139
133
|
|
140
134
|
it "fails to validate if one of a multiple-value parameter doesn't validate" do
|
141
135
|
@validator.add( :foo, /^\d+$/, :multiple )
|
142
136
|
|
143
137
|
@validator.validate( {'foo' => %[1 victor 8]} )
|
144
|
-
@validator.
|
145
|
-
@validator.
|
146
|
-
@validator.error_messages.first.
|
138
|
+
expect( @validator ).to_not be_okay()
|
139
|
+
expect( @validator ).to have_errors()
|
140
|
+
expect( @validator.error_messages.first ).to match( /foo/i )
|
147
141
|
end
|
148
142
|
|
149
143
|
it "untaints valid args if told to do so" do
|
@@ -153,30 +147,53 @@ describe Strelka::ParamValidator do
|
|
153
147
|
@validator.add( :number, /^\d+$/, :untaint )
|
154
148
|
@validator.validate( 'number' => tainted_one )
|
155
149
|
|
156
|
-
@validator[:number].
|
157
|
-
@validator[:number].tainted
|
150
|
+
expect( @validator[:number] ).to eq( "1" )
|
151
|
+
expect( @validator[:number].tainted? ).to be_false()
|
158
152
|
end
|
159
153
|
|
160
154
|
it "knows the names of fields that were required but missing from the parameters" do
|
161
155
|
@validator.add( :id, :integer, :required )
|
162
156
|
@validator.validate( {} )
|
163
157
|
|
164
|
-
@validator.
|
165
|
-
@validator.
|
158
|
+
expect( @validator ).to have_errors()
|
159
|
+
expect( @validator ).to_not be_okay()
|
166
160
|
|
167
|
-
@validator.missing.
|
168
|
-
@validator.missing.
|
161
|
+
expect( @validator.missing ).to have(1).members
|
162
|
+
expect( @validator.missing ).to eq( ['id'] )
|
163
|
+
end
|
164
|
+
|
165
|
+
it "knows the names of fields that were required but empty" do
|
166
|
+
@validator.add( :id, :integer, :required )
|
167
|
+
@validator.validate( 'id' => '' )
|
168
|
+
|
169
|
+
expect( @validator ).to have_errors()
|
170
|
+
expect( @validator ).to_not be_okay()
|
171
|
+
|
172
|
+
expect( @validator.invalid ).to be_empty
|
173
|
+
|
174
|
+
expect( @validator.missing ).to have(1).members
|
175
|
+
expect( @validator.missing ).to eq( ['id'] )
|
169
176
|
end
|
170
177
|
|
171
178
|
it "knows the names of fields that did not meet their constraints" do
|
172
179
|
@validator.add( :number, :integer, :required )
|
173
180
|
@validator.validate( 'number' => 'rhinoceros' )
|
174
181
|
|
175
|
-
@validator.
|
176
|
-
@validator.
|
182
|
+
expect( @validator ).to have_errors()
|
183
|
+
expect( @validator ).to_not be_okay()
|
184
|
+
|
185
|
+
expect( @validator.invalid ).to have(1).keys
|
186
|
+
expect( @validator.invalid.keys ).to eq( ['number'] )
|
187
|
+
end
|
188
|
+
|
189
|
+
it "doesn't apply constraints for optional fields if the value is empty" do
|
190
|
+
@validator.add( :number, :integer, :optional )
|
191
|
+
@validator.validate( 'number' => '' )
|
192
|
+
|
193
|
+
expect( @validator ).to_not have_errors()
|
194
|
+
expect( @validator ).to be_okay()
|
177
195
|
|
178
|
-
@validator.invalid
|
179
|
-
@validator.invalid.keys.should == ['number']
|
196
|
+
expect( @validator.invalid ).to be_empty
|
180
197
|
end
|
181
198
|
|
182
199
|
it "can return a combined list of missing and invalid fields" do
|
@@ -185,43 +202,43 @@ describe Strelka::ParamValidator do
|
|
185
202
|
|
186
203
|
@validator.validate( 'number' => 'rhinoceros' )
|
187
204
|
|
188
|
-
@validator.
|
189
|
-
@validator.
|
205
|
+
expect( @validator ).to have_errors()
|
206
|
+
expect( @validator ).to_not be_okay()
|
190
207
|
|
191
|
-
@validator.error_fields.
|
192
|
-
@validator.error_fields.
|
193
|
-
@validator.error_fields.
|
208
|
+
expect( @validator.error_fields ).to have(2).members
|
209
|
+
expect( @validator.error_fields ).to include('number')
|
210
|
+
expect( @validator.error_fields ).to include('id')
|
194
211
|
end
|
195
212
|
|
196
213
|
it "allows valid parameters to be fetched en masse" do
|
197
214
|
@validator.add( :foom, /^\d+$/ )
|
198
215
|
@validator.add( :bewm, /^\d+$/ )
|
199
216
|
@validator.validate( 'foom' => "1", "bewm" => "2" )
|
200
|
-
@validator.values_at( :foom, :bewm ).
|
217
|
+
expect( @validator.values_at( :foom, :bewm ) ).to eq( [ '1', '2' ] )
|
201
218
|
end
|
202
219
|
|
203
220
|
it "re-validates if profile is modified" do
|
204
221
|
@validator.add( :a_field, :string )
|
205
222
|
@validator.validate( 'a_field' => 'a string!' )
|
206
|
-
@validator.
|
207
|
-
@validator.
|
223
|
+
expect( @validator ).to_not have_errors()
|
224
|
+
expect( @validator ).to be_okay()
|
208
225
|
|
209
226
|
@validator.override( :a_field, :integer )
|
210
|
-
@validator.
|
211
|
-
@validator.
|
212
|
-
@validator.error_messages.
|
227
|
+
expect( @validator ).to have_errors()
|
228
|
+
expect( @validator ).to_not be_okay()
|
229
|
+
expect( @validator.error_messages ).to include( "Invalid value for 'A Field'" )
|
213
230
|
end
|
214
231
|
|
215
232
|
it "re-validates if profile is modified, even with no parameters" do
|
216
233
|
@validator.add( :a_field, :string )
|
217
234
|
@validator.validate
|
218
|
-
@validator.
|
219
|
-
@validator.
|
235
|
+
expect( @validator ).to_not have_errors()
|
236
|
+
expect( @validator ).to be_okay()
|
220
237
|
|
221
238
|
@validator.override( :a_field, :string, :required )
|
222
|
-
@validator.
|
223
|
-
@validator.
|
224
|
-
@validator.error_messages.
|
239
|
+
expect( @validator ).to have_errors()
|
240
|
+
expect( @validator ).to_not be_okay()
|
241
|
+
expect( @validator.error_messages ).to include( "Missing value for 'A Field'" )
|
225
242
|
end
|
226
243
|
|
227
244
|
end # describe "validation"
|
@@ -233,9 +250,9 @@ describe Strelka::ParamValidator do
|
|
233
250
|
@validator.add( :id, /^(\w{20})$/, :required )
|
234
251
|
@validator.validate( 'number' => 'rhinoceros', 'unknown' => "1" )
|
235
252
|
|
236
|
-
@validator.error_messages.
|
237
|
-
@validator.error_messages.
|
238
|
-
@validator.error_messages.
|
253
|
+
expect( @validator.error_messages ).to have(2).members
|
254
|
+
expect( @validator.error_messages ).to include("Missing value for 'Id'")
|
255
|
+
expect( @validator.error_messages ).to include("Invalid value for 'Number'")
|
239
256
|
end
|
240
257
|
|
241
258
|
it "can include unknown fields in its human descriptions of validation errors" do
|
@@ -243,10 +260,10 @@ describe Strelka::ParamValidator do
|
|
243
260
|
@validator.add( :id, /^(\w{20})$/, :required )
|
244
261
|
@validator.validate( 'number' => 'rhinoceros', 'unknown' => "1" )
|
245
262
|
|
246
|
-
@validator.error_messages(true).
|
247
|
-
@validator.error_messages(true).
|
248
|
-
@validator.error_messages(true).
|
249
|
-
@validator.error_messages(true).
|
263
|
+
expect( @validator.error_messages(true) ).to have(3).members
|
264
|
+
expect( @validator.error_messages(true) ).to include("Missing value for 'Id'")
|
265
|
+
expect( @validator.error_messages(true) ).to include("Invalid value for 'Number'")
|
266
|
+
expect( @validator.error_messages(true) ).to include("Unknown parameter 'Unknown'")
|
250
267
|
end
|
251
268
|
|
252
269
|
it "can use descriptions of parameters when constructing human validation error messages" do
|
@@ -254,9 +271,9 @@ describe Strelka::ParamValidator do
|
|
254
271
|
@validator.add( :id, /^(\w{20})$/, "Test Name", :required )
|
255
272
|
@validator.validate( 'number' => 'rhinoceros', 'unknown' => "1" )
|
256
273
|
|
257
|
-
@validator.error_messages.
|
258
|
-
@validator.error_messages.
|
259
|
-
@validator.error_messages.
|
274
|
+
expect( @validator.error_messages ).to have(2).members
|
275
|
+
expect( @validator.error_messages ).to include("Missing value for 'Test Name'")
|
276
|
+
expect( @validator.error_messages ).to include("Invalid value for 'Numeral'")
|
260
277
|
end
|
261
278
|
|
262
279
|
it "can get and set the profile's descriptions directly" do
|
@@ -269,30 +286,30 @@ describe Strelka::ParamValidator do
|
|
269
286
|
}
|
270
287
|
@validator.validate( 'number' => 'rhinoceros', 'unknown' => "1" )
|
271
288
|
|
272
|
-
@validator.descriptions.
|
273
|
-
@validator.error_messages.
|
274
|
-
@validator.error_messages.
|
275
|
-
@validator.error_messages.
|
289
|
+
expect( @validator.descriptions ).to have( 2 ).members
|
290
|
+
expect( @validator.error_messages ).to have( 2 ).members
|
291
|
+
expect( @validator.error_messages ).to include("Missing value for 'Test Name'")
|
292
|
+
expect( @validator.error_messages ).to include("Invalid value for 'Numeral'")
|
276
293
|
end
|
277
294
|
|
278
295
|
it "capitalizes the names of simple fields for descriptions" do
|
279
296
|
@validator.add( :required, :string )
|
280
|
-
@validator.get_description( "required" ).
|
297
|
+
expect( @validator.get_description( "required" ) ).to eq( 'Required' )
|
281
298
|
end
|
282
299
|
|
283
300
|
it "splits apart underbarred field names into capitalized words for descriptions" do
|
284
301
|
@validator.add( :rodent_size, :string )
|
285
|
-
@validator.get_description( "rodent_size" ).
|
302
|
+
expect( @validator.get_description( "rodent_size" ) ).to eq( 'Rodent Size' )
|
286
303
|
end
|
287
304
|
|
288
305
|
it "uses the key for descriptions of hash fields" do
|
289
306
|
@validator.add( 'rodent[size]', :string )
|
290
|
-
@validator.get_description( "rodent[size]" ).
|
307
|
+
expect( @validator.get_description( "rodent[size]" ) ).to eq( 'Size' )
|
291
308
|
end
|
292
309
|
|
293
310
|
it "uses separate capitalized words for descriptions of hash fields with underbarred keys " do
|
294
311
|
@validator.add( 'castle[baron_id]', :string )
|
295
|
-
@validator.get_description( "castle[baron_id]" ).
|
312
|
+
expect( @validator.get_description( "castle[baron_id]" ) ).to eq( 'Baron Id' )
|
296
313
|
end
|
297
314
|
|
298
315
|
end # describe "validation error descriptions"
|
@@ -303,7 +320,7 @@ describe Strelka::ParamValidator do
|
|
303
320
|
@validator.add( 'rodent[size]', :string )
|
304
321
|
@validator.validate( 'rodent[size]' => 'unusual' )
|
305
322
|
|
306
|
-
@validator.valid.
|
323
|
+
expect( @validator.valid ).to eq( {'rodent' => {'size' => 'unusual'}} )
|
307
324
|
end
|
308
325
|
|
309
326
|
it "coalesces complex hash fields into a nested hash of validated values" do
|
@@ -318,12 +335,12 @@ describe Strelka::ParamValidator do
|
|
318
335
|
}
|
319
336
|
@validator.validate( args )
|
320
337
|
|
321
|
-
@validator.valid.
|
338
|
+
expect( @validator.valid ).to eq({
|
322
339
|
'recipe' => {
|
323
340
|
'ingredient' => { 'name' => 'nutmeg', 'cost' => '$0.18' },
|
324
341
|
'yield' => '2 loaves'
|
325
342
|
}
|
326
|
-
}
|
343
|
+
})
|
327
344
|
end
|
328
345
|
|
329
346
|
it "untaints both keys and values in complex hash fields if untainting is turned on" do
|
@@ -341,21 +358,21 @@ describe Strelka::ParamValidator do
|
|
341
358
|
}
|
342
359
|
@validator.validate( args )
|
343
360
|
|
344
|
-
@validator.valid.
|
361
|
+
expect( @validator.valid ).to eq({
|
345
362
|
'recipe' => {
|
346
363
|
'ingredient' => { 'name' => 'nutmeg', 'cost' => '$0.18', 'rarity' => 'super-rare' },
|
347
364
|
'yield' => '2 loaves'
|
348
365
|
}
|
349
|
-
}
|
350
|
-
|
351
|
-
@validator.valid.keys.
|
352
|
-
@validator.valid.values.
|
353
|
-
@validator.valid['recipe'].keys.
|
354
|
-
@validator.valid['recipe']['ingredient'].keys.
|
355
|
-
@validator.valid['recipe']['yield'].
|
356
|
-
@validator.valid['recipe']['ingredient']['rarity'].
|
357
|
-
@validator.valid['recipe']['ingredient']['name'].
|
358
|
-
@validator.valid['recipe']['ingredient']['cost'].
|
366
|
+
})
|
367
|
+
|
368
|
+
@validator.valid.keys.each {|key| expect(key).to_not be_tainted() }
|
369
|
+
@validator.valid.values.each {|key| expect(key).to_not be_tainted() }
|
370
|
+
@validator.valid['recipe'].keys.each {|key| expect(key).to_not be_tainted() }
|
371
|
+
@validator.valid['recipe']['ingredient'].keys.each {|key| expect(key).to_not be_tainted() }
|
372
|
+
expect( @validator.valid['recipe']['yield'] ).to_not be_tainted()
|
373
|
+
expect( @validator.valid['recipe']['ingredient']['rarity'] ).to_not be_tainted()
|
374
|
+
expect( @validator.valid['recipe']['ingredient']['name'] ).to_not be_tainted()
|
375
|
+
expect( @validator.valid['recipe']['ingredient']['cost'] ).to_not be_tainted()
|
359
376
|
end
|
360
377
|
|
361
378
|
end # describe "hash parameters"
|
@@ -367,15 +384,15 @@ describe Strelka::ParamValidator do
|
|
367
384
|
@validator.validate( {} )
|
368
385
|
newval = @validator.merge( 'foo' => '1' )
|
369
386
|
|
370
|
-
newval.
|
387
|
+
expect( newval ).to_not equal( @validator )
|
371
388
|
|
372
|
-
@validator.
|
373
|
-
@validator.
|
374
|
-
newval.
|
375
|
-
newval.
|
389
|
+
expect( @validator ).to_not be_okay()
|
390
|
+
expect( @validator ).to have_errors()
|
391
|
+
expect( newval ).to be_okay()
|
392
|
+
expect( newval ).to_not have_errors()
|
376
393
|
|
377
|
-
@validator[:foo].
|
378
|
-
newval[:foo].
|
394
|
+
expect( @validator[:foo] ).to eq( nil )
|
395
|
+
expect( newval[:foo] ).to eq( 1 )
|
379
396
|
end
|
380
397
|
|
381
398
|
it "can have required parameters merged into it after the initial validation" do
|
@@ -383,10 +400,10 @@ describe Strelka::ParamValidator do
|
|
383
400
|
@validator.validate( {} )
|
384
401
|
@validator.merge!( 'foo' => '1' )
|
385
402
|
|
386
|
-
@validator.
|
387
|
-
@validator.
|
403
|
+
expect( @validator ).to be_okay()
|
404
|
+
expect( @validator ).to_not have_errors()
|
388
405
|
|
389
|
-
@validator[:foo].
|
406
|
+
expect( @validator[:foo] ).to eq( 1 )
|
390
407
|
end
|
391
408
|
|
392
409
|
it "can have optional parameters merged into it after the initial validation" do
|
@@ -394,23 +411,23 @@ describe Strelka::ParamValidator do
|
|
394
411
|
@validator.validate( {} )
|
395
412
|
@validator.merge!( 'foom' => '5' )
|
396
413
|
|
397
|
-
@validator.
|
398
|
-
@validator.
|
414
|
+
expect( @validator ).to be_okay()
|
415
|
+
expect( @validator ).to_not have_errors()
|
399
416
|
|
400
|
-
@validator[:foom].
|
417
|
+
expect( @validator[:foom] ).to eq( '5' )
|
401
418
|
end
|
402
419
|
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
420
|
+
it "rejects invalid parameters when they're merged after initial validation" do
|
421
|
+
@validator.add( :foom, /^\d+$/ )
|
422
|
+
@validator.add( :bewm, /^\d+$/ )
|
423
|
+
@validator.validate( 'foom' => "1" )
|
407
424
|
|
408
|
-
|
425
|
+
@validator.merge!( 'bewm' => 'buckwheat noodles' )
|
409
426
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
427
|
+
expect( @validator ).to_not be_okay()
|
428
|
+
expect( @validator ).to have_errors()
|
429
|
+
expect( @validator[:bewm] ).to eq( nil )
|
430
|
+
end
|
414
431
|
|
415
432
|
end # describe "merging new parameters"
|
416
433
|
|
@@ -419,9 +436,9 @@ describe Strelka::ParamValidator do
|
|
419
436
|
it "treats ArgumentErrors as validation failures" do
|
420
437
|
@validator.add( :integer )
|
421
438
|
@validator.validate( 'integer' => 'jalopy' )
|
422
|
-
@validator.
|
423
|
-
@validator.
|
424
|
-
@validator[:integer].
|
439
|
+
expect( @validator ).to_not be_okay()
|
440
|
+
expect( @validator ).to have_errors()
|
441
|
+
expect( @validator[:integer] ).to be_nil()
|
425
442
|
end
|
426
443
|
|
427
444
|
describe "Regexp" do
|
@@ -429,22 +446,22 @@ describe Strelka::ParamValidator do
|
|
429
446
|
it "returns the capture if it has only one" do
|
430
447
|
@validator.add( :treename, /(\w+)/ )
|
431
448
|
@validator.validate( 'treename' => " ygdrassil " )
|
432
|
-
@validator[:treename].
|
449
|
+
expect( @validator[:treename] ).to eq( 'ygdrassil' )
|
433
450
|
end
|
434
451
|
|
435
452
|
it "returns the captures as an array if it has more than one" do
|
436
453
|
@validator.add( :stuff, /(\w+)(\S+)?/ )
|
437
454
|
@validator.validate( 'stuff' => " the1tree(!) " )
|
438
|
-
@validator[:stuff].
|
455
|
+
expect( @validator[:stuff] ).to eq( ['the1tree', '(!)'] )
|
439
456
|
end
|
440
457
|
|
441
458
|
it "returns the captures with named captures as a Hash" do
|
442
459
|
@validator.add( :order_number, /(?<category>[[:upper:]]{3})-(?<sku>\d{12})/, :untaint )
|
443
460
|
@validator.validate( 'order_number' => " JVV-886451300133 ".taint )
|
444
461
|
|
445
|
-
@validator[:order_number].
|
446
|
-
@validator[:order_number][:category].
|
447
|
-
@validator[:order_number][:sku].
|
462
|
+
expect( @validator[:order_number] ).to eq( {:category => 'JVV', :sku => '886451300133'} )
|
463
|
+
expect( @validator[:order_number][:category] ).to_not be_tainted()
|
464
|
+
expect( @validator[:order_number][:sku] ).to_not be_tainted()
|
448
465
|
end
|
449
466
|
|
450
467
|
it "returns the captures as an array " +
|
@@ -452,7 +469,7 @@ describe Strelka::ParamValidator do
|
|
452
469
|
@validator.add( :amount, /^([\-+])?(\d+(?:\.\d+)?)/ )
|
453
470
|
@validator.validate( 'amount' => '2.28' )
|
454
471
|
|
455
|
-
@validator[:amount].
|
472
|
+
expect( @validator[:amount] ).to eq( [ nil, '2.28' ] )
|
456
473
|
end
|
457
474
|
|
458
475
|
end
|
@@ -466,115 +483,115 @@ describe Strelka::ParamValidator do
|
|
466
483
|
it "accepts the value 'true'" do
|
467
484
|
@validator.validate( 'enabled' => 'true' )
|
468
485
|
|
469
|
-
@validator.
|
470
|
-
@validator.
|
486
|
+
expect( @validator ).to be_okay()
|
487
|
+
expect( @validator ).to_not have_errors()
|
471
488
|
|
472
|
-
@validator[:enabled].
|
489
|
+
expect( @validator[:enabled] ).to be_true()
|
473
490
|
end
|
474
491
|
|
475
492
|
it "accepts the value 't'" do
|
476
493
|
@validator.validate( 'enabled' => 't' )
|
477
494
|
|
478
|
-
@validator.
|
479
|
-
@validator.
|
495
|
+
expect( @validator ).to be_okay()
|
496
|
+
expect( @validator ).to_not have_errors()
|
480
497
|
|
481
|
-
@validator[:enabled].
|
498
|
+
expect( @validator[:enabled] ).to be_true()
|
482
499
|
end
|
483
500
|
|
484
501
|
it "accepts the value 'yes'" do
|
485
502
|
@validator.validate( 'enabled' => 'yes' )
|
486
503
|
|
487
|
-
@validator.
|
488
|
-
@validator.
|
504
|
+
expect( @validator ).to be_okay()
|
505
|
+
expect( @validator ).to_not have_errors()
|
489
506
|
|
490
|
-
@validator[:enabled].
|
507
|
+
expect( @validator[:enabled] ).to be_true()
|
491
508
|
end
|
492
509
|
|
493
510
|
it "accepts the value 'y'" do
|
494
511
|
@validator.validate( 'enabled' => 'y' )
|
495
512
|
|
496
|
-
@validator.
|
497
|
-
@validator.
|
513
|
+
expect( @validator ).to be_okay()
|
514
|
+
expect( @validator ).to_not have_errors()
|
498
515
|
|
499
|
-
@validator[:enabled].
|
516
|
+
expect( @validator[:enabled] ).to be_true()
|
500
517
|
end
|
501
518
|
|
502
519
|
it "accepts the value '1'" do
|
503
520
|
@validator.validate( 'enabled' => '1' )
|
504
521
|
|
505
|
-
@validator.
|
506
|
-
@validator.
|
522
|
+
expect( @validator ).to be_okay()
|
523
|
+
expect( @validator ).to_not have_errors()
|
507
524
|
|
508
|
-
@validator[:enabled].
|
525
|
+
expect( @validator[:enabled] ).to be_true()
|
509
526
|
end
|
510
527
|
|
511
528
|
it "accepts the string 'false'" do
|
512
529
|
@validator.validate( 'enabled' => 'false' )
|
513
530
|
|
514
|
-
@validator.
|
515
|
-
@validator.
|
531
|
+
expect( @validator ).to be_okay()
|
532
|
+
expect( @validator ).to_not have_errors()
|
516
533
|
|
517
|
-
@validator[:enabled].
|
534
|
+
expect( @validator[:enabled] ).to be_false()
|
518
535
|
end
|
519
536
|
|
520
537
|
it "accepts the literal false value" do
|
521
538
|
@validator.validate( 'enabled' => false )
|
522
539
|
|
523
|
-
@validator.
|
524
|
-
@validator.
|
540
|
+
expect( @validator ).to be_okay()
|
541
|
+
expect( @validator ).to_not have_errors()
|
525
542
|
|
526
|
-
@validator[:enabled].
|
543
|
+
expect( @validator[:enabled] ).to be_false()
|
527
544
|
end
|
528
545
|
|
529
546
|
it "accepts the value 'f'" do
|
530
547
|
@validator.validate( 'enabled' => 'f' )
|
531
548
|
|
532
|
-
@validator.
|
533
|
-
@validator.
|
549
|
+
expect( @validator ).to be_okay()
|
550
|
+
expect( @validator ).to_not have_errors()
|
534
551
|
|
535
|
-
@validator[:enabled].
|
552
|
+
expect( @validator[:enabled] ).to be_false()
|
536
553
|
end
|
537
554
|
|
538
555
|
it "accepts the value 'no'" do
|
539
556
|
@validator.validate( 'enabled' => 'no' )
|
540
557
|
|
541
|
-
@validator.
|
542
|
-
@validator.
|
558
|
+
expect( @validator ).to be_okay()
|
559
|
+
expect( @validator ).to_not have_errors()
|
543
560
|
|
544
|
-
@validator[:enabled].
|
561
|
+
expect( @validator[:enabled] ).to be_false()
|
545
562
|
end
|
546
563
|
|
547
564
|
it "accepts the value 'n'" do
|
548
565
|
@validator.validate( 'enabled' => 'n' )
|
549
566
|
|
550
|
-
@validator.
|
551
|
-
@validator.
|
567
|
+
expect( @validator ).to be_okay()
|
568
|
+
expect( @validator ).to_not have_errors()
|
552
569
|
|
553
|
-
@validator[:enabled].
|
570
|
+
expect( @validator[:enabled] ).to be_false()
|
554
571
|
end
|
555
572
|
|
556
573
|
it "accepts the value '0'" do
|
557
574
|
@validator.validate( 'enabled' => '0' )
|
558
575
|
|
559
|
-
@validator.
|
560
|
-
@validator.
|
576
|
+
expect( @validator ).to be_okay()
|
577
|
+
expect( @validator ).to_not have_errors()
|
561
578
|
|
562
|
-
@validator[:enabled].
|
579
|
+
expect( @validator[:enabled] ).to be_false()
|
563
580
|
end
|
564
581
|
|
565
582
|
it "rejects non-boolean parameters" do
|
566
583
|
@validator.validate( 'enabled' => 'peanut' )
|
567
584
|
|
568
|
-
@validator.
|
569
|
-
@validator.
|
585
|
+
expect( @validator ).to_not be_okay()
|
586
|
+
expect( @validator ).to have_errors()
|
570
587
|
|
571
|
-
@validator[:enabled].
|
588
|
+
expect( @validator[:enabled] ).to be_nil()
|
572
589
|
end
|
573
590
|
|
574
591
|
it "includes literal false values in the hash of valid data" do
|
575
592
|
@validator.validate( 'enabled' => false )
|
576
593
|
|
577
|
-
@validator.valid.
|
594
|
+
expect( @validator.valid ).to include( enabled: false )
|
578
595
|
end
|
579
596
|
|
580
597
|
end
|
@@ -585,60 +602,60 @@ describe Strelka::ParamValidator do
|
|
585
602
|
@validator.add( :count, :integer )
|
586
603
|
@validator.validate( 'count' => '11' )
|
587
604
|
|
588
|
-
@validator.
|
589
|
-
@validator.
|
605
|
+
expect( @validator ).to be_okay()
|
606
|
+
expect( @validator ).to_not have_errors()
|
590
607
|
|
591
|
-
@validator[:count].
|
608
|
+
expect( @validator[:count] ).to eq( 11 )
|
592
609
|
end
|
593
610
|
|
594
611
|
it "accepts '0'" do
|
595
612
|
@validator.add( :count, :integer )
|
596
613
|
@validator.validate( 'count' => '0' )
|
597
614
|
|
598
|
-
@validator.
|
599
|
-
@validator.
|
615
|
+
expect( @validator ).to be_okay()
|
616
|
+
expect( @validator ).to_not have_errors()
|
600
617
|
|
601
|
-
@validator[:count].
|
618
|
+
expect( @validator[:count] ).to eq( 0 )
|
602
619
|
end
|
603
620
|
|
604
621
|
it "accepts negative integers" do
|
605
622
|
@validator.add( :count, :integer )
|
606
623
|
@validator.validate( 'count' => '-407' )
|
607
624
|
|
608
|
-
@validator.
|
609
|
-
@validator.
|
625
|
+
expect( @validator ).to be_okay()
|
626
|
+
expect( @validator ).to_not have_errors()
|
610
627
|
|
611
|
-
@validator[:count].
|
628
|
+
expect( @validator[:count] ).to eq( -407 )
|
612
629
|
end
|
613
630
|
|
614
631
|
it "accepts literal integers" do
|
615
632
|
@validator.add( :count, :integer )
|
616
633
|
@validator.validate( 'count' => 118 )
|
617
634
|
|
618
|
-
@validator.
|
619
|
-
@validator.
|
635
|
+
expect( @validator ).to be_okay()
|
636
|
+
expect( @validator ).to_not have_errors()
|
620
637
|
|
621
|
-
@validator[:count].
|
638
|
+
expect( @validator[:count] ).to eq( 118 )
|
622
639
|
end
|
623
640
|
|
624
641
|
it "rejects non-integers" do
|
625
642
|
@validator.add( :count, :integer )
|
626
643
|
@validator.validate( 'count' => '11.1' )
|
627
644
|
|
628
|
-
@validator.
|
629
|
-
@validator.
|
645
|
+
expect( @validator ).to_not be_okay()
|
646
|
+
expect( @validator ).to have_errors()
|
630
647
|
|
631
|
-
@validator[:count].
|
648
|
+
expect( @validator[:count] ).to be_nil()
|
632
649
|
end
|
633
650
|
|
634
651
|
it "rejects integer values with other cruft in them" do
|
635
652
|
@validator.add( :count, :integer )
|
636
653
|
@validator.validate( 'count' => '88licks' )
|
637
654
|
|
638
|
-
@validator.
|
639
|
-
@validator.
|
655
|
+
expect( @validator ).to_not be_okay()
|
656
|
+
expect( @validator ).to have_errors()
|
640
657
|
|
641
|
-
@validator[:count].
|
658
|
+
expect( @validator[:count] ).to be_nil()
|
642
659
|
end
|
643
660
|
|
644
661
|
end
|
@@ -652,118 +669,118 @@ describe Strelka::ParamValidator do
|
|
652
669
|
it "accepts simple floats" do
|
653
670
|
@validator.validate( 'amount' => '3.14' )
|
654
671
|
|
655
|
-
@validator.
|
656
|
-
@validator.
|
672
|
+
expect( @validator ).to be_okay()
|
673
|
+
expect( @validator ).to_not have_errors()
|
657
674
|
|
658
|
-
@validator[:amount].
|
675
|
+
expect( @validator[:amount] ).to eq( 3.14 )
|
659
676
|
end
|
660
677
|
|
661
678
|
it "accepts negative floats" do
|
662
679
|
@validator.validate( 'amount' => '-3.14' )
|
663
680
|
|
664
|
-
@validator.
|
665
|
-
@validator.
|
681
|
+
expect( @validator ).to be_okay()
|
682
|
+
expect( @validator ).to_not have_errors()
|
666
683
|
|
667
|
-
@validator[:amount].
|
684
|
+
expect( @validator[:amount] ).to eq( -3.14 )
|
668
685
|
end
|
669
686
|
|
670
687
|
it "accepts positive floats" do
|
671
688
|
@validator.validate( 'amount' => '+3.14' )
|
672
689
|
|
673
|
-
@validator.
|
674
|
-
@validator.
|
690
|
+
expect( @validator ).to be_okay()
|
691
|
+
expect( @validator ).to_not have_errors()
|
675
692
|
|
676
|
-
@validator[:amount].
|
693
|
+
expect( @validator[:amount] ).to eq( 3.14 )
|
677
694
|
end
|
678
695
|
|
679
696
|
it "accepts floats that begin with '.'" do
|
680
697
|
@validator.validate( 'amount' => '.1418' )
|
681
698
|
|
682
|
-
@validator.
|
683
|
-
@validator.
|
699
|
+
expect( @validator ).to be_okay()
|
700
|
+
expect( @validator ).to_not have_errors()
|
684
701
|
|
685
|
-
@validator[:amount].
|
702
|
+
expect( @validator[:amount] ).to eq( 0.1418 )
|
686
703
|
end
|
687
704
|
|
688
705
|
it "accepts negative floats that begin with '.'" do
|
689
706
|
@validator.validate( 'amount' => '-.171' )
|
690
707
|
|
691
|
-
@validator.
|
692
|
-
@validator.
|
708
|
+
expect( @validator ).to be_okay()
|
709
|
+
expect( @validator ).to_not have_errors()
|
693
710
|
|
694
|
-
@validator[:amount].
|
711
|
+
expect( @validator[:amount] ).to eq( -0.171 )
|
695
712
|
end
|
696
713
|
|
697
714
|
it "accepts positive floats that begin with '.'" do
|
698
715
|
@validator.validate( 'amount' => '+.86668001' )
|
699
716
|
|
700
|
-
@validator.
|
701
|
-
@validator.
|
717
|
+
expect( @validator ).to be_okay()
|
718
|
+
expect( @validator ).to_not have_errors()
|
702
719
|
|
703
|
-
@validator[:amount].
|
720
|
+
expect( @validator[:amount] ).to eq( 0.86668001 )
|
704
721
|
end
|
705
722
|
|
706
723
|
it "accepts floats in exponential notation" do
|
707
724
|
@validator.validate( 'amount' => '1756e-5' )
|
708
725
|
|
709
|
-
@validator.
|
710
|
-
@validator.
|
726
|
+
expect( @validator ).to be_okay()
|
727
|
+
expect( @validator ).to_not have_errors()
|
711
728
|
|
712
|
-
@validator[:amount].
|
729
|
+
expect( @validator[:amount] ).to eq( 1756e-5 )
|
713
730
|
end
|
714
731
|
|
715
732
|
it "accepts negative floats in exponential notation" do
|
716
733
|
@validator.validate( 'amount' => '-28e8' )
|
717
734
|
|
718
|
-
@validator.
|
719
|
-
@validator.
|
735
|
+
expect( @validator ).to be_okay()
|
736
|
+
expect( @validator ).to_not have_errors()
|
720
737
|
|
721
|
-
@validator[:amount].
|
738
|
+
expect( @validator[:amount] ).to eq( -28e8 )
|
722
739
|
end
|
723
740
|
|
724
741
|
it "accepts floats that start with '.' in exponential notation" do
|
725
742
|
@validator.validate( 'amount' => '.5552e-10' )
|
726
743
|
|
727
|
-
@validator.
|
728
|
-
@validator.
|
744
|
+
expect( @validator ).to be_okay()
|
745
|
+
expect( @validator ).to_not have_errors()
|
729
746
|
|
730
|
-
@validator[:amount].
|
747
|
+
expect( @validator[:amount] ).to eq( 0.5552e-10 )
|
731
748
|
end
|
732
749
|
|
733
750
|
it "accepts negative floats that start with '.' in exponential notation" do
|
734
751
|
@validator.validate( 'amount' => '-.288088e18' )
|
735
752
|
|
736
|
-
|
737
|
-
|
753
|
+
expect( @validator ).to be_okay()
|
754
|
+
expect( @validator ).to_not have_errors()
|
738
755
|
|
739
|
-
|
756
|
+
expect( @validator[:amount] ).to eq( -0.288088e18 )
|
740
757
|
end
|
741
758
|
|
742
759
|
it "accepts integers" do
|
743
760
|
@validator.validate( 'amount' => '288' )
|
744
761
|
|
745
|
-
@validator.
|
746
|
-
@validator.
|
762
|
+
expect( @validator ).to be_okay()
|
763
|
+
expect( @validator ).to_not have_errors()
|
747
764
|
|
748
|
-
@validator[:amount].
|
765
|
+
expect( @validator[:amount] ).to eq( 288.0 )
|
749
766
|
end
|
750
767
|
|
751
768
|
it "accepts negative integers" do
|
752
769
|
@validator.validate( 'amount' => '-1606' )
|
753
770
|
|
754
|
-
@validator.
|
755
|
-
@validator.
|
771
|
+
expect( @validator ).to be_okay()
|
772
|
+
expect( @validator ).to_not have_errors()
|
756
773
|
|
757
|
-
@validator[:amount].
|
774
|
+
expect( @validator[:amount] ).to eq( -1606.0 )
|
758
775
|
end
|
759
776
|
|
760
777
|
it "accepts positive integers" do
|
761
778
|
@validator.validate( 'amount' => '2600' )
|
762
779
|
|
763
|
-
@validator.
|
764
|
-
@validator.
|
780
|
+
expect( @validator ).to be_okay()
|
781
|
+
expect( @validator ).to_not have_errors()
|
765
782
|
|
766
|
-
@validator[:amount].
|
783
|
+
expect( @validator[:amount] ).to eq( 2600.0 )
|
767
784
|
end
|
768
785
|
|
769
786
|
end
|
@@ -777,19 +794,19 @@ describe Strelka::ParamValidator do
|
|
777
794
|
it "accepts dates" do
|
778
795
|
@validator.validate( 'expires' => '2008-11-18' )
|
779
796
|
|
780
|
-
@validator.
|
781
|
-
@validator.
|
797
|
+
expect( @validator ).to be_okay()
|
798
|
+
expect( @validator ).to_not have_errors()
|
782
799
|
|
783
|
-
@validator[:expires].
|
800
|
+
expect( @validator[:expires] ).to eq( Date.parse( '2008-11-18' ) )
|
784
801
|
end
|
785
802
|
|
786
803
|
it "rejects non-dates" do
|
787
804
|
@validator.validate( 'expires' => 'Mexico' )
|
788
805
|
|
789
|
-
@validator.
|
790
|
-
@validator.
|
806
|
+
expect( @validator ).to_not be_okay()
|
807
|
+
expect( @validator ).to have_errors()
|
791
808
|
|
792
|
-
@validator[:expires].
|
809
|
+
expect( @validator[:expires] ).to be_nil()
|
793
810
|
end
|
794
811
|
|
795
812
|
end
|
@@ -803,28 +820,28 @@ describe Strelka::ParamValidator do
|
|
803
820
|
it "accepts dates" do
|
804
821
|
@validator.validate( 'expires' => '2008-11-18' )
|
805
822
|
|
806
|
-
@validator.
|
807
|
-
@validator.
|
823
|
+
expect( @validator ).to be_okay()
|
824
|
+
expect( @validator ).to_not have_errors()
|
808
825
|
|
809
|
-
@validator[:expires].
|
826
|
+
expect( @validator[:expires] ).to eq( Time.parse( '2008-11-18' ) )
|
810
827
|
end
|
811
828
|
|
812
829
|
it "accepts a date with a time" do
|
813
830
|
@validator.validate( 'expires' => '2008-11-18T12:31:18.818Z' )
|
814
831
|
|
815
|
-
@validator.
|
816
|
-
@validator.
|
832
|
+
expect( @validator ).to be_okay()
|
833
|
+
expect( @validator ).to_not have_errors()
|
817
834
|
|
818
|
-
@validator[:expires].
|
835
|
+
expect( @validator[:expires] ).to eq( Time.parse( '2008-11-18T12:31:18.818Z' ) )
|
819
836
|
end
|
820
837
|
|
821
838
|
it "rejects non-dates" do
|
822
839
|
@validator.validate( 'expires' => 'someday' )
|
823
840
|
|
824
|
-
@validator.
|
825
|
-
@validator.
|
841
|
+
expect( @validator ).to_not be_okay()
|
842
|
+
expect( @validator ).to have_errors()
|
826
843
|
|
827
|
-
@validator[:expires].
|
844
|
+
expect( @validator[:expires] ).to be_nil()
|
828
845
|
end
|
829
846
|
|
830
847
|
end
|
@@ -899,11 +916,11 @@ describe Strelka::ParamValidator do
|
|
899
916
|
it "accepts #{uri_string}" do
|
900
917
|
@validator.validate( 'homepage' => uri_string )
|
901
918
|
|
902
|
-
@validator.
|
903
|
-
@validator.
|
919
|
+
expect( @validator ).to be_okay()
|
920
|
+
expect( @validator ).to_not have_errors()
|
904
921
|
|
905
|
-
@validator[:homepage].
|
906
|
-
@validator[:homepage].to_s.
|
922
|
+
expect( @validator[:homepage] ).to be_a_kind_of( URI::Generic )
|
923
|
+
expect( @validator[:homepage].to_s ).to eq( uri_string )
|
907
924
|
end
|
908
925
|
end
|
909
926
|
|
@@ -911,10 +928,10 @@ describe Strelka::ParamValidator do
|
|
911
928
|
it "rejects #{uri_string}" do
|
912
929
|
@validator.validate( 'homepage' => uri_string )
|
913
930
|
|
914
|
-
@validator.
|
915
|
-
@validator.
|
931
|
+
expect( @validator ).to_not be_okay()
|
932
|
+
expect( @validator ).to have_errors()
|
916
933
|
|
917
|
-
@validator[:homepage].
|
934
|
+
expect( @validator[:homepage] ).to be_nil()
|
918
935
|
end
|
919
936
|
end
|
920
937
|
|
@@ -940,20 +957,20 @@ describe Strelka::ParamValidator do
|
|
940
957
|
@validator.add( :email )
|
941
958
|
@validator.validate( 'email' => 'jrandom@hacker.ie' )
|
942
959
|
|
943
|
-
@validator.
|
944
|
-
@validator.
|
960
|
+
expect( @validator ).to be_okay()
|
961
|
+
expect( @validator ).to_not have_errors()
|
945
962
|
|
946
|
-
@validator[:email].
|
963
|
+
expect( @validator[:email] ).to eq( 'jrandom@hacker.ie' )
|
947
964
|
end
|
948
965
|
|
949
966
|
it "accepts hyphenated domains in RFC822 addresses" do
|
950
967
|
@validator.add( :email )
|
951
968
|
@validator.validate( 'email' => 'jrandom@just-another-hacquer.fr' )
|
952
969
|
|
953
|
-
@validator.
|
954
|
-
@validator.
|
970
|
+
expect( @validator ).to be_okay()
|
971
|
+
expect( @validator ).to_not have_errors()
|
955
972
|
|
956
|
-
@validator[:email].
|
973
|
+
expect( @validator[:email] ).to eq( 'jrandom@just-another-hacquer.fr' )
|
957
974
|
end
|
958
975
|
|
959
976
|
COMPLEX_ADDRESSES.each do |addy|
|
@@ -961,10 +978,10 @@ describe Strelka::ParamValidator do
|
|
961
978
|
@validator.add( :mail, :email )
|
962
979
|
@validator.validate( 'mail' => addy )
|
963
980
|
|
964
|
-
@validator.
|
965
|
-
@validator.
|
981
|
+
expect( @validator ).to be_okay()
|
982
|
+
expect( @validator ).to_not have_errors()
|
966
983
|
|
967
|
-
@validator[:mail].
|
984
|
+
expect( @validator[:mail] ).to eq( addy )
|
968
985
|
end
|
969
986
|
end
|
970
987
|
|
@@ -973,10 +990,10 @@ describe Strelka::ParamValidator do
|
|
973
990
|
@validator.add( :mail, :email )
|
974
991
|
@validator.validate( 'mail' => addy )
|
975
992
|
|
976
|
-
@validator.
|
977
|
-
@validator.
|
993
|
+
expect( @validator ).to_not be_okay()
|
994
|
+
expect( @validator ).to have_errors()
|
978
995
|
|
979
|
-
@validator[:mail].
|
996
|
+
expect( @validator[:mail] ).to be_nil()
|
980
997
|
end
|
981
998
|
end
|
982
999
|
|
@@ -996,20 +1013,20 @@ describe Strelka::ParamValidator do
|
|
996
1013
|
@validator.add( :host, :hostname )
|
997
1014
|
@validator.validate( 'host' => 'deveiate.org' )
|
998
1015
|
|
999
|
-
@validator.
|
1000
|
-
@validator.
|
1016
|
+
expect( @validator ).to be_okay()
|
1017
|
+
expect( @validator ).to_not have_errors()
|
1001
1018
|
|
1002
|
-
@validator[:host].
|
1019
|
+
expect( @validator[:host] ).to eq( 'deveiate.org' )
|
1003
1020
|
end
|
1004
1021
|
|
1005
1022
|
it "accepts hyphenated hostnames" do
|
1006
1023
|
@validator.add( :hostname )
|
1007
1024
|
@validator.validate( 'hostname' => 'your-characters-can-fly.kr' )
|
1008
1025
|
|
1009
|
-
@validator.
|
1010
|
-
@validator.
|
1026
|
+
expect( @validator ).to be_okay()
|
1027
|
+
expect( @validator ).to_not have_errors()
|
1011
1028
|
|
1012
|
-
@validator[:hostname].
|
1029
|
+
expect( @validator[:hostname] ).to eq( 'your-characters-can-fly.kr' )
|
1013
1030
|
end
|
1014
1031
|
|
1015
1032
|
BOGUS_HOSTS.each do |hostname|
|
@@ -1017,10 +1034,10 @@ describe Strelka::ParamValidator do
|
|
1017
1034
|
@validator.add( :hostname )
|
1018
1035
|
@validator.validate( 'hostname' => hostname )
|
1019
1036
|
|
1020
|
-
@validator.
|
1021
|
-
@validator.
|
1037
|
+
expect( @validator ).to_not be_okay()
|
1038
|
+
expect( @validator ).to have_errors()
|
1022
1039
|
|
1023
|
-
@validator[:hostname].
|
1040
|
+
expect( @validator[:hostname] ).to be_nil()
|
1024
1041
|
end
|
1025
1042
|
end
|
1026
1043
|
|
@@ -1032,20 +1049,20 @@ describe Strelka::ParamValidator do
|
|
1032
1049
|
@validator.add( :alpha )
|
1033
1050
|
@validator.validate( 'alpha' => 'abelincoln' )
|
1034
1051
|
|
1035
|
-
@validator.
|
1036
|
-
@validator.
|
1052
|
+
expect( @validator ).to be_okay()
|
1053
|
+
expect( @validator ).to_not have_errors()
|
1037
1054
|
|
1038
|
-
@validator[:alpha].
|
1055
|
+
expect( @validator[:alpha] ).to eq( 'abelincoln' )
|
1039
1056
|
end
|
1040
1057
|
|
1041
1058
|
it "rejects non-alpha characters" do
|
1042
1059
|
@validator.add( :alpha )
|
1043
1060
|
@validator.validate( 'alpha' => 'duck45' )
|
1044
1061
|
|
1045
|
-
@validator.
|
1046
|
-
@validator.
|
1062
|
+
expect( @validator ).to_not be_okay()
|
1063
|
+
expect( @validator ).to have_errors()
|
1047
1064
|
|
1048
|
-
@validator[:alpha].
|
1065
|
+
expect( @validator[:alpha] ).to be_nil()
|
1049
1066
|
end
|
1050
1067
|
|
1051
1068
|
end
|
@@ -1056,20 +1073,20 @@ describe Strelka::ParamValidator do
|
|
1056
1073
|
@validator.add( :uuid )
|
1057
1074
|
@validator.validate( 'uuid' => '21BEBFCD-d222-4c40-831e-26730dc9531f' )
|
1058
1075
|
|
1059
|
-
@validator.
|
1060
|
-
@validator.
|
1076
|
+
expect( @validator ).to be_okay()
|
1077
|
+
expect( @validator ).to_not have_errors()
|
1061
1078
|
|
1062
|
-
@validator[:uuid].
|
1079
|
+
expect( @validator[:uuid] ).to eq( '21BEBFCD-d222-4c40-831e-26730dc9531f' )
|
1063
1080
|
end
|
1064
1081
|
|
1065
1082
|
it "rejects invalid UUIDs" do
|
1066
1083
|
@validator.add( :uuid )
|
1067
1084
|
@validator.validate( 'uuid' => '21bebfcd-d222-4c40-g31e-26730dc9531f' )
|
1068
1085
|
|
1069
|
-
@validator.
|
1070
|
-
@validator.
|
1086
|
+
expect( @validator ).to_not be_okay()
|
1087
|
+
expect( @validator ).to have_errors()
|
1071
1088
|
|
1072
|
-
@validator[:uuid].
|
1089
|
+
expect( @validator[:uuid] ).to be_nil()
|
1073
1090
|
end
|
1074
1091
|
|
1075
1092
|
end
|
@@ -1080,20 +1097,20 @@ describe Strelka::ParamValidator do
|
|
1080
1097
|
@validator.add( :username, :alphanumeric )
|
1081
1098
|
@validator.validate( 'username' => 'zombieabe11' )
|
1082
1099
|
|
1083
|
-
@validator.
|
1084
|
-
@validator.
|
1100
|
+
expect( @validator ).to be_okay()
|
1101
|
+
expect( @validator ).to_not have_errors()
|
1085
1102
|
|
1086
|
-
@validator[:username].
|
1103
|
+
expect( @validator[:username] ).to eq( 'zombieabe11' )
|
1087
1104
|
end
|
1088
1105
|
|
1089
1106
|
it "rejects non-alphanumeric characters" do
|
1090
1107
|
@validator.add( :username, :alphanumeric )
|
1091
1108
|
@validator.validate( 'username' => 'duck!ling' )
|
1092
1109
|
|
1093
|
-
@validator.
|
1094
|
-
@validator.
|
1110
|
+
expect( @validator ).to_not be_okay()
|
1111
|
+
expect( @validator ).to have_errors()
|
1095
1112
|
|
1096
|
-
@validator[:username].
|
1113
|
+
expect( @validator[:username] ).to be_nil()
|
1097
1114
|
end
|
1098
1115
|
|
1099
1116
|
end
|
@@ -1110,18 +1127,18 @@ describe Strelka::ParamValidator do
|
|
1110
1127
|
@validator.add( :prologue, :printable )
|
1111
1128
|
@validator.validate( 'prologue' => test_content )
|
1112
1129
|
|
1113
|
-
@validator.
|
1114
|
-
@validator[:prologue].
|
1130
|
+
expect( @validator ).to be_okay()
|
1131
|
+
expect( @validator[:prologue] ).to eq( test_content )
|
1115
1132
|
end
|
1116
1133
|
|
1117
1134
|
it "rejects non-printable characters" do
|
1118
1135
|
@validator.add( :prologue, :printable )
|
1119
1136
|
@validator.validate( 'prologue' => %{\0Something cold\0} )
|
1120
1137
|
|
1121
|
-
@validator.
|
1122
|
-
@validator.
|
1138
|
+
expect( @validator ).to_not be_okay()
|
1139
|
+
expect( @validator ).to have_errors()
|
1123
1140
|
|
1124
|
-
@validator[:prologue].
|
1141
|
+
expect( @validator[:prologue] ).to be_nil()
|
1125
1142
|
end
|
1126
1143
|
|
1127
1144
|
end
|
@@ -1132,20 +1149,20 @@ describe Strelka::ParamValidator do
|
|
1132
1149
|
@validator.add( :vocab_word, :word )
|
1133
1150
|
@validator.validate( 'vocab_word' => "Собака" )
|
1134
1151
|
|
1135
|
-
@validator.
|
1136
|
-
@validator.
|
1152
|
+
expect( @validator ).to_not have_errors()
|
1153
|
+
expect( @validator ).to be_okay()
|
1137
1154
|
|
1138
|
-
@validator[:vocab_word].
|
1155
|
+
expect( @validator[:vocab_word] ).to eq( "Собака" )
|
1139
1156
|
end
|
1140
1157
|
|
1141
1158
|
it "rejects non-word characters" do
|
1142
1159
|
@validator.add( :vocab_word, :word )
|
1143
1160
|
@validator.validate( 'vocab_word' => "Собака!" )
|
1144
1161
|
|
1145
|
-
@validator.
|
1146
|
-
@validator.
|
1162
|
+
expect( @validator ).to have_errors()
|
1163
|
+
expect( @validator ).to_not be_okay()
|
1147
1164
|
|
1148
|
-
@validator[:vocab_word].
|
1165
|
+
expect( @validator[:vocab_word] ).to be_nil()
|
1149
1166
|
end
|
1150
1167
|
|
1151
1168
|
end
|
@@ -1160,10 +1177,10 @@ describe Strelka::ParamValidator do
|
|
1160
1177
|
end
|
1161
1178
|
@validator.validate( 'creation_date' => test_date )
|
1162
1179
|
|
1163
|
-
@validator.
|
1164
|
-
@validator.
|
1180
|
+
expect( @validator ).to be_okay()
|
1181
|
+
expect( @validator ).to_not have_errors()
|
1165
1182
|
|
1166
|
-
@validator[:creation_date].
|
1183
|
+
expect( @validator[:creation_date] ).to eq( Date.parse( test_date ) )
|
1167
1184
|
end
|
1168
1185
|
|
1169
1186
|
it "rejects parameters if the Proc returns a false value" do
|
@@ -1172,10 +1189,10 @@ describe Strelka::ParamValidator do
|
|
1172
1189
|
end
|
1173
1190
|
@validator.validate( 'creation_date' => '::::' )
|
1174
1191
|
|
1175
|
-
@validator.
|
1176
|
-
@validator.
|
1192
|
+
expect( @validator ).to_not be_okay()
|
1193
|
+
expect( @validator ).to have_errors()
|
1177
1194
|
|
1178
|
-
@validator[:creation_date].
|
1195
|
+
expect( @validator[:creation_date] ).to be_nil()
|
1179
1196
|
end
|
1180
1197
|
|
1181
1198
|
end
|
@@ -1191,8 +1208,8 @@ describe Strelka::ParamValidator do
|
|
1191
1208
|
@validator.add( :object, :json )
|
1192
1209
|
@validator.validate( 'object' => json )
|
1193
1210
|
|
1194
|
-
@validator.
|
1195
|
-
@validator[:object].
|
1211
|
+
expect( @validator ).to be_okay()
|
1212
|
+
expect( @validator[:object] ).to eq( json )
|
1196
1213
|
end
|
1197
1214
|
|
1198
1215
|
it "accepts a simple object string value" do
|
@@ -1200,8 +1217,8 @@ describe Strelka::ParamValidator do
|
|
1200
1217
|
@validator.add( :object, :json )
|
1201
1218
|
@validator.validate( 'object' => json )
|
1202
1219
|
|
1203
|
-
@validator.
|
1204
|
-
@validator[:object].
|
1220
|
+
expect( @validator ).to be_okay()
|
1221
|
+
expect( @validator[:object] ).to eq( json )
|
1205
1222
|
end
|
1206
1223
|
|
1207
1224
|
it "accepts whitespace in a value" do
|
@@ -1209,8 +1226,8 @@ describe Strelka::ParamValidator do
|
|
1209
1226
|
@validator.add( :object, :json )
|
1210
1227
|
@validator.validate( 'object' => json )
|
1211
1228
|
|
1212
|
-
@validator.
|
1213
|
-
@validator[:object].
|
1229
|
+
expect( @validator ).to be_okay()
|
1230
|
+
expect( @validator[:object] ).to eq( json )
|
1214
1231
|
end
|
1215
1232
|
|
1216
1233
|
it "accepts a simple object integer value" do
|
@@ -1218,8 +1235,8 @@ describe Strelka::ParamValidator do
|
|
1218
1235
|
@validator.add( :object, :json )
|
1219
1236
|
@validator.validate( 'object' => json )
|
1220
1237
|
|
1221
|
-
@validator.
|
1222
|
-
@validator[:object].
|
1238
|
+
expect( @validator ).to be_okay()
|
1239
|
+
expect( @validator[:object] ).to eq( json )
|
1223
1240
|
end
|
1224
1241
|
|
1225
1242
|
it "accepts a single quote in a string value" do
|
@@ -1227,8 +1244,8 @@ describe Strelka::ParamValidator do
|
|
1227
1244
|
@validator.add( :object, :json )
|
1228
1245
|
@validator.validate( 'object' => json )
|
1229
1246
|
|
1230
|
-
@validator.
|
1231
|
-
@validator[:object].
|
1247
|
+
expect( @validator ).to be_okay()
|
1248
|
+
expect( @validator[:object] ).to eq( json )
|
1232
1249
|
end
|
1233
1250
|
|
1234
1251
|
it "accepts a exponented float value" do
|
@@ -1236,8 +1253,8 @@ describe Strelka::ParamValidator do
|
|
1236
1253
|
@validator.add( :object, :json )
|
1237
1254
|
@validator.validate( 'object' => json )
|
1238
1255
|
|
1239
|
-
@validator.
|
1240
|
-
@validator[:object].
|
1256
|
+
expect( @validator ).to be_okay()
|
1257
|
+
expect( @validator[:object] ).to eq( json )
|
1241
1258
|
end
|
1242
1259
|
|
1243
1260
|
it "accepts a lowercase exponented value" do
|
@@ -1245,8 +1262,8 @@ describe Strelka::ParamValidator do
|
|
1245
1262
|
@validator.add( :object, :json )
|
1246
1263
|
@validator.validate( 'object' => json )
|
1247
1264
|
|
1248
|
-
@validator.
|
1249
|
-
@validator[:object].
|
1265
|
+
expect( @validator ).to be_okay()
|
1266
|
+
expect( @validator[:object] ).to eq( json )
|
1250
1267
|
end
|
1251
1268
|
|
1252
1269
|
it "accepts a long number value" do
|
@@ -1254,8 +1271,8 @@ describe Strelka::ParamValidator do
|
|
1254
1271
|
@validator.add( :object, :json )
|
1255
1272
|
@validator.validate( 'object' => json )
|
1256
1273
|
|
1257
|
-
@validator.
|
1258
|
-
@validator[:object].
|
1274
|
+
expect( @validator ).to be_okay()
|
1275
|
+
expect( @validator[:object] ).to eq( json )
|
1259
1276
|
end
|
1260
1277
|
|
1261
1278
|
it "accepts a Bigint value" do
|
@@ -1263,8 +1280,8 @@ describe Strelka::ParamValidator do
|
|
1263
1280
|
@validator.add( :object, :json )
|
1264
1281
|
@validator.validate( 'object' => json )
|
1265
1282
|
|
1266
|
-
@validator.
|
1267
|
-
@validator[:object].
|
1283
|
+
expect( @validator ).to be_okay()
|
1284
|
+
expect( @validator[:object] ).to eq( json )
|
1268
1285
|
end
|
1269
1286
|
|
1270
1287
|
it "accepts a simple digit array value" do
|
@@ -1272,8 +1289,8 @@ describe Strelka::ParamValidator do
|
|
1272
1289
|
@validator.add( :object, :json )
|
1273
1290
|
@validator.validate( 'object' => json )
|
1274
1291
|
|
1275
|
-
@validator.
|
1276
|
-
@validator[:object].
|
1292
|
+
expect( @validator ).to be_okay()
|
1293
|
+
expect( @validator[:object] ).to eq( json )
|
1277
1294
|
end
|
1278
1295
|
|
1279
1296
|
it "accepts a simple string array value" do
|
@@ -1281,8 +1298,8 @@ describe Strelka::ParamValidator do
|
|
1281
1298
|
@validator.add( :object, :json )
|
1282
1299
|
@validator.validate( 'object' => json )
|
1283
1300
|
|
1284
|
-
@validator.
|
1285
|
-
@validator[:object].
|
1301
|
+
expect( @validator ).to be_okay()
|
1302
|
+
expect( @validator[:object] ).to eq( json )
|
1286
1303
|
end
|
1287
1304
|
|
1288
1305
|
it "accepts an array of empty values" do
|
@@ -1290,8 +1307,8 @@ describe Strelka::ParamValidator do
|
|
1290
1307
|
@validator.add( :object, :json )
|
1291
1308
|
@validator.validate( 'object' => json )
|
1292
1309
|
|
1293
|
-
@validator.
|
1294
|
-
@validator[:object].
|
1310
|
+
expect( @validator ).to be_okay()
|
1311
|
+
expect( @validator[:object] ).to eq( json )
|
1295
1312
|
end
|
1296
1313
|
|
1297
1314
|
it "accepts lowercase Unicode text values" do
|
@@ -1299,8 +1316,8 @@ describe Strelka::ParamValidator do
|
|
1299
1316
|
@validator.add( :object, :json )
|
1300
1317
|
@validator.validate( 'object' => json )
|
1301
1318
|
|
1302
|
-
@validator.
|
1303
|
-
@validator[:object].
|
1319
|
+
expect( @validator ).to be_okay()
|
1320
|
+
expect( @validator[:object] ).to eq( json )
|
1304
1321
|
end
|
1305
1322
|
|
1306
1323
|
it "accepts a uppercase Unicode value" do
|
@@ -1308,8 +1325,8 @@ describe Strelka::ParamValidator do
|
|
1308
1325
|
@validator.add( :object, :json )
|
1309
1326
|
@validator.validate( 'object' => json )
|
1310
1327
|
|
1311
|
-
@validator.
|
1312
|
-
@validator[:object].
|
1328
|
+
expect( @validator ).to be_okay()
|
1329
|
+
expect( @validator[:object] ).to eq( json )
|
1313
1330
|
end
|
1314
1331
|
|
1315
1332
|
it "accepts an escaped backslash value" do
|
@@ -1317,8 +1334,8 @@ describe Strelka::ParamValidator do
|
|
1317
1334
|
@validator.add( :object, :json )
|
1318
1335
|
@validator.validate( 'object' => json )
|
1319
1336
|
|
1320
|
-
@validator.
|
1321
|
-
@validator[:object].
|
1337
|
+
expect( @validator ).to be_okay()
|
1338
|
+
expect( @validator[:object] ).to eq( json )
|
1322
1339
|
end
|
1323
1340
|
|
1324
1341
|
it "accepts null values" do
|
@@ -1326,8 +1343,8 @@ describe Strelka::ParamValidator do
|
|
1326
1343
|
@validator.add( :object, :json )
|
1327
1344
|
@validator.validate( 'object' => json )
|
1328
1345
|
|
1329
|
-
@validator.
|
1330
|
-
@validator[:object].
|
1346
|
+
expect( @validator ).to be_okay()
|
1347
|
+
expect( @validator[:object] ).to eq( json )
|
1331
1348
|
end
|
1332
1349
|
|
1333
1350
|
it "accepts a boolean true value" do
|
@@ -1335,8 +1352,8 @@ describe Strelka::ParamValidator do
|
|
1335
1352
|
@validator.add( :object, :json )
|
1336
1353
|
@validator.validate( 'object' => json )
|
1337
1354
|
|
1338
|
-
@validator.
|
1339
|
-
@validator[:object].
|
1355
|
+
expect( @validator ).to be_okay()
|
1356
|
+
expect( @validator[:object] ).to eq( json )
|
1340
1357
|
end
|
1341
1358
|
|
1342
1359
|
it "accepts a boolean value with whitespace" do
|
@@ -1344,8 +1361,8 @@ describe Strelka::ParamValidator do
|
|
1344
1361
|
@validator.add( :object, :json )
|
1345
1362
|
@validator.validate( 'object' => json )
|
1346
1363
|
|
1347
|
-
@validator.
|
1348
|
-
@validator[:object].
|
1364
|
+
expect( @validator ).to be_okay()
|
1365
|
+
expect( @validator[:object] ).to eq( json )
|
1349
1366
|
end
|
1350
1367
|
|
1351
1368
|
it "accepts a double-precision floating value" do
|
@@ -1353,8 +1370,8 @@ describe Strelka::ParamValidator do
|
|
1353
1370
|
@validator.add( :object, :json )
|
1354
1371
|
@validator.validate( 'object' => json )
|
1355
1372
|
|
1356
|
-
@validator.
|
1357
|
-
@validator[:object].
|
1373
|
+
expect( @validator ).to be_okay()
|
1374
|
+
expect( @validator[:object] ).to eq( json )
|
1358
1375
|
end
|
1359
1376
|
|
1360
1377
|
|
@@ -1364,10 +1381,10 @@ describe Strelka::ParamValidator do
|
|
1364
1381
|
@validator.add( :object, :json )
|
1365
1382
|
@validator.validate( 'object' => json )
|
1366
1383
|
|
1367
|
-
@validator.
|
1368
|
-
@validator.
|
1384
|
+
expect( @validator ).to_not be_okay()
|
1385
|
+
expect( @validator ).to have_errors()
|
1369
1386
|
|
1370
|
-
@validator[:object].
|
1387
|
+
expect( @validator[:object] ).to be_nil()
|
1371
1388
|
end
|
1372
1389
|
|
1373
1390
|
it "rejects a truncated Object value" do
|
@@ -1375,10 +1392,10 @@ describe Strelka::ParamValidator do
|
|
1375
1392
|
@validator.add( :object, :json )
|
1376
1393
|
@validator.validate( 'object' => json )
|
1377
1394
|
|
1378
|
-
@validator.
|
1379
|
-
@validator.
|
1395
|
+
expect( @validator ).to_not be_okay()
|
1396
|
+
expect( @validator ).to have_errors()
|
1380
1397
|
|
1381
|
-
@validator[:object].
|
1398
|
+
expect( @validator[:object] ).to be_nil()
|
1382
1399
|
end
|
1383
1400
|
|
1384
1401
|
it "rejects a truncated String value" do
|
@@ -1386,10 +1403,10 @@ describe Strelka::ParamValidator do
|
|
1386
1403
|
@validator.add( :object, :json )
|
1387
1404
|
@validator.validate( 'object' => json )
|
1388
1405
|
|
1389
|
-
@validator.
|
1390
|
-
@validator.
|
1406
|
+
expect( @validator ).to_not be_okay()
|
1407
|
+
expect( @validator ).to have_errors()
|
1391
1408
|
|
1392
|
-
@validator[:object].
|
1409
|
+
expect( @validator[:object] ).to be_nil()
|
1393
1410
|
end
|
1394
1411
|
|
1395
1412
|
it "rejects unescaped control characters in a String value" do
|
@@ -1397,10 +1414,10 @@ describe Strelka::ParamValidator do
|
|
1397
1414
|
@validator.add( :object, :json )
|
1398
1415
|
@validator.validate( 'object' => json )
|
1399
1416
|
|
1400
|
-
@validator.
|
1401
|
-
@validator.
|
1417
|
+
expect( @validator ).to_not be_okay()
|
1418
|
+
expect( @validator ).to have_errors()
|
1402
1419
|
|
1403
|
-
@validator[:object].
|
1420
|
+
expect( @validator[:object] ).to be_nil()
|
1404
1421
|
end
|
1405
1422
|
end
|
1406
1423
|
|
@@ -1412,20 +1429,20 @@ describe Strelka::ParamValidator do
|
|
1412
1429
|
@validator.add( :apikey, :md5sum )
|
1413
1430
|
@validator.validate( 'apikey' => sum )
|
1414
1431
|
|
1415
|
-
@validator.
|
1416
|
-
@validator.
|
1432
|
+
expect( @validator ).to_not have_errors()
|
1433
|
+
expect( @validator ).to be_okay()
|
1417
1434
|
|
1418
|
-
@validator[:apikey].
|
1435
|
+
expect( @validator[:apikey] ).to eq( sum )
|
1419
1436
|
end
|
1420
1437
|
|
1421
1438
|
it "rejects anything but a 32-character hex string" do
|
1422
1439
|
@validator.add( :apikey, :md5sum )
|
1423
1440
|
@validator.validate( 'apikey' => 'my ponies have WINGS!!!11' )
|
1424
1441
|
|
1425
|
-
@validator.
|
1426
|
-
@validator.
|
1442
|
+
expect( @validator ).to have_errors()
|
1443
|
+
expect( @validator ).to_not be_okay()
|
1427
1444
|
|
1428
|
-
@validator[:apikey].
|
1445
|
+
expect( @validator[:apikey] ).to be_nil()
|
1429
1446
|
end
|
1430
1447
|
|
1431
1448
|
end
|
@@ -1438,20 +1455,20 @@ describe Strelka::ParamValidator do
|
|
1438
1455
|
@validator.add( :apikey, :sha1sum )
|
1439
1456
|
@validator.validate( 'apikey' => sum )
|
1440
1457
|
|
1441
|
-
@validator.
|
1442
|
-
@validator.
|
1458
|
+
expect( @validator ).to_not have_errors()
|
1459
|
+
expect( @validator ).to be_okay()
|
1443
1460
|
|
1444
|
-
@validator[:apikey].
|
1461
|
+
expect( @validator[:apikey] ).to eq( sum )
|
1445
1462
|
end
|
1446
1463
|
|
1447
1464
|
it "rejects anything but a 40-character hex string" do
|
1448
1465
|
@validator.add( :apikey, :sha1sum )
|
1449
1466
|
@validator.validate( 'apikey' => '084444a9979487f43a238e45afc1ec1277a' )
|
1450
1467
|
|
1451
|
-
@validator.
|
1452
|
-
@validator.
|
1468
|
+
expect( @validator ).to have_errors()
|
1469
|
+
expect( @validator ).to_not be_okay()
|
1453
1470
|
|
1454
|
-
@validator[:apikey].
|
1471
|
+
expect( @validator[:apikey] ).to be_nil()
|
1455
1472
|
end
|
1456
1473
|
|
1457
1474
|
end
|
@@ -1464,20 +1481,20 @@ describe Strelka::ParamValidator do
|
|
1464
1481
|
@validator.add( :apikey, :sha256sum )
|
1465
1482
|
@validator.validate( 'apikey' => sum )
|
1466
1483
|
|
1467
|
-
@validator.
|
1468
|
-
@validator.
|
1484
|
+
expect( @validator ).to_not have_errors()
|
1485
|
+
expect( @validator ).to be_okay()
|
1469
1486
|
|
1470
|
-
@validator[:apikey].
|
1487
|
+
expect( @validator[:apikey] ).to eq( sum )
|
1471
1488
|
end
|
1472
1489
|
|
1473
1490
|
it "rejects anything but a 64-character hex string" do
|
1474
1491
|
@validator.add( :apikey, :sha256sum )
|
1475
1492
|
@validator.validate( 'apikey' => 'a_key' )
|
1476
1493
|
|
1477
|
-
@validator.
|
1478
|
-
@validator.
|
1494
|
+
expect( @validator ).to have_errors()
|
1495
|
+
expect( @validator ).to_not be_okay()
|
1479
1496
|
|
1480
|
-
@validator[:apikey].
|
1497
|
+
expect( @validator[:apikey] ).to be_nil()
|
1481
1498
|
end
|
1482
1499
|
|
1483
1500
|
end
|
@@ -1490,20 +1507,20 @@ describe Strelka::ParamValidator do
|
|
1490
1507
|
@validator.add( :apikey, :sha384sum )
|
1491
1508
|
@validator.validate( 'apikey' => sum )
|
1492
1509
|
|
1493
|
-
@validator.
|
1494
|
-
@validator.
|
1510
|
+
expect( @validator ).to_not have_errors()
|
1511
|
+
expect( @validator ).to be_okay()
|
1495
1512
|
|
1496
|
-
@validator[:apikey].
|
1513
|
+
expect( @validator[:apikey] ).to eq( sum )
|
1497
1514
|
end
|
1498
1515
|
|
1499
1516
|
it "rejects anything but a 96-character hex string" do
|
1500
1517
|
@validator.add( :apikey, :sha384sum )
|
1501
1518
|
@validator.validate( 'apikey' => ' ' + sum )
|
1502
1519
|
|
1503
|
-
@validator.
|
1504
|
-
@validator.
|
1520
|
+
expect( @validator ).to have_errors()
|
1521
|
+
expect( @validator ).to_not be_okay()
|
1505
1522
|
|
1506
|
-
@validator[:apikey].
|
1523
|
+
expect( @validator[:apikey] ).to be_nil()
|
1507
1524
|
end
|
1508
1525
|
|
1509
1526
|
end
|
@@ -1516,26 +1533,25 @@ describe Strelka::ParamValidator do
|
|
1516
1533
|
@validator.add( :apikey, :sha512sum )
|
1517
1534
|
@validator.validate( 'apikey' => sum )
|
1518
1535
|
|
1519
|
-
@validator.
|
1520
|
-
@validator.
|
1536
|
+
expect( @validator ).to_not have_errors()
|
1537
|
+
expect( @validator ).to be_okay()
|
1521
1538
|
|
1522
|
-
@validator[:apikey].
|
1539
|
+
expect( @validator[:apikey] ).to eq( sum )
|
1523
1540
|
end
|
1524
1541
|
|
1525
1542
|
it "rejects anything but a 128-character hex string" do
|
1526
1543
|
@validator.add( :apikey, :sha512sum )
|
1527
1544
|
@validator.validate( 'apikey' => '..,,..' )
|
1528
1545
|
|
1529
|
-
@validator.
|
1530
|
-
@validator.
|
1546
|
+
expect( @validator ).to have_errors()
|
1547
|
+
expect( @validator ).to_not be_okay()
|
1531
1548
|
|
1532
|
-
@validator[:apikey].
|
1549
|
+
expect( @validator[:apikey] ).to be_nil()
|
1533
1550
|
end
|
1534
1551
|
|
1535
1552
|
end
|
1536
1553
|
|
1537
1554
|
end # describe "constraints"
|
1538
1555
|
|
1539
|
-
|
1540
1556
|
end
|
1541
1557
|
|