Skip to content

Commit 9a5f585

Browse files
Merge remote-tracking branch 'origin/development' into local-staged-release
2 parents c56dfe7 + d77a0c7 commit 9a5f585

File tree

7 files changed

+118
-5
lines changed

7 files changed

+118
-5
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"services": [
3+
{
4+
"serviceName": "S3",
5+
"type": "patch",
6+
"changeLogMessages": [ "Fixed an issue where IAmazonS3.EnsureBucketExists(Async) was throwing an exception if S3 bucket already exists in the executing account." ]
7+
}
8+
]
9+
}
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/src/Services/S3/Custom/_async/AmazonS3Client.Extensions.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,16 @@ Task ICoreAmazonS3.MakeObjectPublicAsync(string bucket, string objectKey, bool e
145145
return this.PutObjectAclAsync(request);
146146
}
147147

148-
Task ICoreAmazonS3.EnsureBucketExistsAsync(string bucketName)
148+
async Task ICoreAmazonS3.EnsureBucketExistsAsync(string bucketName)
149149
{
150-
return this.PutBucketAsync(bucketName);
150+
try
151+
{
152+
await this.PutBucketAsync(bucketName).ConfigureAwait(false);
153+
}
154+
catch (BucketAlreadyOwnedByYouException)
155+
{
156+
}
151157
}
152-
153158
#endregion
154159
}
155160
}

sdk/src/Services/S3/Custom/_bcl/AmazonS3Client.Extensions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ void ICoreAmazonS3.MakeObjectPublic(string bucket, string objectKey, bool enable
143143

144144
void ICoreAmazonS3.EnsureBucketExists(string bucketName)
145145
{
146-
this.PutBucket(bucketName);
146+
try
147+
{
148+
this.PutBucket(bucketName);
149+
}
150+
catch (BucketAlreadyOwnedByYouException) { }
147151
}
148152
#endregion
149153
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.IO;
3+
using System.Net;
4+
using System.Net.Http;
5+
using System.Threading;
6+
using Microsoft.VisualStudio.TestTools.UnitTesting;
7+
8+
using Amazon;
9+
10+
using Amazon.SecurityToken;
11+
using Amazon.SecurityToken.Model;
12+
13+
using Amazon.S3;
14+
using Amazon.S3.Model;
15+
using Amazon.S3.Transfer;
16+
17+
using Amazon.S3Control;
18+
using Amazon.S3Control.Model;
19+
using Amazon.Runtime.SharedInterfaces;
20+
21+
22+
23+
namespace AWSSDK_DotNet.IntegrationTests.Tests.S3
24+
{
25+
[TestClass]
26+
public class S3ExtensionsTests : TestBase<AmazonS3Client>
27+
{
28+
static string _bucketName;
29+
30+
[ClassInitialize]
31+
public static void Setup(TestContext context)
32+
{
33+
_bucketName = S3TestUtils.CreateBucketWithWait(Client);
34+
}
35+
36+
[ClassCleanup]
37+
public static void ClassCleanup()
38+
{
39+
Amazon.S3.Util.AmazonS3Util.DeleteS3BucketWithObjects(Client, _bucketName);
40+
}
41+
42+
43+
[TestMethod]
44+
public void EnsureBucketExists()
45+
{
46+
IAmazonS3 s3Client = Client;
47+
s3Client.EnsureBucketExists(_bucketName);
48+
}
49+
}
50+
}

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)