public async Task RamRoleArnProviderAsyncTest()
        {
            Config config = new Config()
            {
                AccessKeyId = "accessKeyId", AccessKeySecret = "accessKeySecret", RoleArn = "roleArn"
            };
            RamRoleArnCredentialProvider provider = new RamRoleArnCredentialProvider(config);

            Assert.NotNull(provider);

            provider = new RamRoleArnCredentialProvider("accessKeyID", "accessKeySecret", "roleSessionName", "roleArn", "regionId", "policy");
            await Assert.ThrowsAsync <CredentialException>(async() => { await provider.GetCredentialsAsync(); });

            Mock <IConnClient> mock     = new Mock <IConnClient>();
            HttpResponse       response = new HttpResponse("http://www.aliyun.com")
            {
                Status   = 200,
                Encoding = "UTF-8",
                Content  = Encoding.UTF8.GetBytes("{\"Credentials\":{\"Expiration\":\"2019-01-01T1:1:1Z\",\"AccessKeyId\":\"test\"," +
                                                  "\"AccessKeySecret\":\"test\",\"SecurityToken\":\"test\"}}")
            };

            mock.Setup(p => p.DoActionAsync(It.IsAny <HttpRequest>())).ReturnsAsync(response);
            Assert.IsType <RamRoleArnCredential>(TestHelper.RunInstanceMethodAsync(typeof(RamRoleArnCredentialProvider), "CreateCredentialAsync", provider, new object[] { mock.Object }));

            Mock <IAlibabaCloudCredentialsProvider> mockProvider = new Mock <IAlibabaCloudCredentialsProvider>();

            mockProvider.Setup(p => p.GetCredentialsAsync()).ReturnsAsync(new RamRoleArnCredential("accessKeyId", "accessKeySecret", "securityToken", 64090527132000L, null));
            RamRoleArnCredential credentialMock = new RamRoleArnCredential("accessKeyId", "accessKeySecret", "securityToken", 1000L, mockProvider.Object);
            await credentialMock.RefreshCredentialAsync();

            Assert.NotNull(credentialMock);
        }
Exemplo n.º 2
0
        public async Task RamRoleArnAsyncTest()
        {
            Mock <IAlibabaCloudCredentialsProvider> mockProvider = new Mock <IAlibabaCloudCredentialsProvider>();

            mockProvider.Setup(p => p.GetCredentialsAsync()).ReturnsAsync(new RamRoleArnCredential("accessKeyId", "accessKeySecret", "securityToken", 10000, null));
            RamRoleArnCredential ramRoleArnCredential = new RamRoleArnCredential("accessKeyId", "accessKeySecret", "securityToken", 64090527132000L, mockProvider.Object);

            Assert.Equal("accessKeyId", await ramRoleArnCredential.GetAccessKeyIdAsync());
            Assert.Equal("accessKeySecret", await ramRoleArnCredential.GetAccessKeySecretAsync());
            Assert.Equal("securityToken", await ramRoleArnCredential.GetSecurityTokenAsync());
            Assert.Equal(64090527132000L, await ramRoleArnCredential.GetExpirationAsync());
            Assert.Equal(AuthConstant.RamRoleArn, await ramRoleArnCredential.GetCredentialTypeAsync());
            Assert.NotNull(await ramRoleArnCredential.GetNewCredentialAsync <RamRoleArnCredential>());

            await ramRoleArnCredential.RefreshCredentialAsync();

            Assert.NotNull(ramRoleArnCredential);
        }