Skip to content

Commit 1505b5c

Browse files
Merge pull request #3799 from aws/muhamoth/issue-3797
Fix missing OriginalRequest in RequestContext when generating presigned URLs.
2 parents a4b59eb + 2fd4657 commit 1505b5c

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"services": [
3+
{
4+
"serviceName": "S3",
5+
"type": "patch",
6+
"changeLogMessages": [
7+
"Fix regression where presigned URLs could not be created when using a custom `ServiceURL`."
8+
]
9+
}
10+
]
11+
}

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,15 @@ internal string GetPreSignedURLInternal(GetPreSignedUrlRequest request)
113113
var immutableCredentials = credentials.GetCredentials();
114114
var irequest = Marshall(this.Config, request, immutableCredentials.AccessKey, immutableCredentials.Token, signatureVersionToUse);
115115

116-
var context = new Amazon.Runtime.Internal.ExecutionContext(new Amazon.Runtime.Internal.RequestContext(true, new NullSigner()) { Request = irequest, ClientConfig = this.Config }, null);
117-
116+
var context = new Amazon.Runtime.Internal.ExecutionContext(
117+
new RequestContext(true, new NullSigner())
118+
{
119+
Request = irequest,
120+
ClientConfig = this.Config,
121+
OriginalRequest = request,
122+
},
123+
null
124+
);
118125
new AmazonS3EndpointResolver().ProcessRequestHandlers(context);
119126
var expressConfig = this.Config as AmazonS3Config;
120127
if (context.RequestContext.Request.IsDirectoryBucket() && !expressConfig.DisableS3ExpressSessionAuth)
@@ -176,8 +183,15 @@ internal async Task<string> GetPreSignedURLInternalAsync(GetPreSignedUrlRequest
176183
var immutableCredentials = await credentials.GetCredentialsAsync().ConfigureAwait(false);
177184
var irequest = Marshall(this.Config, request, immutableCredentials.AccessKey, immutableCredentials.Token, signatureVersionToUse);
178185

179-
180-
var context = new Amazon.Runtime.Internal.ExecutionContext(new Amazon.Runtime.Internal.RequestContext(true, new NullSigner()) { Request = irequest, ClientConfig = this.Config }, null);
186+
var context = new Amazon.Runtime.Internal.ExecutionContext(
187+
new RequestContext(true, new NullSigner())
188+
{
189+
Request = irequest,
190+
ClientConfig = this.Config,
191+
OriginalRequest = request,
192+
},
193+
null
194+
);
181195
new AmazonS3EndpointResolver().ProcessRequestHandlers(context);
182196
var expressConfig = this.Config as AmazonS3Config;
183197
if (context.RequestContext.Request.IsDirectoryBucket() && !expressConfig.DisableS3ExpressSessionAuth)

sdk/test/Services/S3/IntegrationTests/GeneratePreSignedUrlTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,34 @@ public void EUNorth1PutWithMetadata()
176176
});
177177
}
178178

179+
[TestMethod]
180+
[TestCategory("S3")]
181+
public void TestGetPreSignedURL_WithCustomServiceURL()
182+
{
183+
var serviceUrl = "https://s3-external-1.amazonaws.com";
184+
var config = new AmazonS3Config
185+
{
186+
ServiceURL = serviceUrl,
187+
ForcePathStyle = true,
188+
AuthenticationRegion = "us-west-2"
189+
};
190+
191+
var credentials = new BasicAWSCredentials("accessKey", "secretKey");
192+
193+
var s3Client = new AmazonS3Client(credentials, config);
194+
195+
var request = new GetPreSignedUrlRequest
196+
{
197+
BucketName = "my-bucket",
198+
Key = "my-object-key",
199+
Expires = DateTime.UtcNow.AddMinutes(5)
200+
};
201+
202+
var url = s3Client.GetPreSignedURL(request);
203+
204+
Assert.IsTrue(url.StartsWith(serviceUrl));
205+
}
206+
179207
private void TestPreSignedUrlPut(PresignedUrlTestParameters testParams)
180208
{
181209
var client = new AmazonS3Client(testParams.Region);

0 commit comments

Comments
 (0)