Skip to content

Commit

Permalink
Fix: Update CopyObjectRequestMarshaller to throw ArgumentException fo…
Browse files Browse the repository at this point in the history
…r missing properties
  • Loading branch information
muhammad-othman committed Mar 25, 2024
1 parent 2c3dc52 commit 1a41d36
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
11 changes: 11 additions & 0 deletions generator/.DevConfigs/40980b2b-ec4c-4081-9a64-6a8a4a47d6bc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"services": [
{
"serviceName": "S3",
"type": "patch",
"changeLogMessages": [
"Fix: Update CopyObjectRequestMarshaller to throw ArgumentException for missing properties"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public IRequest Marshall(Amazon.Runtime.AmazonWebServiceRequest input)
public IRequest Marshall(CopyObjectRequest copyObjectRequest)
{
var sourceKey =
copyObjectRequest.DisableTrimmingLeadingSlash ?
copyObjectRequest.DisableTrimmingLeadingSlash || string.IsNullOrEmpty(copyObjectRequest.SourceKey) ?
copyObjectRequest.SourceKey :
AmazonS3Util.RemoveLeadingSlash(copyObjectRequest.SourceKey);

var destinationKey =
copyObjectRequest.DisableTrimmingLeadingSlash ?
copyObjectRequest.DisableTrimmingLeadingSlash || string.IsNullOrEmpty(copyObjectRequest.DestinationKey) ?
copyObjectRequest.DestinationKey:
AmazonS3Util.RemoveLeadingSlash(copyObjectRequest.DestinationKey);

Expand Down Expand Up @@ -148,6 +148,10 @@ public IRequest Marshall(CopyObjectRequest copyObjectRequest)
throw new System.ArgumentException("DestinationBucket is a required property and must be set before making this call.", "CopyObjectRequest.DestinationBucket");
if (string.IsNullOrEmpty(destinationKey))
throw new System.ArgumentException("DestinationKey is a required property and must be set before making this call.", "CopyObjectRequest.DestinationKey");
if (string.IsNullOrEmpty(copyObjectRequest.SourceBucket))
throw new System.ArgumentException("SourceBucket is a required property and must be set before making this call.", "CopyObjectRequest.SourceBucket");
if (string.IsNullOrEmpty(sourceKey))
throw new System.ArgumentException("SourceKey is a required property and must be set before making this call.", "CopyObjectRequest.SourceKey");

request.ResourcePath = string.Format(CultureInfo.InvariantCulture, "/{0}",
S3Transforms.ToStringValue(destinationKey));
Expand Down
28 changes: 28 additions & 0 deletions sdk/test/Services/S3/IntegrationTests/CopyObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,33 @@ public void TestCopyObjectWithLeadingSlash(bool disableTrimmingLeadingSlash, str
Assert.AreEqual(testContent, actualText);
}
}

[DataRow(testKey, true, "/destinationTestKey1.txt", true, null)]
[DataRow(null, true, "/destinationTestKey1.txt", true, "CopyObjectRequest.SourceKey")]
[DataRow(testKey, false, "/destinationTestKey1.txt", true, "CopyObjectRequest.SourceBucket")]
[DataRow(testKey, true, null, true, "CopyObjectRequest.DestinationKey")]
[DataRow(testKey, true, "/destinationTestKey1.txt", false, "CopyObjectRequest.DestinationBucket")]
[DataTestMethod]
[TestCategory("S3")]
public void TestCopyObjectWithMissingParameters(string sourceKey, bool includeSourceBucket, string destinationKey, bool includeDestinationBucket, string expectedMissingParameter)
{
string missingParameter = null;
try
{
var copyObjectResponse = usEastClient.CopyObject(new CopyObjectRequest
{
SourceKey = sourceKey,
SourceBucket = includeSourceBucket ? eastBucketName : null,

DestinationKey = destinationKey,
DestinationBucket = includeDestinationBucket ? eastBucketName : null,
});
}
catch (ArgumentException ex)
{
missingParameter = ex.ParamName;
}
Assert.AreEqual(missingParameter, expectedMissingParameter);
}
}
}

0 comments on commit 1a41d36

Please sign in to comment.