2
2
3
3
import com .aliyuncs .exceptions .ClientException ;
4
4
import com .aliyuncs .utils .AuthUtils ;
5
+ import com .aliyuncs .utils .EnvHelper ;
6
+
5
7
import org .junit .Assert ;
6
8
import org .junit .Test ;
7
9
@@ -23,7 +25,7 @@ public void userConfigurationProvidersTest() {
23
25
@ Test
24
26
public void getCredentialsTest () throws ClientException {
25
27
DefaultCredentialsProvider provider = new DefaultCredentialsProvider ();
26
- AuthUtils . setEnvironmentECSMetaData ( "" );
28
+ EnvHelper . setenv ( "ALIBABA_CLOUD_ECS_METADATA" , "" );
27
29
try {
28
30
new DefaultCredentialsProvider ();
29
31
Assert .fail ();
@@ -32,8 +34,8 @@ public void getCredentialsTest() throws ClientException {
32
34
e .getMessage ());
33
35
}
34
36
35
- AuthUtils . setEnvironmentAccessKeyId ( "test" );
36
- AuthUtils . setEnvironmentAccessKeySecret ( "test" );
37
+ EnvHelper . setenv ( "ALIBABA_CLOUD_ACCESS_KEY_ID" , "test" );
38
+ EnvHelper . setenv ( "ALIBABA_CLOUD_ACCESS_KEY_SECRET" , "test" );
37
39
AlibabaCloudCredentials credential = provider .getCredentials ();
38
40
Assert .assertTrue (credential instanceof BasicCredentials );
39
41
@@ -53,11 +55,11 @@ public AlibabaCloudCredentials getCredentials() {
53
55
Assert .assertTrue (credential instanceof BasicCredentials );
54
56
55
57
DefaultCredentialsProvider .clearCredentialsProvider ();
56
- AuthUtils . setEnvironmentECSMetaData ( null );
57
- AuthUtils . setEnvironmentAccessKeyId ( null );
58
- AuthUtils . setEnvironmentAccessKeySecret ( null );
58
+ EnvHelper . setenv ( "ALIBABA_CLOUD_ECS_METADATA" , null );
59
+ EnvHelper . setenv ( "ALIBABA_CLOUD_ACCESS_KEY_ID" , null );
60
+ EnvHelper . setenv ( "ALIBABA_CLOUD_ACCESS_KEY_SECRET" , null );
59
61
System .setProperty (AuthConstant .SYSTEM_ACCESSKEYID , "" );
60
- AuthUtils . setEnvironmentCredentialsFile ( null );
62
+ EnvHelper . setenv ( "ALIBABA_CLOUD_CREDENTIALS_FILE" , null );
61
63
try {
62
64
provider .getCredentials ();
63
65
} catch (ClientException e ) {
@@ -68,15 +70,15 @@ public AlibabaCloudCredentials getCredentials() {
68
70
@ Test
69
71
public void defaultCredentialsProviderTest () throws ClientException {
70
72
DefaultCredentialsProvider .clearCredentialsProvider ();
71
- AuthUtils . setEnvironmentECSMetaData ( "test" );
72
- AuthUtils . setEnvironmentAccessKeyId ( "test" );
73
- AuthUtils . setEnvironmentAccessKeySecret ( "test" );
73
+ EnvHelper . setenv ( "ALIBABA_CLOUD_ECS_METADATA" , "test" );
74
+ EnvHelper . setenv ( "ALIBABA_CLOUD_ACCESS_KEY_ID" , "test" );
75
+ EnvHelper . setenv ( "ALIBABA_CLOUD_ACCESS_KEY_SECRET" , "test" );
74
76
DefaultCredentialsProvider provider = new DefaultCredentialsProvider ();
75
77
DefaultCredentialsProvider .addCredentialsProvider (new SystemPropertiesCredentialsProvider ());
76
78
Assert .assertTrue (provider .getCredentials () instanceof BasicCredentials );
77
- AuthUtils . setEnvironmentECSMetaData ( null );
78
- AuthUtils . setEnvironmentAccessKeyId ( null );
79
- AuthUtils . setEnvironmentAccessKeySecret ( null );
79
+ EnvHelper . setenv ( "ALIBABA_CLOUD_ECS_METADATA" , null );
80
+ EnvHelper . setenv ( "ALIBABA_CLOUD_ACCESS_KEY_ID" , null );
81
+ EnvHelper . setenv ( "ALIBABA_CLOUD_ACCESS_KEY_SECRET" , null );
80
82
DefaultCredentialsProvider .clearCredentialsProvider ();
81
83
}
82
84
0 commit comments