Пример #1
0
        public void GetRsaKeyPairAlibabaCloudCredential()
        {
            Environment.SetEnvironmentVariable("ALIBABA_CLOUD_REGION_ID", "region_id");

            var response = new GetSessionAccessKeyResponse();

            response.SessionAccesskey = new GetSessionAccessKeyResponse.GetSessionAccessKey_SessionAccesskey();
            response.SessionAccesskey.SessionAccessKeyId     = "ak";
            response.SessionAccesskey.SessionAccessKeySecert = "aks";

            var mockClient = new Mock <IAcsClient>();

            mockClient.Setup(x => x.GetAcsResponse(It.IsAny <AcsRequest <GetSessionAccessKeyResponse> >())).Returns(response);
            var client = mockClient.Object;

            var basicSessionCredential = new BasicSessionCredentials("accessKey", "aks", "sessionToken");
            var rsaKeyCredential       = new RsaKeyPairCredential("publicKey", "privateKey");
            var profile = DefaultProfile.GetProfile();

            var rsaProvider = new Core.Auth.Provider.RsaKeyPairCredentialProvider(rsaKeyCredential, client);

            var defaultCredentialProvider = new Core.Auth.Provider.DefaultCredentialProvider(profile, rsaProvider, "publicKeyId", "privateKeyFile");

            var actualCredentil = defaultCredentialProvider.GetRsaKeyPairAlibabaCloudCredential();

            Environment.SetEnvironmentVariable("ALIBABA_CLOUD_REGION_ID", null);
            Assert.NotNull(actualCredentil);
            Assert.Equal("aks", actualCredentil.GetAccessKeySecret());
        }
Пример #2
0
        public void GetRsaKeyPairAlibabaCloudCredentialWithException()
        {
            var profile = DefaultProfile.GetProfile();
            var defaultCredentialProvider = new Core.Auth.Provider.DefaultCredentialProvider(profile, null);

            var exception = Assert.Throws <ClientException>(() =>
            {
                var credential = defaultCredentialProvider.GetRsaKeyPairAlibabaCloudCredential();
            });

            Assert.Equal("Missing required variable option for 'default Client'", exception.Message);
        }