19
19
package org .apache .hadoop .fs .aliyun .oss ;
20
20
21
21
import com .aliyun .oss .common .auth .Credentials ;
22
- import com .aliyun .oss .common .auth .CredentialsProvider ;
23
22
import com .aliyun .oss .common .auth .InvalidCredentialsException ;
24
23
import org .apache .hadoop .conf .Configuration ;
25
24
import org .apache .hadoop .fs .aliyun .oss .contract .AliyunOSSContract ;
28
27
import org .junit .Test ;
29
28
30
29
import java .io .IOException ;
31
- import java .lang .reflect .InvocationTargetException ;
32
- import java .net .URI ;
33
30
34
31
import static org .apache .hadoop .fs .aliyun .oss .Constants .ACCESS_KEY_ID ;
35
32
import static org .apache .hadoop .fs .aliyun .oss .Constants .ACCESS_KEY_SECRET ;
36
- import static org .apache .hadoop .fs .aliyun .oss .Constants .ASSUMED_ROLE_SESSION_NAME ;
37
- import static org .apache .hadoop .fs .aliyun .oss .Constants .ASSUMED_ROLE_STS_ENDPOINT ;
38
- import static org .apache .hadoop .fs .aliyun .oss .Constants .CREDENTIALS_PROVIDER_KEY ;
39
- import static org .apache .hadoop .fs .aliyun .oss .Constants .ROLE_ARN ;
40
33
import static org .apache .hadoop .fs .aliyun .oss .Constants .SECURITY_TOKEN ;
41
34
42
35
/**
@@ -70,54 +63,16 @@ public void testCredentialMissingAccessKeySecret() throws Throwable {
70
63
validateCredential (conf );
71
64
}
72
65
73
- @ Test
74
- public void testCredentialMissingRoleArn () throws Throwable {
75
- Configuration conf = new Configuration ();
76
- conf .set (CREDENTIALS_PROVIDER_KEY , AssumedRoleCredentialProvider .NAME );
77
- conf .set (ROLE_ARN , "" );
78
- validateCredential (conf );
79
- }
80
-
81
- @ Test
82
- public void testCredentialMissingStsEndpoint () throws Throwable {
83
- Configuration conf = new Configuration ();
84
- conf .set (CREDENTIALS_PROVIDER_KEY , AssumedRoleCredentialProvider .NAME );
85
- conf .set (ASSUMED_ROLE_STS_ENDPOINT , "" );
86
- validateCredential (conf );
87
- }
88
-
89
- @ Test
90
- public void testCredentialInvalidSessionName () throws Throwable {
91
- Configuration conf = new Configuration ();
92
- conf .set (CREDENTIALS_PROVIDER_KEY , AssumedRoleCredentialProvider .NAME );
93
- conf .set (ASSUMED_ROLE_SESSION_NAME , "hadoop oss" );
94
- validateCredential (conf );
95
- }
96
-
97
- private void validateCredential (URI uri , Configuration conf ) {
66
+ private void validateCredential (Configuration conf ) {
98
67
try {
99
- CredentialsProvider provider =
100
- AliyunOSSUtils . getCredentialsProvider ( uri , conf );
68
+ AliyunCredentialsProvider provider
69
+ = new AliyunCredentialsProvider ( conf );
101
70
Credentials credentials = provider .getCredentials ();
102
71
fail ("Expected a CredentialInitializationException, got " + credentials );
103
72
} catch (InvalidCredentialsException expected ) {
104
73
// expected
105
74
} catch (IOException e ) {
106
- Throwable cause = e .getCause ();
107
- if (cause instanceof InvocationTargetException ) {
108
- boolean isInstance =
109
- ((InvocationTargetException )cause ).getTargetException ()
110
- instanceof InvalidCredentialsException ;
111
- if (!isInstance ) {
112
- fail ("Unexpected exception." );
113
- }
114
- } else {
115
- fail ("Unexpected exception." );
116
- }
75
+ fail ("Unexpected exception." );
117
76
}
118
77
}
119
-
120
- private void validateCredential (Configuration conf ) {
121
- validateCredential (null , conf );
122
- }
123
- }
78
+ }
0 commit comments