コード例 #1
0
        public void MarshallXMLWithExtraEncodingTest(string toEncode, string expectedEncoding)
        {
            var request = new PutBucketTaggingRequest()
            {
                AccountId = "0123456789",
                Bucket    = "foo",
                Tagging   = new Tagging()
                {
                    TagSet = new List <S3Tag>()
                    {
                        new S3Tag {
                            Key = "foo", Value = toEncode
                        }
                    }
                }
            };

            var internalRequest = S3ControlArnTestUtils.RunMockRequest(request, PutBucketTaggingRequestMarshaller.Instance, new AmazonS3ControlConfig {
                RegionEndpoint = RegionEndpoint.USEast1
            });
            var requestContent = System.Text.Encoding.UTF8.GetString(internalRequest.Content);

            Assert.IsFalse(requestContent.Contains(toEncode));
            Assert.IsTrue(requestContent.Contains(expectedEncoding));
        }
コード例 #2
0
        public void ThrowExceptionGetAccessPointCustomEndpointAndOutpostsCrossRegionRequest()
        {
            var request = new GetAccessPointRequest
            {
                Name = "arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint"
            };

            var config = CreateConfig("https://beta.example.com", Flags.None);

            S3ControlArnTestUtils.RunMockRequest(request, GetAccessPointRequestMarshaller.Instance, config);
        }
コード例 #3
0
        public void ThrowExceptionGetBucketCustomEndpointAndOutpostsDualstackNotSupported()
        {
            var request = new GetBucketRequest
            {
                Bucket = "arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket:mybucket"
            };

            var config = CreateConfig("https://beta.example.com", Flags.Dualstack);

            S3ControlArnTestUtils.RunMockRequest(request, GetBucketRequestMarshaller.Instance, config);
        }
コード例 #4
0
        public void ArnIdSetFieldIdNotSet()
        {
            var outpostArn      = "arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket:mybucket";
            var s3ControlConfig = new AmazonS3ControlConfig
            {
                UseArnRegion   = true,
                RegionEndpoint = RegionEndpoint.USWest2
            };
            var getBucketRequest = new GetBucketRequest
            {
                Bucket = outpostArn
            };
            var marshalledRequest = S3ControlArnTestUtils.RunMockRequest(getBucketRequest, GetBucketRequestMarshaller.Instance, s3ControlConfig);

            Assert.AreEqual("123456789012", marshalledRequest.Headers["x-amz-account-id"]);
        }
コード例 #5
0
        public void OutpostsBucketInputUSWest2UseArnRegionFalse()
        {
            var outpostsBucketArn = "arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket:mybucket";
            var s3ControlConfig   = new AmazonS3ControlConfig
            {
                RegionEndpoint = RegionEndpoint.USWest2
            };
            var getBucketRequest = new GetBucketRequest
            {
                Bucket = outpostsBucketArn
            };
            var marshalledRequest = S3ControlArnTestUtils.RunMockRequest(getBucketRequest, GetBucketRequestMarshaller.Instance, s3ControlConfig);

            Assert.AreEqual(new Uri("https://s3-outposts.us-west-2.amazonaws.com"), marshalledRequest.Endpoint);
            Assert.AreEqual("op-01234567890123456", marshalledRequest.Headers[HeaderKeys.XAmzOutpostId]);
            Assert.AreEqual("123456789012", marshalledRequest.Headers[HeaderKeys.XAmzAccountId]);
        }
コード例 #6
0
        public void ListRegionalBucketsTest()
        {
            var s3ControlConfig = new AmazonS3ControlConfig
            {
                RegionEndpoint = RegionEndpoint.USWest2
            };
            var listRegionalBucketsRequest = new ListRegionalBucketsRequest
            {
                OutpostId = "op-01234567890123456",
                AccountId = "123456789012"
            };
            var marshalledRequest = S3ControlArnTestUtils.RunMockRequest(listRegionalBucketsRequest, ListRegionalBucketsRequestMarshaller.Instance, s3ControlConfig);

            Assert.AreEqual(new Uri("https://s3-outposts.us-west-2.amazonaws.com"), marshalledRequest.Endpoint);
            Assert.AreEqual("op-01234567890123456", marshalledRequest.Headers["x-amz-outpost-id"]);
            Assert.AreEqual("123456789012", marshalledRequest.Headers["x-amz-account-id"]);
        }
