Skip to content

Commit 2a1f184

Browse files
authored
Update JSON error unmarshaller not to check for nested properties (#3889)
1 parent dd4b2eb commit 2a1f184

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"core": {
3+
"changeLogMessages": [
4+
"Update `JsonErrorResponseUnmarshaller` not to check nested properties when trying to populate details for operations that failed."
5+
],
6+
"type": "patch",
7+
"updateMinimum": true
8+
},
9+
"services": [
10+
{
11+
"serviceName": "DynamoDBv2",
12+
"type": "patch",
13+
"changeLogMessages": [
14+
"Fix issue where `ReturnValuesOnConditionCheckFailure` could not be used if the provided document included properties that ended with `code` or `message` (https://github.com/aws/aws-sdk-net/issues/3764)."
15+
]
16+
}
17+
]
18+
}

sdk/src/Core/Amazon.Runtime/Internal/Transform/JsonErrorResponseUnmarshaller.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ private static void GetValuesFromJsonIfPossible(JsonUnmarshallerContext context,
148148

149149
while (TryReadContext(context))
150150
{
151+
// Do not attempt to process nested properties, as for DynamoDB the error response may contain
152+
// extra values that end with one of the prefixes we're looking.
153+
// Issue reported in: https://github.com/aws/aws-sdk-net/issues/3764
154+
if (context.CurrentDepth > 1)
155+
{
156+
continue;
157+
}
158+
151159
if (context.TestExpression("__type"))
152160
{
153161
type = StringUnmarshaller.GetInstance().Unmarshall(context);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using Amazon.DynamoDBv2.Model;
2+
using Amazon.DynamoDBv2.Model.Internal.MarshallTransformations;
3+
using Amazon.Runtime.Internal.Transform;
4+
using AWSSDK_DotNet35.UnitTests.TestTools;
5+
using Microsoft.VisualStudio.TestTools.UnitTesting;
6+
using System.IO;
7+
using System.Net;
8+
using System.Text;
9+
10+
namespace AWSSDK_DotNet35.UnitTests
11+
{
12+
[TestClass]
13+
public class ErrorMarshallerTests
14+
{
15+
/// <summary>
16+
/// Reported in https://github.com/aws/aws-sdk-net/issues/3764
17+
/// </summary>
18+
[TestMethod]
19+
[TestCategory("DynamoDBv2")]
20+
public void ErrorMarshaller_IgnoresNestedPropertiesForException()
21+
{
22+
var content = @"{
23+
""__type"": ""com.amazonaws.dynamodb.v20120810#ConditionalCheckFailedException"",
24+
""Item"": {
25+
""Dictionary"": {
26+
""M"": {
27+
""keyThatEndsWithCode"": {
28+
""M"": {
29+
""Foo"": {
30+
""S"": ""bar""
31+
}
32+
}
33+
}
34+
}
35+
},
36+
""Key"": {
37+
""S"": ""Key""
38+
}
39+
},
40+
""Message"": ""The conditional request failed""
41+
}";
42+
43+
var webResponseData = new WebResponseData();
44+
webResponseData.StatusCode = HttpStatusCode.BadRequest;
45+
webResponseData.Headers["Content-Type"] = "application/x-amz-json-1.0";
46+
47+
var stream = new MemoryStream(Encoding.ASCII.GetBytes(content));
48+
var context = new JsonUnmarshallerContext(stream, true, webResponseData);
49+
50+
var response = new PutItemResponseUnmarshaller().UnmarshallException(context, null, HttpStatusCode.BadRequest);
51+
var actualException = response as ConditionalCheckFailedException;
52+
Assert.IsNotNull(actualException);
53+
54+
Assert.IsNotNull(actualException.Item);
55+
Assert.AreEqual(2, actualException.Item.Count);
56+
Assert.IsNotNull(actualException.Item["Dictionary"].M["keyThatEndsWithCode"]);
57+
Assert.IsNotNull(actualException.Item["Key"].S);
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)