Skip to content

Commit 705de4e

Browse files
feat(codegen): support malformed request tests (#2695)
Co-authored-by: Adam Thomas <[email protected]>
1 parent 88de69b commit 705de4e

File tree

1 file changed

+62
-1
lines changed
  • codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen

1 file changed

+62
-1
lines changed

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsProtocolUtils.java

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import software.amazon.smithy.model.traits.TimestampFormatTrait;
3434
import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
3535
import software.amazon.smithy.model.traits.XmlNamespaceTrait;
36+
import software.amazon.smithy.protocoltests.traits.HttpMalformedRequestTestCase;
3637
import software.amazon.smithy.protocoltests.traits.HttpMessageTestCase;
3738
import software.amazon.smithy.typescript.codegen.HttpProtocolTestGenerator;
3839
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
@@ -281,7 +282,10 @@ static String getInputTimestampValueProvider(
281282
}
282283

283284
static void generateProtocolTests(ProtocolGenerator generator, GenerationContext context) {
284-
new HttpProtocolTestGenerator(context, generator, AwsProtocolUtils::filterProtocolTests).run();
285+
new HttpProtocolTestGenerator(context,
286+
generator,
287+
AwsProtocolUtils::filterProtocolTests,
288+
AwsProtocolUtils::filterMalformedRequestTests).run();
285289
}
286290

287291
private static boolean filterProtocolTests(
@@ -299,4 +303,61 @@ private static boolean filterProtocolTests(
299303
}
300304
return false;
301305
}
306+
307+
private static boolean filterMalformedRequestTests(
308+
ServiceShape service,
309+
OperationShape operation,
310+
HttpMalformedRequestTestCase testCase,
311+
TypeScriptSettings settings
312+
) {
313+
//TODO: underflow/overflow not rejected yet
314+
if (testCase.hasTag("underflow/overflow")) {
315+
return true;
316+
}
317+
318+
//TODO: float truncation not rejected yet
319+
if (testCase.hasTag("float_truncation")) {
320+
return true;
321+
}
322+
323+
// TODO: handle timestamps
324+
if (testCase.hasTag("timestamp")) {
325+
return true;
326+
}
327+
328+
if (!testCase.getId().matches("^RestJsonBody\\w+MalformedValueRejected.*")) {
329+
//TODO: trailing characters in untyped contexts not rejected yet
330+
if (testCase.hasTag("trailing_chars") || testCase.hasTag("hex")) {
331+
return true;
332+
}
333+
}
334+
335+
//TODO: request serialization does not verify that the request is an object
336+
if (testCase.hasTag("technically_valid_json_body")) {
337+
return true;
338+
}
339+
//TODO: we don't do any union validation
340+
if (testCase.getId().startsWith("RestJsonMalformedUnion")) {
341+
return true;
342+
}
343+
//TODO: we don't do any set validation
344+
if (testCase.getId().startsWith("RestJsonMalformedSet")) {
345+
return true;
346+
}
347+
//TODO: we don't do any list validation
348+
if (testCase.getId().startsWith("RestJsonBodyMalformedList")) {
349+
return true;
350+
}
351+
//TODO: we don't validate map values
352+
if (testCase.getId().equals("RestJsonBodyMalformedMapNullValue")) {
353+
return true;
354+
}
355+
//TODO: Buffer.from isn't decoding base64 strictly.
356+
if (testCase.getId().equals("RestJsonBodyMalformedBlobInvalidBase64_case1")
357+
|| testCase.getId().equals("RestJsonBodyMalformedBlobInvalidBase64_case2")) {
358+
return true;
359+
}
360+
361+
return false;
362+
}
302363
}

0 commit comments

Comments
 (0)