|
| 1 | +using Amazon; |
| 2 | +using Amazon.Runtime; |
| 3 | +using Amazon.Runtime.Internal.Util; |
| 4 | +using Amazon.S3; |
| 5 | +using Amazon.S3.Model; |
| 6 | +using Amazon.S3.Util; |
| 7 | +using Amazon.Util; |
| 8 | +using AWSSDK_DotNet.IntegrationTests.Utils; |
| 9 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
1 | 10 | using System; |
2 | 11 | using System.Collections.Generic; |
3 | 12 | using System.IO; |
|
6 | 15 | using System.Net; |
7 | 16 | using System.Text; |
8 | 17 | using System.Threading; |
9 | | -using Microsoft.VisualStudio.TestTools.UnitTesting; |
10 | | - |
11 | | -using Amazon; |
12 | | -using Amazon.S3; |
13 | | -using Amazon.S3.Model; |
14 | | -using Amazon.S3.Util; |
15 | | -using Amazon.Runtime; |
16 | | -using Amazon.Runtime.Internal.Util; |
17 | | -using AWSSDK_DotNet.IntegrationTests.Utils; |
18 | | -using System.Diagnostics; |
19 | | -using Amazon.Util; |
20 | 18 | using System.Threading.Tasks; |
21 | 19 |
|
22 | 20 | namespace AWSSDK_DotNet.IntegrationTests.Tests.S3 |
@@ -1372,6 +1370,64 @@ public void TestResetStreamPosition() |
1372 | 1370 |
|
1373 | 1371 | } |
1374 | 1372 |
|
| 1373 | + [TestMethod] |
| 1374 | + [TestCategory("S3")] |
| 1375 | + public async Task ConfirmRetrySignature() |
| 1376 | + { |
| 1377 | + var config = new AmazonS3Config |
| 1378 | + { |
| 1379 | + RegionEndpoint = Client.Config.RegionEndpoint, |
| 1380 | + ResignRetries = true |
| 1381 | + }; |
| 1382 | + var s3Client = new AmazonS3Client(config); |
| 1383 | + // This test is response to this PR https://github.com/aws/aws-sdk-net/pull/4050 |
| 1384 | + // where retries started failing with signature mismatch due to user agent modifications. |
| 1385 | + // In this test we are confirming all retries are attempted and not failing with signature mismatch. |
| 1386 | + var stream = new FailOnceStream(new MemoryStream(Encoding.UTF8.GetBytes("ConfirmRetrySignature"))); |
| 1387 | + PutObjectRequest request = new PutObjectRequest() |
| 1388 | + { |
| 1389 | + BucketName = bucketName, |
| 1390 | + Key = "thestream", |
| 1391 | + InputStream = stream, |
| 1392 | + AutoCloseStream = false, |
| 1393 | + DisablePayloadSigning = true |
| 1394 | + }; |
| 1395 | + |
| 1396 | + ((Amazon.Runtime.Internal.IAmazonWebServiceRequest)request).UserAgentDetails.AddUserAgentComponent("Modifications"); |
| 1397 | + |
| 1398 | + await Client.PutObjectAsync(request); |
| 1399 | + } |
| 1400 | + |
| 1401 | + private class FailOnceStream : WrapperStream |
| 1402 | + { |
| 1403 | + public FailOnceStream(MemoryStream memoryStream) |
| 1404 | + : base(memoryStream) |
| 1405 | + { |
| 1406 | + } |
| 1407 | + |
| 1408 | + bool _firstRead = true; |
| 1409 | + |
| 1410 | + |
| 1411 | + public override int Read(byte[] buffer, int offset, int count) |
| 1412 | + { |
| 1413 | + if (_firstRead) |
| 1414 | + { |
| 1415 | + _firstRead = false; |
| 1416 | + throw new IOException("Fake Exception"); |
| 1417 | + } |
| 1418 | + return base.Read(buffer, offset, count); |
| 1419 | + } |
| 1420 | + public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) |
| 1421 | + { |
| 1422 | + if (_firstRead) |
| 1423 | + { |
| 1424 | + _firstRead = false; |
| 1425 | + throw new IOException("Fake Exception"); |
| 1426 | + } |
| 1427 | + return base.ReadAsync(buffer, offset, count, cancellationToken); |
| 1428 | + } |
| 1429 | + } |
| 1430 | + |
1375 | 1431 | private class ErrorStream : WrapperStream |
1376 | 1432 | { |
1377 | 1433 | private ErrorStream(Stream stream) |
|
0 commit comments