This is an automated email from the ASF dual-hosted git repository.
dimas pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new 0b7fe7ef Move `testRefreshToken()` to
`QuarkusApplicationIntegrationTest` (#834)
0b7fe7ef is described below
commit 0b7fe7efd273120fe73070a73ff9e02e61743761
Author: Dmitri Bourlatchkov <[email protected]>
AuthorDate: Tue Jan 21 09:53:27 2025 -0500
Move `testRefreshToken()` to `QuarkusApplicationIntegrationTest` (#834)
`testRefreshToken()` is not normative for all Polaris Servers
given that external IdPs are going to be supported. Therefore,
the test is moved from the "blackbox" tests module to a
`quarkus/services` tests, which are local to the Apache Polaris
build.
---
.../it/test/PolarisApplicationIntegrationTest.java | 33 ---------------
.../it/QuarkusApplicationIntegrationTest.java | 48 +++++++++++++++++++++-
2 files changed, 47 insertions(+), 34 deletions(-)
diff --git
a/integration-tests/src/main/java/org/apache/polaris/service/it/test/PolarisApplicationIntegrationTest.java
b/integration-tests/src/main/java/org/apache/polaris/service/it/test/PolarisApplicationIntegrationTest.java
index 4275ba0c..99c2744f 100644
---
a/integration-tests/src/main/java/org/apache/polaris/service/it/test/PolarisApplicationIntegrationTest.java
+++
b/integration-tests/src/main/java/org/apache/polaris/service/it/test/PolarisApplicationIntegrationTest.java
@@ -24,8 +24,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;
-import com.auth0.jwt.JWT;
-import com.auth0.jwt.algorithms.Algorithm;
import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.Invocation;
@@ -34,7 +32,6 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
-import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Map;
@@ -59,12 +56,8 @@ import org.apache.iceberg.exceptions.NoSuchTableException;
import org.apache.iceberg.exceptions.RESTException;
import org.apache.iceberg.hadoop.HadoopFileIO;
import org.apache.iceberg.io.ResolvingFileIO;
-import org.apache.iceberg.rest.HTTPClient;
-import org.apache.iceberg.rest.RESTClient;
import org.apache.iceberg.rest.RESTSessionCatalog;
-import org.apache.iceberg.rest.auth.AuthConfig;
import org.apache.iceberg.rest.auth.OAuth2Properties;
-import org.apache.iceberg.rest.auth.OAuth2Util;
import org.apache.iceberg.types.Types;
import org.apache.iceberg.util.EnvironmentUtil;
import org.apache.polaris.core.admin.model.AwsStorageConfigInfo;
@@ -652,30 +645,4 @@ public class PolarisApplicationIntegrationTest {
});
}
}
-
- @Test
- public void testRefreshToken() throws IOException {
- String path = endpoints.catalogApiEndpoint() + "/v1/oauth/tokens";
- try (RESTClient client =
- HTTPClient.builder(Map.of()).withHeader(REALM_HEADER,
realm).uri(path).build()) {
- String credentialString =
- clientCredentials.clientId() + ":" +
clientCredentials.clientSecret();
- String expiredToken =
-
JWT.create().withExpiresAt(Instant.EPOCH).sign(Algorithm.HMAC256("irrelevant-secret"));
- var authConfig =
- AuthConfig.builder()
- .credential(credentialString)
- .scope("PRINCIPAL_ROLE:ALL")
- .oauth2ServerUri(path)
- .token(expiredToken)
- .build();
-
- var parentSession = new OAuth2Util.AuthSession(Map.of(), authConfig);
- var session =
- OAuth2Util.AuthSession.fromAccessToken(client, null, expiredToken,
0L, parentSession);
-
- assertThat(session.token()).isNotEqualTo(expiredToken); // implicit
refresh
-
assertThat(JWT.decode(session.token()).getExpiresAtAsInstant()).isAfter(Instant.EPOCH);
- }
- }
}
diff --git
a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/it/QuarkusApplicationIntegrationTest.java
b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/it/QuarkusApplicationIntegrationTest.java
index 90c74528..4c07adb4 100644
---
a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/it/QuarkusApplicationIntegrationTest.java
+++
b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/it/QuarkusApplicationIntegrationTest.java
@@ -18,8 +18,54 @@
*/
package org.apache.polaris.service.quarkus.it;
+import static
org.apache.polaris.service.it.env.PolarisApiEndpoints.REALM_HEADER;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.auth0.jwt.JWT;
+import com.auth0.jwt.algorithms.Algorithm;
import io.quarkus.test.junit.QuarkusTest;
+import java.io.IOException;
+import java.time.Instant;
+import java.util.Map;
+import org.apache.iceberg.rest.HTTPClient;
+import org.apache.iceberg.rest.RESTClient;
+import org.apache.iceberg.rest.auth.AuthConfig;
+import org.apache.iceberg.rest.auth.OAuth2Util;
+import org.apache.polaris.service.it.env.ClientCredentials;
+import org.apache.polaris.service.it.env.PolarisApiEndpoints;
import org.apache.polaris.service.it.test.PolarisApplicationIntegrationTest;
+import org.junit.jupiter.api.Test;
@QuarkusTest
-public class QuarkusApplicationIntegrationTest extends
PolarisApplicationIntegrationTest {}
+public class QuarkusApplicationIntegrationTest extends
PolarisApplicationIntegrationTest {
+
+ @Test
+ public void testIcebergRestApiRefreshToken(
+ PolarisApiEndpoints endpoints, ClientCredentials clientCredentials)
throws IOException {
+ String path = endpoints.catalogApiEndpoint() + "/v1/oauth/tokens";
+ try (RESTClient client =
+ HTTPClient.builder(Map.of())
+ .withHeader(REALM_HEADER, endpoints.realm())
+ .uri(path)
+ .build()) {
+ String credentialString =
+ clientCredentials.clientId() + ":" +
clientCredentials.clientSecret();
+ String expiredToken =
+
JWT.create().withExpiresAt(Instant.EPOCH).sign(Algorithm.HMAC256("irrelevant-secret"));
+ var authConfig =
+ AuthConfig.builder()
+ .credential(credentialString)
+ .scope("PRINCIPAL_ROLE:ALL")
+ .oauth2ServerUri(path)
+ .token(expiredToken)
+ .build();
+
+ var parentSession = new OAuth2Util.AuthSession(Map.of(), authConfig);
+ var session =
+ OAuth2Util.AuthSession.fromAccessToken(client, null, expiredToken,
0L, parentSession);
+
+ assertThat(session.token()).isNotEqualTo(expiredToken); // implicit
refresh
+
assertThat(JWT.decode(session.token()).getExpiresAtAsInstant()).isAfter(Instant.EPOCH);
+ }
+ }
+}