Ejemplo 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 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());
        }
Ejemplo n.º 2
0
        public BasicSessionCredentials GetNewSessionCredentials()
        {
            GetSessionAccessKeyRequest request = new GetSessionAccessKeyRequest();

            request.PublicKeyId     = rsaKeyPairCredential.GetAccessKeyId();
            request.DurationSeconds = (int)sessionDurationSeconds;
            request.Protocol        = ProtocolType.HTTPS;

            GetSessionAccessKeyResponse response = this.stsClient.GetAcsResponse(request);

            return(new BasicSessionCredentials(
                       response.SessionAccesskey.SessionAccessKeyId,
                       response.SessionAccesskey.SessionAccessKeySecert,
                       null,
                       sessionDurationSeconds
                       ));
        }
Ejemplo n.º 3
0
        public void GetCredentials()
        {
            var mockRsaPairCredential = new Mock <KeyPairCredentials>("publicKeyId", "privateKeyFile");
            var rsaPairCredential     = mockRsaPairCredential.Object;

            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 instance = new Core.Auth.Provider.RsaKeyPairCredentialProvider(rsaPairCredential, client);

            Assert.NotNull(instance.GetCredentials());
        }
        public void GetSessionAccessKeyResponseUnmarshallTest()
        {
            UnmarshallerContext unmarshallerContext = new UnmarshallerContext();

            if (unmarshallerContext.ResponseDictionary == null)
            {
                unmarshallerContext.ResponseDictionary = new Dictionary <string, string>
                {
                    { "GetSessionAccessKey.RequestId", "RequestId" },
                    { "GetSessionAccessKey.SessionAccessKey.SessionAccessKeyId", "SessionAccessKeyId" },
                    { "GetSessionAccessKey.SessionAccessKey.SessionAccessKeySecret", "SessionAccessKeySecret" },
                    { "GetSessionAccessKey.SessionAccessKey.Expiration", "100" }
                };
            }

            GetSessionAccessKeyResponse response = GetSessionAccessKeyResponseUnmarshaller.Unmarshall(unmarshallerContext);

            Assert.Equal("RequestId", response.RequestId);
            Assert.Equal("SessionAccessKeyId", response.SessionAccesskey.SessionAccessKeyId);
            Assert.Equal("SessionAccessKeySecret", response.SessionAccesskey.SessionAccessKeySecert);
            Assert.Equal("100", response.SessionAccesskey.Expiration);
        }