Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/S3Policy/PolicyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static Policy ToPolicy(PolicyRequest[] policyRequests)
Action = new string[] { "s3:*" },
Effect = "Allow",
Resource = policyRequests
.Select(pr => System.IO.Path.Join(pr.BucketName, pr.FolderName, "*"))
.Select(pr => $"{pr.BucketName}/{pr.FolderName}/*")
.Distinct()
.ToArray(),
},
Expand Down
17 changes: 17 additions & 0 deletions src/S3Policy/Tests/Extensions/PolicyExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

using Monai.Deploy.Storage.S3Policy.Policies;
using Newtonsoft.Json;

namespace Monai.Deploy.Storage.S3Policy.Tests.Extensions
Expand Down Expand Up @@ -100,6 +101,22 @@ public void ToPolicy_NullFolder_ThrowsException()
Assert.Throws<ArgumentNullException>(() => PolicyExtensions.ToPolicy("test-bucket", null));
}

[Fact]
public async Task ToPolicy_Should_Set_Correct_Allow_All_Path()
{
const string bucketName = "test-bucket";
const string payloadId = "00000000-1000-0000-0000-000000000000";

var policys = new PolicyRequest[] { new PolicyRequest(bucketName, payloadId) };

var policyMade = PolicyExtensions.ToPolicy(policys);

Assert.EndsWith(
$"{bucketName}/{payloadId}/*",
policyMade.Statement.First(p => p.Sid == "AllowAllS3ActionsInUserFolder").Resource?.First());

}

#endregion ToPolicy
}
}