Skip to content

Commit 2dff666

Browse files
committed
fix for policy allowAllInFolder part
Signed-off-by: Neil South <neil.south@answerdigital.com>
1 parent 6e2935a commit 2dff666

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/S3Policy/PolicyExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public static Policy ToPolicy(PolicyRequest[] policyRequests)
139139
Action = new string[] { "s3:*" },
140140
Effect = "Allow",
141141
Resource = policyRequests
142-
.Select(pr => System.IO.Path.Join(pr.BucketName, pr.FolderName, "*"))
142+
.Select(pr => $"{pr.BucketName}/{pr.FolderName}/*")
143143
.Distinct()
144144
.ToArray(),
145145
},

src/S3Policy/Tests/Extensions/PolicyExtensionsTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
using Monai.Deploy.Storage.S3Policy.Policies;
1718
using Newtonsoft.Json;
1819

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

104+
[Fact]
105+
public async Task ToPolicy_Should_Set_Correct_Allow_All_Path()
106+
{
107+
const string bucketName = "test-bucket";
108+
const string payloadId = "00000000-1000-0000-0000-000000000000";
109+
110+
var policys = new PolicyRequest[] { new PolicyRequest(bucketName, payloadId) };
111+
112+
var policyMade = PolicyExtensions.ToPolicy(policys);
113+
114+
Assert.EndsWith(
115+
$"{bucketName}/{payloadId}/*",
116+
policyMade.Statement.First(p => p.Sid == "AllowAllS3ActionsInUserFolder").Resource?.First());
117+
118+
}
119+
103120
#endregion ToPolicy
104121
}
105122
}

0 commit comments

Comments
 (0)