コード例 #7
0
        public void ListAccessPointsTest()
        {
            var bucketArn       = "arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket:mybucket";
            var s3ControlConfig = new AmazonS3ControlConfig
            {
                RegionEndpoint = RegionEndpoint.USWest2
            };
            var listAccessPointsRequest = new ListAccessPointsRequest
            {
                Bucket = bucketArn
            };
            var marshalledRequest = S3ControlArnTestUtils.RunMockRequest(listAccessPointsRequest, ListAccessPointsRequestMarshaller.Instance, s3ControlConfig);

            Assert.AreEqual(new Uri("https://s3-outposts.us-west-2.amazonaws.com"), marshalledRequest.Endpoint);
            Assert.AreEqual("op-01234567890123456", marshalledRequest.Headers["x-amz-outpost-id"]);
            Assert.AreEqual("123456789012", marshalledRequest.Headers["x-amz-account-id"]);
        }
コード例 #8
0
        public void ArnIdNotSetFieldIdSet()
        {
            var accessPoint     = "myAccessPoint";
            var s3ControlConfig = new AmazonS3ControlConfig
            {
                UseArnRegion   = true,
                RegionEndpoint = RegionEndpoint.USWest2
            };
            var getAccessPointRequest = new GetAccessPointRequest
            {
                Name      = accessPoint,
                AccountId = "123456789012"
            };
            var marshalledRequest = S3ControlArnTestUtils.RunMockRequest(getAccessPointRequest, GetAccessPointRequestMarshaller.Instance, s3ControlConfig);

            Assert.AreEqual("123456789012", marshalledRequest.Headers["x-amz-account-id"]);
        }
コード例 #9
0
        public void OutpostsBucketInputUSGovEast1UseArnRegionTrueSystemFips()
        {
            var outpostsBucketArn = "arn:aws-us-gov:s3-outposts:us-gov-east-1:123456789012:outpost:op-01234567890123456:bucket:mybucket";
            var s3ControlConfig   = new AmazonS3ControlConfig
            {
                RegionEndpoint = RegionEndpoint.GetBySystemName("fips-us-gov-east-1"),
                UseArnRegion   = true
            };
            var getBucketRequest = new GetBucketRequest
            {
                Bucket = outpostsBucketArn
            };
            var marshalledRequest = S3ControlArnTestUtils.RunMockRequest(getBucketRequest, GetBucketRequestMarshaller.Instance, s3ControlConfig);

            Assert.AreEqual(new Uri("https://s3-outposts.us-gov-east-1.amazonaws.com"), marshalledRequest.Endpoint);
            Assert.AreEqual("op-01234567890123456", marshalledRequest.Headers[HeaderKeys.XAmzOutpostId]);
            Assert.AreEqual("123456789012", marshalledRequest.Headers[HeaderKeys.XAmzAccountId]);
        }
コード例 #10
0
        public void CreateBucketTest()
        {
            var bucketName      = "testBucket";
            var s3ControlConfig = new AmazonS3ControlConfig
            {
                UseArnRegion   = false,
                RegionEndpoint = RegionEndpoint.USWest2
            };
            var createBucketRequest = new CreateBucketRequest
            {
                Bucket    = bucketName,
                OutpostId = "op-01234567890123456"
            };
            var marshalledRequest = S3ControlArnTestUtils.RunMockRequest(createBucketRequest, CreateBucketRequestMarshaller.Instance, s3ControlConfig);

            Assert.AreEqual(new Uri("https://s3-outposts.us-west-2.amazonaws.com"), marshalledRequest.Endpoint);
            Assert.AreEqual("op-01234567890123456", marshalledRequest.Headers["x-amz-outpost-id"]);
        }
