Пример #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 KeyPairCredentials("publicKey", "privateKey");
            var profile = DefaultProfile.GetProfile();

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

            var defaultCredentialProvider =
                new DefaultCredentialProvider(profile, "publicKeyId", "privateKeyFile", rsaProvider);

            var actualCredentil = defaultCredentialProvider.GetRsaKeyPairAlibabaCloudCredential();

            Environment.SetEnvironmentVariable("ALIBABA_CLOUD_REGION_ID", null);
            Assert.NotNull(actualCredentil);
            Assert.Equal("aks", actualCredentil.GetAccessKeySecret());
        }
Пример #2
0
        public void GetAccessKeySecret()
        {
            var instance = new KeyPairCredentials("publicKeyId", "privateKeySecret");

            Assert.Equal("privateKeySecret", instance.GetAccessKeySecret());
            Assert.Equal("publicKeyId", instance.GetAccessKeyId());
        }
Пример #3
0
        public void GetAccessKeyId()
        {
            var instance = new KeyPairCredentials("publicKeyId", "privateKeySecret");

            Assert.Equal("publicKeyId", instance.GetAccessKeyId());

            Assert.Throws <ArgumentNullException>(() => { instance = new KeyPairCredentials("publicKeyId", null); });
        }
Пример #4
0
        public void Instance()
        {
            MockSigner instance = new MockSigner();
            var        mock     = new Mock <AlibabaCloudCredentials>();
            AlibabaCloudCredentials credentials = mock.Object;

            Assert.IsType <HmacSHA1Signer>(MockSigner.GetSigner(credentials));

            KeyPairCredentials KeyPairCredentials = new KeyPairCredentials("publicKeyId", "privateKeySecret");

            Assert.IsType <SHA256withRSASigner>(MockSigner.GetSigner(KeyPairCredentials));
        }
Пример #5
0
        public void Instance()
        {
            var instance    = new MockSigner();
            var mock        = new Mock <AlibabaCloudCredentials>();
            var credentials = mock.Object;

            Assert.IsType <HmacSHA1Signer>(Signer.GetSigner(credentials));

            var KeyPairCredentials = new KeyPairCredentials("publicKeyId", "privateKeySecret");

            Assert.IsType <SHA256withRSASigner>(Signer.GetSigner(KeyPairCredentials));

            var bearerTokenCredential = new BearerTokenCredential("FakeBearerToken");

            Assert.IsType <BearerTokenSigner>(Signer.GetSigner(bearerTokenCredential));
        }
        public void GetRsaKeyPairAlibabaCloudCredential2()
        {
            Environment.SetEnvironmentVariable("ALIBABA_CLOUD_REGION_ID", "region_id");

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

            var defaultCredentialProvider = new DefaultCredentialProvider(profile, "publicKeyId", "privateKeyFile", null);

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

            Environment.SetEnvironmentVariable("ALIBABA_CLOUD_REGION_ID", null);
            Assert.Equal("Specified access key is not found.", exception.ErrorMessage);
        }
Пример #7
0
        public virtual AlibabaCloudCredentials GetRsaKeyPairAlibabaCloudCredential()
        {
            if (String.IsNullOrEmpty(publicKeyId) || String.IsNullOrEmpty(privateKeyFile) || String.IsNullOrEmpty(regionId))
            {
                throw new ClientException("Missing required variable option for 'default Client'");
            }
            var rsaKeyPairCredential = new KeyPairCredentials(publicKeyId, privateKeyFile);
            var profile = DefaultProfile.GetProfile(regionId, publicKeyId, privateKeyFile);

            RsaKeyPairCredentialProvider rsaKeyPairCredentialProvider;

            if (null != alibabaCloudCredentialProvider)
            {
                rsaKeyPairCredentialProvider = (RsaKeyPairCredentialProvider)alibabaCloudCredentialProvider;
            }
            else
            {
                rsaKeyPairCredentialProvider = new RsaKeyPairCredentialProvider(rsaKeyPairCredential, profile);
            }

            return(rsaKeyPairCredentialProvider.GetCredentials());
        }
Пример #8
0
 public RsaKeyPairCredentialProvider(KeyPairCredentials rsaKeyPairCredential, IAcsClient stsClient)
 {
     this.rsaKeyPairCredential = rsaKeyPairCredential;
     this.stsClient            = stsClient;
 }
Пример #9
0
 public RsaKeyPairCredentialProvider(KeyPairCredentials rsaKeyPairCredential, IClientProfile profile)
 {
     this.rsaKeyPairCredential = rsaKeyPairCredential;
     stsClient = new DefaultAcsClient(profile, rsaKeyPairCredential);
 }