Ejemplo n.º 1
0
        public void TestAssumeRoleCredentials()
        {
            var          clientId    = Guid.NewGuid();
            var          roleArn     = _role.Arn;
            const string sessionName = "NetUser";

            // sleep for IAM data to propagate
            Thread.Sleep(TimeSpan.FromSeconds(10));
            var sts = new AmazonSecurityTokenServiceClient(_userCredentials);

            Thread.Sleep(TimeSpan.FromSeconds(60));
            var request = new AssumeRoleRequest
            {
                RoleArn         = roleArn,
                RoleSessionName = sessionName,
                DurationSeconds = 3600,
                ExternalId      = clientId.ToString()
            };

            // keep this unit test even though STSAssumeRoleAWSCredentials is obsolete
#pragma warning disable 0618
            var credentials = new STSAssumeRoleAWSCredentials(sts, request);

            var client   = new AmazonIdentityManagementServiceClient(credentials);
            var response = client.ListRoles();
            Assert.IsNotNull(response);
        }
Ejemplo n.º 2
0
        public void TestAssumeRoleCredentials()
        {
            var          clientId    = Guid.NewGuid();
            var          roleArn     = _role.Arn;
            const string sessionName = "NetUser";

            // sleep for IAM data to propagate
            UtilityMethods.Sleep(TimeSpan.FromSeconds(10));
            var sts = new AmazonSecurityTokenServiceClient(_userCredentials);

            UtilityMethods.Sleep(TimeSpan.FromSeconds(60));
            var request = new AssumeRoleRequest
            {
                RoleArn         = roleArn,
                RoleSessionName = sessionName,
                DurationSeconds = 3600,
                ExternalId      = clientId.ToString()
            };

            var credentials = new STSAssumeRoleAWSCredentials(sts, request);

            var client   = new AmazonIdentityManagementServiceClient(credentials);
            var response = client.ListRolesAsync().Result;

            Assert.IsNotNull(response);
        }
Ejemplo n.º 3
0
        public void NoCredentialsOnContext()
        {
            var request = new AssumeRoleRequest()
            {
                DurationSeconds = 0 // invalid value for DurationSeconds - credentials will be null when retrying request
            };
            var credentials = new STSAssumeRoleAWSCredentials(new AmazonSecurityTokenServiceClient(), request);
            var s3Client    = new AmazonS3Client(credentials);

            AssertExtensions.ExpectException(() => { s3Client.ListBuckets(); }, typeof(AmazonSecurityTokenServiceException), new Regex("3 validation errors detected"));
        }
Ejemplo n.º 4
0
        public void NoCredentialsOnContext()
        {
            var request = new AssumeRoleRequest()
            {
                DurationSeconds = 0 // invalid value for DurationSeconds - credentials will be null when retrying request
            };

            // keep this unit test even though STSAssumeRoleAWSCredentials is obsolete
            // the condition it's testing doesn't exist when AssumeRoleAWSCredentials (STSAssumeRoleAWSCredentials's replacement) is used
#pragma warning disable 0618
            var credentials = new STSAssumeRoleAWSCredentials(new AmazonSecurityTokenServiceClient(), request);
            var s3Client    = new AmazonS3Client(credentials);
            AssertExtensions.ExpectException(() => { s3Client.ListBuckets(); }, typeof(AmazonSecurityTokenServiceException), new Regex("3 validation errors detected"));
        }