コード例 #11
0
        public void ArnIdNotSetFieldIdNotSetException()
        {
            var outpostAccessPointName = "myAccessPoint";
            var s3ControlConfig        = new AmazonS3ControlConfig
            {
                UseArnRegion   = true,
                RegionEndpoint = RegionEndpoint.USWest2
            };
            var getBucketRequest = new GetBucketRequest
            {
                Bucket = outpostAccessPointName,
            };
            var exception = Assert.ThrowsException <AmazonS3ControlException>(() => {
                S3ControlArnTestUtils.RunMockRequest(getBucketRequest, GetBucketRequestMarshaller.Instance, s3ControlConfig);
            });

            Assert.AreEqual("AccountId can only contain alphanumeric characters and dashes and must be between 1 and 63 characters long.", exception.Message);
        }
コード例 #12
0
        public void OutpostsBucketInputUSWest2UseArnRegionTrueInvalidArnException(string outpostsBucketArn)
        {
            var s3ControlConfig = new AmazonS3ControlConfig
            {
                RegionEndpoint = RegionEndpoint.USWest2,
                UseArnRegion   = true
            };
            var getBucketRequest = new GetBucketRequest
            {
                Bucket = outpostsBucketArn
            };
            var exception = Assert.ThrowsException <AmazonClientException>(() =>
            {
                S3ControlArnTestUtils.RunMockRequest(getBucketRequest, GetBucketRequestMarshaller.Instance, s3ControlConfig);
            });

            Assert.AreEqual("Invalid ARN, outpost resource format is incorrect", exception.Message);
        }
コード例 #13
0
        public void OutpostsAccessPointInputUSEast1UseArnRegionTrue()
        {
            var outpostsAccessPointArn = "arn:aws:s3-outposts:us-east-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint";
            var s3ControlConfig        = new AmazonS3ControlConfig
            {
                RegionEndpoint = RegionEndpoint.USWest2,
                UseArnRegion   = true
            };
            var getAccessPointRequest = new GetAccessPointRequest
            {
                Name = outpostsAccessPointArn
            };
            var marshalledRequest = S3ControlArnTestUtils.RunMockRequest(getAccessPointRequest, GetAccessPointRequestMarshaller.Instance, s3ControlConfig);

            Assert.AreEqual(new Uri("https://s3-outposts.us-east-1.amazonaws.com"), marshalledRequest.Endpoint);
            Assert.AreEqual("op-01234567890123456", marshalledRequest.Headers[HeaderKeys.XAmzOutpostId]);
            Assert.AreEqual("123456789012", marshalledRequest.Headers[HeaderKeys.XAmzAccountId]);
        }
コード例 #14
0
        public void OutpostsBucketInputUSGovEast1UseArnRegionTrueFipsException()
        {
            var outpostsBucketArn = "arn:aws-us-gov:s3-outposts:fips-us-gov-east-1:123456789012:outpost:op-01234567890123456:bucket:mybucket";
            var s3ControlConfig   = new AmazonS3ControlConfig
            {
                RegionEndpoint = RegionEndpoint.GetBySystemName("fips-us-gov-east-1"),
                UseArnRegion   = true
            };
            var getBucketRequest = new GetBucketRequest
            {
                Bucket = outpostsBucketArn
            };
            var exception = Assert.ThrowsException <AmazonClientException>(() =>
            {
                S3ControlArnTestUtils.RunMockRequest(getBucketRequest, GetBucketRequestMarshaller.Instance, s3ControlConfig);
            });

            Assert.AreEqual("Invalid configuration Outpost Buckets do not support Fips- regions", exception.Message);
        }
コード例 #15
0
        public void OutpostsAccessPointInputCNNorth1UseArnRegionTrueCrossPartitionError()
        {
            var outpostsAccessPointArn = "arn:aws-cn:s3-outposts:cn-north-1:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint";
            var s3ControlConfig        = new AmazonS3ControlConfig
            {
                RegionEndpoint = RegionEndpoint.USWest2,
                UseArnRegion   = true
            };
            var getAccessPointRequest = new GetAccessPointRequest
            {
                Name = outpostsAccessPointArn
            };
            var exception = Assert.ThrowsException <AmazonClientException>(() =>
            {
                S3ControlArnTestUtils.RunMockRequest(getAccessPointRequest, GetAccessPointRequestMarshaller.Instance, s3ControlConfig);
            });

            Assert.AreEqual("Invalid configuration, cross partition Outpost Access Point ARN", exception.Message);
        }
