Ejemplo n.º 1
0
        public void GetCredentialFileAlibabaCloudCredentialWithEnvDefinedButNotFoundTest()
        {
            DefaultProfile profile = DefaultProfile.GetProfile();

            Environment.SetEnvironmentVariable("ALIBABA_CLOUD_CREDENTIALS_FILE", "D://credentials1.ini");

            Core.Auth.Provider.DefaultCredentialProvider defaultCredentialProvider = new Core.Auth.Provider.DefaultCredentialProvider(profile);

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

            Assert.Equal("Invalid credentials file: D://credentials1.ini", exception.Message);
            Environment.SetEnvironmentVariable("ALIBABA_CLOUD_CREDENTIALS_FILE", null);
        }
Ejemplo n.º 2
0
        public void GetEnvironmentAlibabaCloudCredentialUseChain()
        {
            DefaultProfile profile = DefaultProfile.GetProfile();

            profile.DefaultClientName = "default";

            TestHelper.InitializeEnvironmentValue();

            Core.Auth.Provider.DefaultCredentialProvider defaultCredentialProvider = new Core.Auth.Provider.DefaultCredentialProvider(profile);
            var credential = (AccessKeyCredential)defaultCredentialProvider.GetAlibabaCloudClientCredential();

            Assert.NotNull(credential);
            Assert.Equal("ACCESS_KEY_ID", credential.GetAccessKeyId());

            TestHelper.RemoveEnvironmentValue();
        }
Ejemplo n.º 3
0
        public void GetCredentialFileAlibabaCloudCredentialWithBearerToken()
        {
            DefaultProfile profile = DefaultProfile.GetProfile();

            profile.DefaultClientName = "default";
            Core.Auth.Provider.DefaultCredentialProvider defaultCredentialProvider = new Core.Auth.Provider.DefaultCredentialProvider(profile);
            var homePath = defaultCredentialProvider.GetHomePath();

            TestHelper.CreateIniFileWithBearerToken(homePath);

            var credential = (BearerTokenCredential)defaultCredentialProvider.GetAlibabaCloudClientCredential();

            TestHelper.DeleteIniFile(homePath);
            Assert.NotNull(credential);
            Assert.Null(credential.GetAccessKeyId());
            Assert.Null(credential.GetAccessKeySecret());
        }