public void S3OutpostBucketARNTests(string bucketNameOrARNInput, string clientRegion, string additionalFlags, string useArnRegion, string expectedEndpoint, string expectedHeaders, string expectedSignedBy) { Console.WriteLine(string.Join(" | ", bucketNameOrARNInput, clientRegion, additionalFlags, useArnRegion, expectedEndpoint, expectedHeaders, expectedSignedBy)); Console.WriteLine(); // ARRANGE // expectedEndpoint can be overloaded with the expected error message var expectSuccess = expectedEndpoint.Contains("amazonaws.com"); // outputs to assert against: IRequest s3Request = null; Exception exception = null; var request = new GetBucketRequest { Bucket = bucketNameOrARNInput, AccountId = "123456789012" }; var config = new AmazonS3ControlConfig { RegionEndpoint = clientRegion == "" ? null : RegionEndpoint.GetBySystemName(clientRegion), UseArnRegion = useArnRegion == "" ? false : bool.Parse(useArnRegion) }; if (additionalFlags.Contains("dualstack")) { config.UseDualstackEndpoint = true; } if (additionalFlags.Contains("fips")) { config.UseFIPSEndpoint = true; } if (additionalFlags.Contains("accelerate") && !expectSuccess) { // S3 Control Config does not allow setting accelerate, so it will not generate the expected error return; } // ACT try { s3Request = S3ControlArnTestUtils.RunMockRequest(request, GetBucketRequestMarshaller.Instance, config); Console.WriteLine(s3Request.Endpoint.ToString()); Console.WriteLine(); } catch (Exception e) { exception = e; } // ASSERT if (expectSuccess) { Assert.IsNull(exception, exception?.Message + "\r\n" + exception?.StackTrace); Assert.IsNotNull(s3Request); AssertExtensions.UrlSuffixMatches(expectedEndpoint, s3Request.Endpoint); AssertExtensions.ContainsHeaders(SpecMarkdownTestDataHelper.ParseExpectedHeaders(expectedHeaders), s3Request.Headers); } else { Assert.IsNull(s3Request); Assert.IsNotNull(exception); // reminder, expectedEndpoint also contains expected error message. AssertExtensions.AssertAreSameWithEmbellishments(expectedEndpoint, exception.Message); } }
public void S3ObjectLambdaBucketFieldInputTests(string bucketFieldInput, string clientRegion, string additionalFlags, string useArnRegion, string endpointUrl, string expectedEndpoint) { Console.WriteLine(string.Join(" | ", bucketFieldInput, clientRegion, additionalFlags, useArnRegion, endpointUrl, expectedEndpoint)); Console.WriteLine(); // ARRANGE // expectedEndpoint can be overloaded with the expected error message var expectSuccess = expectedEndpoint.Contains("amazonaws.com") || expectedEndpoint.Contains("my-endpoint.com"); // outputs to assert against: IRequest s3Request = null; Exception exception = null; var request = new GetObjectRequest { BucketName = bucketFieldInput, Key = "foo.txt" }; var config = new AmazonS3Config { UseArnRegion = useArnRegion == "" ? false : bool.Parse(useArnRegion), RegionEndpoint = clientRegion == "" ? null : RegionEndpoint.GetBySystemName(clientRegion) }; if (!string.IsNullOrWhiteSpace(endpointUrl)) { if (!endpointUrl.ToLower().StartsWith("https://")) { endpointUrl = $"https://{endpointUrl}"; } config.ServiceURL = endpointUrl; } if (additionalFlags.Contains("dualstack")) { config.UseDualstackEndpoint = true; } if (additionalFlags.Contains("fips")) { config.UseFIPSEndpoint = true; } if (additionalFlags.Contains("accelerate")) { config.UseAccelerateEndpoint = true; } // ACT try { s3Request = S3ArnTestUtils.RunMockRequest(request, GetObjectRequestMarshaller.Instance, config); Console.WriteLine(s3Request.Endpoint.ToString()); Console.WriteLine(); } catch (Exception e) { exception = e; } // ASSERT if (expectSuccess) { Assert.IsNull(exception, exception?.Message); Assert.IsNotNull(s3Request); AssertExtensions.UrlSuffixMatches(expectedEndpoint, s3Request.Endpoint); } else { Assert.IsNull(s3Request, s3Request?.Endpoint.ToString()); Assert.IsNotNull(exception); // reminder, expectedEndpoint also contains expected error message. AssertExtensions.AssertAreSameWithEmbellishments(expectedEndpoint, exception.Message); } }