コード例 #16
0
        public void ArnIdNotSetFieldIdNotSetInvalidArnException()
        {
            var accessPointName = "arn:aws:s3-outposts:us-west-2::outpost:op-01234567890123456:bucket:mybucket";
            var s3ControlConfig = new AmazonS3ControlConfig
            {
                UseArnRegion   = true,
                RegionEndpoint = RegionEndpoint.USWest2
            };
            var getAccessPointRequest = new GetAccessPointRequest
            {
                Name = accessPointName
            };
            var exception = Assert.ThrowsException <AmazonClientException>(() =>
            {
                S3ControlArnTestUtils.RunMockRequest(getAccessPointRequest, GetAccessPointRequestMarshaller.Instance, s3ControlConfig);
            });

            Assert.AreEqual("Invalid ARN, Account ID not set", exception.Message);
        }
コード例 #17
0
        public void OutpostsBucketInputUSEast1UseArnRegionFalseCrossRegionError()
        {
            var outpostsBucketArn = "arn:aws:s3-outposts:us-east-1:123456789012:outpost:op-01234567890123456:bucket:mybucket";
            var s3ControlConfig   = new AmazonS3ControlConfig
            {
                RegionEndpoint = RegionEndpoint.USWest2,
                UseArnRegion   = false
            };
            var getBucketRequest = new GetBucketRequest
            {
                Bucket = outpostsBucketArn
            };
            var exception = Assert.ThrowsException <AmazonClientException>(() =>
            {
                S3ControlArnTestUtils.RunMockRequest(getBucketRequest, GetBucketRequestMarshaller.Instance, s3ControlConfig);
            });

            Assert.AreEqual("Invalid configuration, cross region Outpost Bucket ARN", exception.Message);
        }
コード例 #18
0
        public void ArnIdSetFieldIdSetMismatchException()
        {
            var accessPointName = "arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket:mybucket";
            var s3ControlConfig = new AmazonS3ControlConfig
            {
                UseArnRegion   = true,
                RegionEndpoint = RegionEndpoint.USWest2
            };
            var getAccessPointRequest = new GetAccessPointRequest
            {
                AccountId = "923456789012",
                Name      = accessPointName
            };
            var exception = Assert.ThrowsException <AmazonClientException>(() =>
            {
                S3ControlArnTestUtils.RunMockRequest(getAccessPointRequest, GetAccessPointRequestMarshaller.Instance, s3ControlConfig);
            });

            Assert.AreEqual("Account ID mismatch, the Account ID cannot be specified in an ARN and in the accountId field", exception.Message);
        }
コード例 #19
0
        public void OutpostsBucketInputUSWest2UseArnRegionTrueDualstackException()
        {
            var outpostsBucketArn = "arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket:mybucket";
            var s3ControlConfig   = new AmazonS3ControlConfig
            {
                RegionEndpoint       = RegionEndpoint.USWest2,
                UseDualstackEndpoint = true,
                UseArnRegion         = true
            };
            var getBucketRequest = new GetBucketRequest
            {
                Bucket = outpostsBucketArn
            };
            var exception = Assert.ThrowsException <AmazonClientException>(() =>
            {
                S3ControlArnTestUtils.RunMockRequest(getBucketRequest, GetBucketRequestMarshaller.Instance, s3ControlConfig);
            });

            Assert.AreEqual("Invalid configuration Outpost Buckets do not support dualstack", exception.Message);
        }
