public void GetRamRoleArnAlibabaCloudCredential() { TestHelper.InitializeEnvironmentValue(); var ramRoleCredential = new RamRoleArnCredential("accessKey", "aks", "roleArn", "roleSession", "roletoken", 3000); var profile = DefaultProfile.GetProfile(); var response = new AssumeRoleResponse(); response.Credentials = new AssumeRoleResponse.AssumeRole_Credentials(); response.Credentials.AccessKeyId = "ak"; response.Credentials.AccessKeySecret = "aks"; response.Credentials.SecurityToken = "token"; var mockClient = new Mock <IAcsClient>(); mockClient.Setup(x => x.GetAcsResponse(It.IsAny <AcsRequest <AssumeRoleResponse> >())).Returns(response); var client = mockClient.Object; var stsProvider = new STSAssumeRoleSessionCredentialsProvider(ramRoleCredential, "roleArn", client); var defaultCredentialProvider = new Core.Auth.Provider.DefaultCredentialProvider(profile, stsProvider); var actualCredentil = defaultCredentialProvider.GetRamRoleArnAlibabaCloudCredential(); TestHelper.RemoveEnvironmentValue(); Assert.NotNull(actualCredentil); Assert.Equal("aks", actualCredentil.GetAccessKeySecret()); }
public void GetRamRoleArnAlibabaCloudCredentialWithException() { var profile = DefaultProfile.GetProfile(); var defaultCredentialProvider = new Core.Auth.Provider.DefaultCredentialProvider(profile, null); var exception = Assert.Throws <ClientException>(() => { var credential = defaultCredentialProvider.GetRamRoleArnAlibabaCloudCredential(); }); Assert.Equal("Missing required variable option for 'default Client'", exception.Message); }