Esempio n. 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());
        }
        public void RsaKeyPairTest()
        {
            RsaKeyPairCredential rsaKeyPairCredential = new RsaKeyPairCredential("publicKeyId", "privateKeySecret", 10000, null);

            Assert.Equal("publicKeyId", rsaKeyPairCredential.AccessKeyId);
            Assert.Equal("privateKeySecret", rsaKeyPairCredential.AccessKeySecret);
            Assert.Null(rsaKeyPairCredential.SecurityToken);
            Assert.Equal(10000, rsaKeyPairCredential.Expiration);
            Assert.Equal(AuthConstant.RsaKeyPair, rsaKeyPairCredential.CredentialType);
        }
Esempio n. 3
0
        public virtual AlibabaCloudCredentials GetRsaKeyPairAlibabaCloudCredential()
        {
            if (String.IsNullOrEmpty(this.publicKeyId) || String.IsNullOrEmpty(this.privateKeyFile) || String.IsNullOrEmpty(this.regionId))
            {
                throw new ClientException("Missing required variable option for 'default Client'");
            }
            RsaKeyPairCredential         rsaKeyPairCredential = new RsaKeyPairCredential(this.publicKeyId, this.privateKeyFile);
            DefaultProfile               profile           = DefaultProfile.GetProfile(this.regionId, this.publicKeyId, this.privateKeyFile);
            RsaKeyPairCredentialProvider provider          = new RsaKeyPairCredentialProvider(rsaKeyPairCredential, profile);
            BasicSessionCredentials      basicCrededential = (BasicSessionCredentials)provider.GetCredentials();

            return(basicCrededential);
        }
Esempio n. 4
0
        public void RsaKeyPairTestNull()
        {
            Assert.Equal("You must provide a valid pair of Public Key ID and Private Key Secret.",
                         Assert.Throws <InvalidDataException>(() =>
            {
                RsaKeyPairCredential unused = new RsaKeyPairCredential(null, "privateKeySecret", 10000, null);
            }).Message
                         );

            Assert.Equal("You must provide a valid pair of Public Key ID and Private Key Secret.",
                         Assert.Throws <InvalidDataException>(() =>
            {
                RsaKeyPairCredential unused = new RsaKeyPairCredential("publicKeyId", null, 10000, null);
            }).Message
                         );
        }
Esempio n. 5
0
        public async Task RsaKeyPairTest()
        {
            Mock <IAlibabaCloudCredentialsProvider> mockProvider = new Mock <IAlibabaCloudCredentialsProvider>();

            mockProvider.Setup(p => p.GetCredentials()).Returns(new RsaKeyPairCredential("publicKeyId", "privateKeySecret", 1000, null));
            mockProvider.Setup(p => p.GetCredentialsAsync()).ReturnsAsync(new RsaKeyPairCredential("publicKeyId", "privateKeySecret", 1000, null));
            RsaKeyPairCredential rsaKeyPairCredential = new RsaKeyPairCredential("publicKeyId", "privateKeySecret", 64090527132000L, mockProvider.Object);

            Assert.Equal("publicKeyId", rsaKeyPairCredential.GetAccessKeyId());
            Assert.Equal("privateKeySecret", rsaKeyPairCredential.GetAccessKeySecret());
            Assert.Null(rsaKeyPairCredential.GetSecurityToken());
            Assert.Equal(64090527132000, rsaKeyPairCredential.GetExpiration());
            Assert.Equal(AuthConstant.RsaKeyPair, rsaKeyPairCredential.GetCredentialType());

            Assert.Equal("publicKeyId", await rsaKeyPairCredential.GetAccessKeyIdAsync());
            Assert.Equal("privateKeySecret", await rsaKeyPairCredential.GetAccessKeySecretAsync());
            Assert.Null(await rsaKeyPairCredential.GetSecurityTokenAsync());
            Assert.Equal(64090527132000, await rsaKeyPairCredential.GetExpirationAsync());
            Assert.Equal(AuthConstant.RsaKeyPair, await rsaKeyPairCredential.GetCredentialTypeAsync());
        }
Esempio n. 6
0
 public RsaKeyPairCredentialProvider(RsaKeyPairCredential rsaKeyPairCredential, IClientProfile profile)
 {
     this.rsaKeyPairCredential = rsaKeyPairCredential;
     this.stsClient            = new DefaultAcsClient(profile, rsaKeyPairCredential);
 }
 public RsaKeyPairCredentialProvider(RsaKeyPairCredential rsaKeyPairCredential, IAcsClient stsClient)
 {
     this.rsaKeyPairCredential = rsaKeyPairCredential;
     this.stsClient            = stsClient;
 }