Skip to content

Commit c822aec

Browse files
committed
Fixed an issue in JsonPolicyWriter.WritePolicyToString() method where it was not using prettyPrint parameter for indentation.
1 parent 4b0a817 commit c822aec

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"core": {
3+
"changeLogMessages": [
4+
"Fixed an issue in JsonPolicyWriter.WritePolicyToString() method where it was not using prettyPrint parameter for indentation."
5+
],
6+
"type": "patch",
7+
"updateMinimum": false
8+
}
9+
}

sdk/src/Core/Amazon.Auth/AccessControlPolicy/Internal/JsonPolicyWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static string WritePolicyToString(bool prettyPrint, Policy policy)
5353
// indentSize is only available in net8+ and net472
5454
JsonWriterOptions options = new JsonWriterOptions
5555
{
56-
Indented = true,
56+
Indented = prettyPrint
5757
};
5858
using (var stream = new MemoryStream())
5959
using (var generator = new Utf8JsonWriter(stream, options))

sdk/test/UnitTests/Custom/PolicyTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,5 +249,41 @@ public void HandleAnonymousWhenConvertingPrincipals()
249249
Assert.AreEqual(1, statement.Principals.Count);
250250
Assert.AreEqual(Principal.Anonymous, statement.Principals.First());
251251
}
252+
253+
[TestMethod]
254+
public void TestPrettyPrintIndentationDisabled()
255+
{
256+
string testPolicy = @"{
257+
""Version"": ""2012-10-17"",
258+
""Statement"": [
259+
{
260+
""Sid"": ""AllowS3ListBucket"",
261+
""Effect"": ""Allow"",
262+
""Action"": [
263+
""s3:ListBucket""
264+
],
265+
""Resource"": [
266+
""arn:aws:s3:::your-bucket-name""
267+
]
268+
}
269+
]
270+
}";
271+
272+
var policy = Policy.FromJson(testPolicy);
273+
string policyString = policy.ToJson(false);
274+
275+
Assert.IsFalse(policyString.Contains("\n"));
276+
}
277+
278+
[TestMethod]
279+
public void TestPrettyPrintIndentationEnabled()
280+
{
281+
string testPolicy = @"{""Version"": ""2012-10-17"", ""Statement"": [{""Sid"": ""AllowS3ListBucket"", ""Effect"": ""Allow"", ""Action"": [ ""s3:ListBucket"" ], ""Resource"": [ ""arn:aws:s3:::your-bucket-name""]}]}";
282+
283+
var policy = Policy.FromJson(testPolicy);
284+
string policyString = policy.ToJson(true);
285+
286+
Assert.IsTrue(policyString.Contains("\n"));
287+
}
252288
}
253289
}

0 commit comments

Comments
 (0)