@@ -28,12 +28,12 @@ class ObjectIntrospectionSpecification extends DDSpecification {
28
28
29
29
void ' null is preserved' () {
30
30
expect :
31
- convert(null , ctx) == null
31
+ convert(null , ctx). getValue() == null
32
32
}
33
33
34
34
void ' type #type is preserved' () {
35
35
when :
36
- def result = convert(input, ctx)
36
+ def result = convert(input, ctx). getValue()
37
37
38
38
then :
39
39
input. getClass() == type
@@ -56,7 +56,7 @@ class ObjectIntrospectionSpecification extends DDSpecification {
56
56
57
57
void ' type #type is converted to string' () {
58
58
when :
59
- def result = convert(input, ctx)
59
+ def result = convert(input, ctx). getValue()
60
60
61
61
then :
62
62
type. isAssignableFrom(input. getClass())
@@ -83,9 +83,9 @@ class ObjectIntrospectionSpecification extends DDSpecification {
83
83
}
84
84
85
85
expect :
86
- convert(iter, ctx) instanceof List
87
- convert(iter, ctx) == [' a' , ' b' ]
88
- convert([' a' , ' b' ], ctx) == [' a' , ' b' ]
86
+ convert(iter, ctx). getValue() instanceof List
87
+ convert(iter, ctx) .getValue() == [' a' , ' b' ]
88
+ convert([' a' , ' b' ], ctx). getValue() == [' a' , ' b' ]
89
89
}
90
90
91
91
void ' maps are converted to hash maps' () {
@@ -95,21 +95,21 @@ class ObjectIntrospectionSpecification extends DDSpecification {
95
95
}
96
96
97
97
expect :
98
- convert(map, ctx) instanceof HashMap
99
- convert(map, ctx) == [a : ' b' ]
100
- convert([(6 ): ' b' ], ctx) == [' 6' : ' b' ]
101
- convert([(null ): ' b' ], ctx) == [' null' : ' b' ]
102
- convert([(true ): ' b' ], ctx) == [' true' : ' b' ]
103
- convert([(' a' as Character ): ' b' ], ctx) == [' a' : ' b' ]
104
- convert([(createCharBuffer(' a' )): ' b' ], ctx) == [' a' : ' b' ]
98
+ convert(map, ctx). getValue() instanceof HashMap
99
+ convert(map, ctx). getValue() == [a : ' b' ]
100
+ convert([(6 ): ' b' ], ctx). getValue() == [' 6' : ' b' ]
101
+ convert([(null ): ' b' ], ctx). getValue() == [' null' : ' b' ]
102
+ convert([(true ): ' b' ], ctx). getValue() == [' true' : ' b' ]
103
+ convert([(' a' as Character ): ' b' ], ctx). getValue() == [' a' : ' b' ]
104
+ convert([(createCharBuffer(' a' )): ' b' ], ctx). getValue() == [' a' : ' b' ]
105
105
}
106
106
107
107
void ' arrays are converted into lists' () {
108
108
expect :
109
- convert([6 , ' b' ] as Object [], ctx) == [6 , ' b' ]
110
- convert([null , null ] as Object [], ctx) == [null , null ]
111
- convert([1 , 2 ] as int [], ctx) == [1 as int , 2 as int ]
112
- convert([1 , 2 ] as byte [], ctx) == [1 as byte , 2 as byte ]
109
+ convert([6 , ' b' ] as Object [], ctx). getValue() == [6 , ' b' ]
110
+ convert([null , null ] as Object [], ctx). getValue() == [null , null ]
111
+ convert([1 , 2 ] as int [], ctx). getValue() == [1 as int , 2 as int ]
112
+ convert([1 , 2 ] as byte [], ctx). getValue() == [1 as byte , 2 as byte ]
113
113
}
114
114
115
115
@SuppressWarnings (' UnusedPrivateField' )
@@ -127,8 +127,8 @@ class ObjectIntrospectionSpecification extends DDSpecification {
127
127
128
128
void ' other objects are converted into hash maps' () {
129
129
expect :
130
- convert(new ClassToBeConverted (), ctx) instanceof HashMap
131
- convert(new ClassToBeConvertedExt (), ctx) == [c : ' d' , a : ' b' , l : [1 , 2 ]]
130
+ convert(new ClassToBeConverted (), ctx). getValue() instanceof HashMap
131
+ convert(new ClassToBeConvertedExt (), ctx) .getValue() == [c : ' d' , a : ' b' , l : [1 , 2 ]]
132
132
}
133
133
134
134
class ProtobufLikeClass {
@@ -139,15 +139,15 @@ class ObjectIntrospectionSpecification extends DDSpecification {
139
139
140
140
void ' some field names are ignored' () {
141
141
expect :
142
- convert(new ProtobufLikeClass (), ctx) instanceof HashMap
143
- convert(new ProtobufLikeClass (), ctx) == [c : ' d' ]
142
+ convert(new ProtobufLikeClass (), ctx). getValue() instanceof HashMap
143
+ convert(new ProtobufLikeClass (), ctx). getValue() == [c : ' d' ]
144
144
}
145
145
146
146
void ' invalid keys are converted to special strings' () {
147
147
expect :
148
- convert(Collections . singletonMap(new ClassToBeConverted (), ' a' ), ctx) == [' invalid_key:1' : ' a' ]
149
- convert([new ClassToBeConverted (): ' a' , new ClassToBeConverted (): ' b' ], ctx) == [' invalid_key:1' : ' a' , ' invalid_key:2' : ' b' ]
150
- convert(Collections . singletonMap([1 , 2 ], ' a' ), ctx) == [' invalid_key:1' : ' a' ]
148
+ convert(Collections . singletonMap(new ClassToBeConverted (), ' a' ), ctx). getValue() == [' invalid_key:1' : ' a' ]
149
+ convert([new ClassToBeConverted (): ' a' , new ClassToBeConverted (): ' b' ], ctx). getValue() == [' invalid_key:1' : ' a' , ' invalid_key:2' : ' b' ]
150
+ convert(Collections . singletonMap([1 , 2 ], ' a' ), ctx). getValue() == [' invalid_key:1' : ' a' ]
151
151
}
152
152
153
153
void ' max number of elements is honored' () {
@@ -156,16 +156,28 @@ class ObjectIntrospectionSpecification extends DDSpecification {
156
156
128. times { m[it] = ' b' }
157
157
158
158
when :
159
- def result1 = convert([[' a' ] * 255 ], ctx)[ 0 ]
160
- def result2 = convert([[' a' ] * 255 as String []], ctx)[ 0 ]
159
+ def result1 = convert([[' a' ] * 255 ], ctx)
160
+ def result2 = convert([[' a' ] * 255 as String []], ctx)
161
161
def result3 = convert(m, ctx)
162
162
163
163
then :
164
- result1. size() == 254 // +2 for the lists
165
- result2. size() == 254 // +2 for the lists
166
- result3. size() == 127 // +1 for the map, 2 for each entry (key and value)
164
+ result1. getValue()[0 ]. size() == 254 // +2 for the lists
165
+ result1. isAnyTruncated()
166
+ result1. isCollectionTruncated()
167
+ ! result1. isDepthTruncated()
168
+ ! result1. isStringTruncated()
169
+ result2. getValue()[0 ]. size() == 254 // +2 for the lists
170
+ result2. isAnyTruncated()
171
+ result2. isCollectionTruncated()
172
+ ! result2. isDepthTruncated()
173
+ ! result2. isStringTruncated()
174
+ result3. getValue(). size() == 127 // +1 for the map, 2 for each entry (key and value)
175
+ ! result3. isAnyTruncated()
176
+ ! result3. isCollectionTruncated()
177
+ ! result3. isDepthTruncated()
178
+ ! result3. isStringTruncated()
167
179
2 * ctx. setWafTruncated()
168
- 2 * wafMetricCollector. wafInputTruncated(false , true , false )
180
+ // 2 * wafMetricCollector.wafInputTruncated(false, true, false)
169
181
170
182
}
171
183
@@ -179,18 +191,23 @@ class ObjectIntrospectionSpecification extends DDSpecification {
179
191
when :
180
192
// Invoke conversion with context
181
193
def result = convert(objArray, ctx)
194
+ def converted = result. getValue()
182
195
183
196
then :
184
197
// Traverse converted arrays to count actual depth
185
198
int depth = 0
186
- for (p = result ; p != null ; p = p[0 ]) {
199
+ for (p = converted ; p != null ; p = p[0 ]) {
187
200
depth++
188
201
}
189
202
depth == 21 // after max depth we have nulls
190
203
191
204
// Should record a truncation due to depth
192
205
1 * ctx. setWafTruncated()
193
- 1 * wafMetricCollector. wafInputTruncated(false , false , true )
206
+ result. isDepthTruncated()
207
+ ! result. isCollectionTruncated()
208
+ result. isAnyTruncated()
209
+ ! result. isStringTruncated()
210
+ // 1 * wafMetricCollector.wafInputTruncated(false, false, true)
194
211
}
195
212
196
213
void ' max depth is honored — list version' () {
@@ -203,18 +220,23 @@ class ObjectIntrospectionSpecification extends DDSpecification {
203
220
when :
204
221
// Invoke conversion with context
205
222
def result = convert(list, ctx)
223
+ def converted = result. getValue()
206
224
207
225
then :
208
226
// Traverse converted lists to count actual depth
209
227
int depth = 0
210
- for (p = result ; p != null ; p = p[0 ]) {
228
+ for (p = converted ; p != null ; p = p[0 ]) {
211
229
depth++
212
230
}
213
231
depth == 21 // after max depth we have nulls
214
232
215
233
// Should record a truncation due to depth
216
234
1 * ctx. setWafTruncated()
217
- 1 * wafMetricCollector. wafInputTruncated(false , false , true )
235
+ result. isDepthTruncated()
236
+ ! result. isCollectionTruncated()
237
+ result. isAnyTruncated()
238
+ ! result. isStringTruncated()
239
+ // 1 * wafMetricCollector.wafInputTruncated(false, false, true)
218
240
}
219
241
220
242
def ' max depth is honored — map version' () {
@@ -227,26 +249,32 @@ class ObjectIntrospectionSpecification extends DDSpecification {
227
249
when :
228
250
// Invoke conversion with context
229
251
def result = convert(map, ctx)
252
+ def converted = result. getValue()
230
253
231
254
then :
232
255
// Traverse converted maps to count actual depth
233
256
int depth = 0
234
- for (p = result ; p != null ; p = p[' a' ]) {
257
+ for (p = converted ; p != null ; p = p[' a' ]) {
235
258
depth++
236
259
}
237
260
depth == 21 // after max depth we have nulls
238
261
239
262
// Should record a truncation due to depth
240
263
1 * ctx. setWafTruncated()
241
- 1 * wafMetricCollector. wafInputTruncated(false , false , true )
264
+ result. isDepthTruncated()
265
+ ! result. isCollectionTruncated()
266
+ result. isAnyTruncated()
267
+ ! result. isStringTruncated()
268
+ // 1 * wafMetricCollector.wafInputTruncated(false, false, true)
242
269
}
243
270
244
271
void ' truncate long #typeName to 4096 chars and set truncation flag' () {
245
272
setup :
246
273
def longInput = rawInput
247
274
248
275
when :
249
- def converted = convert(longInput, ctx)
276
+ def result = convert(longInput, ctx)
277
+ def converted = result. getValue()
250
278
251
279
then :
252
280
// Should always produce a String of exactly 4096 chars
@@ -255,7 +283,11 @@ class ObjectIntrospectionSpecification extends DDSpecification {
255
283
256
284
// Should record a truncation due to string length
257
285
1 * ctx. setWafTruncated()
258
- 1 * wafMetricCollector. wafInputTruncated(true , false , false )
286
+ // 1 * wafMetricCollector.wafInputTruncated(true, false, false)
287
+ result. isStringTruncated()
288
+ ! result. isDepthTruncated()
289
+ ! result. isCollectionTruncated()
290
+ result. isAnyTruncated()
259
291
260
292
where :
261
293
typeName | rawInput
@@ -271,7 +303,8 @@ class ObjectIntrospectionSpecification extends DDSpecification {
271
303
272
304
when :
273
305
// convert returns Pair<convertedObject, wasTruncated>
274
- def converted = convert(inputMap, ctx)
306
+ def result = convert(inputMap, ctx)
307
+ def converted = result. getValue()
275
308
276
309
then :
277
310
// Extract the single truncated key
@@ -281,7 +314,11 @@ class ObjectIntrospectionSpecification extends DDSpecification {
281
314
truncatedKey. length() == 4096
282
315
283
316
1 * ctx. setWafTruncated()
284
- 1 * wafMetricCollector. wafInputTruncated(true , false , false )
317
+ // 1 * wafMetricCollector.wafInputTruncated(true, false, false)
318
+ result. isStringTruncated()
319
+ ! result. isDepthTruncated()
320
+ ! result. isCollectionTruncated()
321
+ result. isAnyTruncated()
285
322
286
323
287
324
where :
@@ -302,6 +339,7 @@ class ObjectIntrospectionSpecification extends DDSpecification {
302
339
}
303
340
304
341
expect :
305
- convert([cs], ctx) == [' error:my exception' ]
342
+ convert([cs], ctx). getValue() == [' error:my exception' ]
306
343
}
307
344
}
345
+
0 commit comments