|
20 | 20 |
|
21 | 21 | import static org.assertj.core.api.Assertions.assertThat;
|
22 | 22 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
| 23 | +import static org.assertj.core.api.InstanceOfAssertFactories.type; |
23 | 24 | import static org.mockito.ArgumentMatchers.any;
|
24 | 25 | import static org.mockito.Mockito.when;
|
25 | 26 |
|
26 | 27 | import java.util.Map;
|
27 | 28 | import org.apache.iceberg.catalog.SessionCatalog;
|
28 | 29 | import org.apache.iceberg.catalog.TableIdentifier;
|
29 |
| -import org.apache.iceberg.rest.HTTPClient; |
30 |
| -import org.apache.iceberg.rest.RESTClient; |
31 | 30 | import org.apache.iceberg.rest.auth.AuthManager;
|
32 | 31 | import org.apache.iceberg.rest.auth.AuthManagers;
|
33 | 32 | import org.apache.iceberg.rest.auth.AuthProperties;
|
34 | 33 | import org.apache.iceberg.rest.auth.AuthSession;
|
| 34 | +import org.apache.iceberg.rest.auth.ImmutableAuthScopes; |
35 | 35 | import org.apache.iceberg.rest.auth.NoopAuthManager;
|
36 | 36 | import org.apache.iceberg.rest.auth.OAuth2Manager;
|
37 | 37 | import org.apache.iceberg.rest.auth.OAuth2Util;
|
38 | 38 | import org.junit.jupiter.api.Test;
|
39 | 39 | import org.mockito.Mockito;
|
| 40 | +import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; |
| 41 | +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; |
| 42 | +import software.amazon.awssdk.regions.Region; |
40 | 43 |
|
41 | 44 | class TestRESTSigV4AuthManager {
|
42 | 45 |
|
@@ -106,64 +109,59 @@ void createInvalidCustomDelegate() {
|
106 | 109 | @Test
|
107 | 110 | void initSession() {
|
108 | 111 | AuthManager delegate = Mockito.mock(AuthManager.class);
|
109 |
| - when(delegate.initSession(any(), any())).thenReturn(Mockito.mock(OAuth2Util.AuthSession.class)); |
110 |
| - RESTClient client = Mockito.mock(RESTClient.class); |
| 112 | + when(delegate.authSession(any())).thenReturn(Mockito.mock(OAuth2Util.AuthSession.class)); |
111 | 113 | AuthManager manager = new RESTSigV4AuthManager("test", delegate);
|
112 |
| - AuthSession authSession = manager.initSession(client, awsProperties); |
113 |
| - assertThat(authSession) |
114 |
| - .isInstanceOf(RESTSigV4AuthSession.class) |
115 |
| - .extracting("delegate") |
116 |
| - .isInstanceOf(OAuth2Util.AuthSession.class); |
| 114 | + AuthSession authSession = manager.authSession(ImmutableAuthScopes.Initial.of(awsProperties)); |
| 115 | + assertAuthSession(authSession); |
117 | 116 | }
|
118 | 117 |
|
119 | 118 | @Test
|
120 |
| - void catalogSession() { |
| 119 | + void authSession() { |
121 | 120 | AuthManager delegate = Mockito.mock(AuthManager.class);
|
122 |
| - when(delegate.catalogSession(any(), any())) |
123 |
| - .thenReturn(Mockito.mock(OAuth2Util.AuthSession.class)); |
124 |
| - RESTClient client = Mockito.mock(RESTClient.class); |
| 121 | + when(delegate.authSession(any())).thenReturn(Mockito.mock(OAuth2Util.AuthSession.class)); |
125 | 122 | AuthManager manager = new RESTSigV4AuthManager("test", delegate);
|
126 |
| - AuthSession authSession = manager.catalogSession(client, awsProperties); |
127 |
| - assertThat(authSession) |
128 |
| - .isInstanceOf(RESTSigV4AuthSession.class) |
129 |
| - .extracting("delegate") |
130 |
| - .isInstanceOf(OAuth2Util.AuthSession.class); |
| 123 | + AuthSession authSession = manager.authSession(ImmutableAuthScopes.Catalog.of(awsProperties)); |
| 124 | + assertAuthSession(authSession); |
131 | 125 | }
|
132 | 126 |
|
133 | 127 | @Test
|
134 | 128 | void contextualSession() {
|
135 | 129 | AuthManager delegate = Mockito.mock(AuthManager.class);
|
136 |
| - when(delegate.catalogSession(any(), any())) |
137 |
| - .thenReturn(Mockito.mock(OAuth2Util.AuthSession.class)); |
138 |
| - when(delegate.contextualSession(any(), any())) |
139 |
| - .thenReturn(Mockito.mock(OAuth2Util.AuthSession.class)); |
| 130 | + when(delegate.authSession(any())).thenReturn(Mockito.mock(OAuth2Util.AuthSession.class)); |
140 | 131 | AuthManager manager = new RESTSigV4AuthManager("test", delegate);
|
141 |
| - manager.catalogSession(Mockito.mock(HTTPClient.class), awsProperties); |
| 132 | + AuthSession catalogSession = manager.authSession(ImmutableAuthScopes.Catalog.of(awsProperties)); |
142 | 133 | AuthSession authSession =
|
143 |
| - manager.contextualSession( |
144 |
| - Mockito.mock(SessionCatalog.SessionContext.class), Mockito.mock(AuthSession.class)); |
145 |
| - assertThat(authSession) |
146 |
| - .isInstanceOf(RESTSigV4AuthSession.class) |
147 |
| - .extracting("delegate") |
148 |
| - .isInstanceOf(OAuth2Util.AuthSession.class); |
| 134 | + manager.authSession( |
| 135 | + ImmutableAuthScopes.Contextual.of( |
| 136 | + Mockito.mock(SessionCatalog.SessionContext.class), catalogSession)); |
| 137 | + assertAuthSession(authSession); |
149 | 138 | }
|
150 | 139 |
|
151 | 140 | @Test
|
152 | 141 | void tableSession() {
|
153 | 142 | AuthManager delegate = Mockito.mock(AuthManager.class);
|
154 |
| - when(delegate.catalogSession(any(), any())) |
155 |
| - .thenReturn(Mockito.mock(OAuth2Util.AuthSession.class)); |
156 |
| - when(delegate.tableSession(any(), any(), any())) |
157 |
| - .thenReturn(Mockito.mock(OAuth2Util.AuthSession.class)); |
| 143 | + when(delegate.authSession(any())).thenReturn(Mockito.mock(OAuth2Util.AuthSession.class)); |
158 | 144 | AuthManager manager = new RESTSigV4AuthManager("test", delegate);
|
159 |
| - manager.catalogSession(Mockito.mock(HTTPClient.class), awsProperties); |
| 145 | + AuthSession catalogSession = manager.authSession(ImmutableAuthScopes.Catalog.of(awsProperties)); |
160 | 146 | AuthSession authSession =
|
161 |
| - manager.tableSession( |
162 |
| - Mockito.mock(TableIdentifier.class), Map.of(), Mockito.mock(AuthSession.class)); |
| 147 | + manager.authSession( |
| 148 | + ImmutableAuthScopes.Table.of( |
| 149 | + Mockito.mock(TableIdentifier.class), Map.of(), catalogSession)); |
| 150 | + assertAuthSession(authSession); |
| 151 | + } |
| 152 | + |
| 153 | + private static void assertAuthSession(AuthSession authSession) { |
163 | 154 | assertThat(authSession)
|
164 | 155 | .isInstanceOf(RESTSigV4AuthSession.class)
|
165 | 156 | .extracting("delegate")
|
166 | 157 | .isInstanceOf(OAuth2Util.AuthSession.class);
|
| 158 | + assertThat(authSession).extracting("signer").isNotNull(); |
| 159 | + assertThat(authSession).extracting("signingRegion").isEqualTo(Region.of("us-west-2")); |
| 160 | + assertThat(authSession) |
| 161 | + .extracting("credentialsProvider") |
| 162 | + .asInstanceOf(type(StaticCredentialsProvider.class)) |
| 163 | + .extracting(StaticCredentialsProvider::resolveCredentials) |
| 164 | + .isEqualTo(AwsBasicCredentials.create("id", "secret")); |
167 | 165 | }
|
168 | 166 |
|
169 | 167 | @Test
|
|
0 commit comments