コード例 #20
0
        public void TestS3OutpostsSignerGetBucket()
        {
            var signer = new S3Signer();

            var bucketArn        = "arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket:mybucket";
            var getBucketRequest = new GetBucketRequest
            {
                Bucket = bucketArn
            };
            var config = new AmazonS3ControlConfig
            {
                UseArnRegion   = true,
                RegionEndpoint = RegionEndpoint.USWest2
            };
            var originalAuthService = config.AuthenticationServiceName;
            var iRequest            = S3ControlArnTestUtils.RunMockRequest(getBucketRequest, GetBucketRequestMarshaller.Instance, config);

            signer.Sign(iRequest, config, new RequestMetrics(), new ImmutableCredentials("ACCESS", "SECRET", ""));
            Assert.IsTrue(iRequest.Headers.ContainsKey(HeaderKeys.AuthorizationHeader));
            Assert.IsTrue((iRequest.Headers["Authorization"]).Contains("s3-outposts"));
            Assert.IsTrue(config.AuthenticationServiceName == originalAuthService);
        }
コード例 #21
0
        public void TestS3OutpostsSignerCreateAccessPointWithArn()
        {
            var signer = new S3Signer();
            var createAccessPointRequest = new CreateAccessPointRequest
            {
                Bucket = "arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:bucket:mybucket",
                Name   = "myaccesspoint",
            };
            var config = new AmazonS3ControlConfig
            {
                UseArnRegion   = true,
                RegionEndpoint = RegionEndpoint.USWest2
            };
            var originalAuthService = config.AuthenticationServiceName;
            var iRequest            = S3ControlArnTestUtils.RunMockRequest(createAccessPointRequest, CreateAccessPointRequestMarshaller.Instance, config);

            signer.Sign(iRequest, config, new RequestMetrics(), "ACCESS", "SECRET");

            Assert.IsTrue(iRequest.Headers.ContainsKey(HeaderKeys.AuthorizationHeader));
            Assert.IsTrue((iRequest.Headers["Authorization"]).Contains("s3-outposts"));
            Assert.IsTrue(config.AuthenticationServiceName == originalAuthService);
        }
コード例 #22
0
        private void RunTestRequest(AmazonWebServiceRequest request, IMarshaller <IRequest, AmazonWebServiceRequest> marshaller,
                                    bool isArn, string serviceUrl, Flags flags,
                                    string expectedUri, string expectedRegion, string expectedService)
        {
            var clientConfig = CreateConfig(serviceUrl, flags);

            var internalRequest = S3ControlArnTestUtils.RunMockRequest(request, marshaller, clientConfig);

            Assert.AreEqual(new Uri(expectedUri), internalRequest.Endpoint);

            if (isArn)
            {
                Assert.AreEqual(expectedRegion, internalRequest.AuthenticationRegion);
                Assert.AreEqual(expectedService, internalRequest.OverrideSigningServiceName);
            }

            var service       = DetermineService(clientConfig);
            var signingRegion = AWS4Signer.DetermineSigningRegion(clientConfig, service, internalRequest.AlternateEndpoint, internalRequest);

            Assert.AreEqual(expectedRegion, signingRegion);
            Assert.AreEqual(expectedService, internalRequest.OverrideSigningServiceName ?? service);
        }
コード例 #23
0
        public void TestS3OutpostsSignerCreateBucket()
        {
            var signer = new S3Signer();

            var createBucketRequest = new CreateBucketRequest
            {
                Bucket    = "test",
                OutpostId = "op-123456789012"
            };
            var config = new AmazonS3ControlConfig
            {
                SignatureVersion = "4",
                UseArnRegion     = true,
                RegionEndpoint   = RegionEndpoint.USWest2
            };
            var originalAuthService = config.AuthenticationServiceName;
            var iRequest            = S3ControlArnTestUtils.RunMockRequest(createBucketRequest, CreateBucketRequestMarshaller.Instance, config);

            signer.Sign(iRequest, config, new RequestMetrics(), new ImmutableCredentials("ACCESS", "SECRET", ""));
            Assert.IsTrue(iRequest.Headers.ContainsKey(HeaderKeys.AuthorizationHeader));
            Assert.IsTrue((iRequest.Headers["Authorization"]).Contains("s3-outposts"));
            Assert.IsTrue(config.AuthenticationServiceName == originalAuthService);
        }
コード例 #24
0
        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);
            }
        }