Skip to content

Commit

Permalink
fix(vertx-client): Make sure to close the Vertx instance in the maven…
Browse files Browse the repository at this point in the history
… plugin (#5676)

* Fix an issue where migrating from v2 to v3 failed to create the "latest" branch

* spotless:apply

* Sort versions when importing from a v2 zip

* Remove defaultVertx from VertxAuthFactory

* spotless:apply
  • Loading branch information
EricWittmann authored Dec 6, 2024
1 parent fb8dc52 commit f2664d7
Show file tree
Hide file tree
Showing 49 changed files with 529 additions and 436 deletions.
5 changes: 5 additions & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@
<artifactId>apicurio-registry-avro-serde-kafka</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.apicurio</groupId>
<artifactId>apicurio-registry-java-sdk</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.apicurio</groupId>
<artifactId>apicurio-registry-protobuf-serde-kafka</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.microsoft.kiota.ApiException;
import com.microsoft.kiota.RequestAdapter;
import io.apicurio.registry.client.auth.VertXAuthFactory;
import io.apicurio.registry.model.GroupId;
import io.apicurio.registry.rest.client.RegistryClient;
import io.apicurio.registry.rest.client.models.CreateArtifact;
Expand All @@ -26,6 +25,7 @@
import io.restassured.RestAssured;
import io.restassured.parsing.Parser;
import io.restassured.response.ValidatableResponse;
import io.vertx.core.Vertx;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -60,26 +60,29 @@ public abstract class AbstractResourceTestBase extends AbstractRegistryTestBase
protected RegistryClient clientV3;
protected RestService confluentClient;

protected Vertx vertx;

@BeforeAll
protected void beforeAll() throws Exception {
vertx = Vertx.vertx();
String serverUrl = "http://localhost:%s/apis";
registryApiBaseUrl = String.format(serverUrl, testPort);
registryV3ApiUrl = registryApiBaseUrl + "/registry/v3";
clientV3 = createRestClientV3();
clientV3 = createRestClientV3(vertx);
confluentClient = buildConfluentClient();
}

@AfterAll
protected void afterAll() {
vertx.close();
}

protected RestService buildConfluentClient() {
return new RestService("http://localhost:" + testPort + "/apis/ccompat/v7");
}

protected final RequestAdapter anonymousAdapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx);

protected RegistryClient createRestClientV3() {
protected RegistryClient createRestClientV3(Vertx vertx) {
RequestAdapter anonymousAdapter = new VertXRequestAdapter(vertx);
anonymousAdapter.setBaseUrl(registryV3ApiUrl);
var client = new RegistryClient(anonymousAdapter);
return client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.microsoft.kiota.ApiException;
import io.apicurio.common.apps.config.Info;
import io.apicurio.registry.AbstractResourceTestBase;
import io.apicurio.registry.client.auth.VertXAuthFactory;
import io.apicurio.registry.rest.client.RegistryClient;
import io.apicurio.registry.rest.client.models.CreateArtifact;
import io.apicurio.registry.types.ArtifactType;
Expand Down Expand Up @@ -37,7 +36,7 @@ public class AuthTestAnonymousCredentials extends AbstractResourceTestBase {
@Test
public void testWrongCreds() throws Exception {
var adapter = new VertXRequestAdapter(
buildOIDCWebClient(authServerUrl, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55"));
buildOIDCWebClient(vertx, authServerUrl, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55"));
adapter.setBaseUrl(registryV3ApiUrl);
RegistryClient client = new RegistryClient(adapter);

Expand All @@ -50,7 +49,7 @@ public void testWrongCreds() throws Exception {

@Test
public void testNoCredentials() throws Exception {
var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx);
var adapter = new VertXRequestAdapter(vertx);
adapter.setBaseUrl(registryV3ApiUrl);
RegistryClient client = new RegistryClient(adapter);
// Read-only operation should work without any credentials.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.apicurio.common.apps.config.Info;
import io.apicurio.registry.AbstractResourceTestBase;
import io.apicurio.registry.client.auth.VertXAuthFactory;
import io.apicurio.registry.rest.client.RegistryClient;
import io.apicurio.registry.rest.client.models.CreateArtifact;
import io.apicurio.registry.types.ArtifactType;
Expand All @@ -13,13 +14,12 @@
import io.kiota.http.vertx.VertXRequestAdapter;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.vertx.core.Vertx;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import static io.apicurio.registry.client.auth.VertXAuthFactory.buildOIDCWebClient;

@QuarkusTest
@TestProfile(AuthTestProfileAuthenticatedReadAccess.class)
@Tag(ApicurioTestTags.SLOW)
Expand All @@ -32,18 +32,18 @@ public class AuthTestAuthenticatedReadAccess extends AbstractResourceTestBase {
final String groupId = getClass().getSimpleName() + "Group";

@Override
protected RegistryClient createRestClientV3() {
var adapter = new VertXRequestAdapter(
buildOIDCWebClient(authServerUrl, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
protected RegistryClient createRestClientV3(Vertx vertx) {
var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, authServerUrl,
JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
adapter.setBaseUrl(registryV3ApiUrl);
return new RegistryClient(adapter);
}

@Test
public void testReadOperationWithNoRole() throws Exception {
// Read-only operation should work with credentials but no role.
var adapter = new VertXRequestAdapter(
buildOIDCWebClient(authServerUrl, JWKSMockServer.NO_ROLE_CLIENT_ID, "test1"));
var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, authServerUrl,
JWKSMockServer.NO_ROLE_CLIENT_ID, "test1"));
adapter.setBaseUrl(registryV3ApiUrl);
RegistryClient client = new RegistryClient(adapter);
var results = client.search().artifacts().get(config -> config.queryParameters.groupId = groupId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.apicurio.common.apps.config.Info;
import io.apicurio.registry.AbstractResourceTestBase;
import io.apicurio.registry.client.auth.VertXAuthFactory;
import io.apicurio.registry.model.GroupId;
import io.apicurio.registry.rest.client.RegistryClient;
import io.apicurio.registry.rest.client.models.CreateArtifact;
Expand All @@ -20,6 +21,7 @@
import io.kiota.http.vertx.VertXRequestAdapter;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.vertx.core.Vertx;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
Expand All @@ -46,9 +48,9 @@ public class AuthTestLocalRoles extends AbstractResourceTestBase {
String authServerUrlConfigured;

@Override
protected RegistryClient createRestClientV3() {
protected RegistryClient createRestClientV3(Vertx vertx) {
var adapter = new VertXRequestAdapter(
buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
buildOIDCWebClient(vertx, authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
adapter.setBaseUrl(registryV3ApiUrl);
return new RegistryClient(adapter);
}
Expand All @@ -65,13 +67,13 @@ protected RegistryClient createRestClientV3() {

@Test
public void testLocalRoles() throws Exception {
var adapterAdmin = new VertXRequestAdapter(
buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
var adapterAdmin = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx,
authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
adapterAdmin.setBaseUrl(registryV3ApiUrl);
RegistryClient clientAdmin = new RegistryClient(adapterAdmin);

var adapterAuth = new VertXRequestAdapter(
buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.NO_ROLE_CLIENT_ID, "test1"));
var adapterAuth = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx,
authServerUrlConfigured, JWKSMockServer.NO_ROLE_CLIENT_ID, "test1"));
adapterAuth.setBaseUrl(registryV3ApiUrl);
RegistryClient client = new RegistryClient(adapterAuth);

Expand Down
17 changes: 9 additions & 8 deletions app/src/test/java/io/apicurio/registry/auth/AuthTestNoRoles.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.apicurio.common.apps.config.Info;
import io.apicurio.registry.AbstractResourceTestBase;
import io.apicurio.registry.client.auth.VertXAuthFactory;
import io.apicurio.registry.model.GroupId;
import io.apicurio.registry.rest.client.RegistryClient;
import io.apicurio.registry.rest.client.models.CreateArtifact;
Expand All @@ -19,12 +20,12 @@
import io.kiota.http.vertx.VertXRequestAdapter;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.vertx.core.Vertx;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import static io.apicurio.registry.client.auth.VertXAuthFactory.buildOIDCWebClient;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -40,17 +41,17 @@ public class AuthTestNoRoles extends AbstractResourceTestBase {
final String groupId = "authTestGroupId";

@Override
protected RegistryClient createRestClientV3() {
var adapter = new VertXRequestAdapter(
buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
protected RegistryClient createRestClientV3(Vertx vertx) {
var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx,
authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
adapter.setBaseUrl(registryV3ApiUrl);
return new RegistryClient(adapter);
}

@Test
public void testWrongCreds() throws Exception {
var adapter = new VertXRequestAdapter(
buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55"));
var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx,
authServerUrlConfigured, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55"));
adapter.setBaseUrl(registryV3ApiUrl);
RegistryClient client = new RegistryClient(adapter);
var exception = Assertions.assertThrows(Exception.class, () -> {
Expand All @@ -61,8 +62,8 @@ public void testWrongCreds() throws Exception {

@Test
public void testAdminRole() throws Exception {
var adapter = new VertXRequestAdapter(
buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx,
authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
adapter.setBaseUrl(registryV3ApiUrl);
RegistryClient client = new RegistryClient(adapter);
String artifactId = TestUtils.generateArtifactId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.apicurio.common.apps.config.Info;
import io.apicurio.registry.AbstractResourceTestBase;
import io.apicurio.registry.client.auth.VertXAuthFactory;
import io.apicurio.registry.model.GroupId;
import io.apicurio.registry.rest.client.RegistryClient;
import io.apicurio.registry.rest.client.models.CreateArtifact;
Expand All @@ -20,6 +19,7 @@
import io.kiota.http.vertx.VertXRequestAdapter;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.vertx.core.Vertx;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Tag;
Expand All @@ -41,17 +41,17 @@ public class AuthTestProfileBasicClientCredentials extends AbstractResourceTestB
final String groupId = "authTestGroupId";

@Override
protected RegistryClient createRestClientV3() {
protected RegistryClient createRestClientV3(Vertx vertx) {
var adapter = new VertXRequestAdapter(
buildOIDCWebClient(authServerUrl, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
buildOIDCWebClient(vertx, authServerUrl, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
adapter.setBaseUrl(registryV3ApiUrl);
return new RegistryClient(adapter);
}

@Test
public void testWrongCreds() throws Exception {
var adapter = new VertXRequestAdapter(
buildSimpleAuthWebClient(JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55"));
buildSimpleAuthWebClient(vertx, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55"));
adapter.setBaseUrl(registryV3ApiUrl);
RegistryClient client = new RegistryClient(adapter);
var exception = Assertions.assertThrows(Exception.class, () -> {
Expand All @@ -63,7 +63,7 @@ public void testWrongCreds() throws Exception {
@Test
public void testBasicAuthClientCredentials() throws Exception {
var adapter = new VertXRequestAdapter(
buildSimpleAuthWebClient(JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
buildSimpleAuthWebClient(vertx, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
adapter.setBaseUrl(registryV3ApiUrl);
RegistryClient client = new RegistryClient(adapter);
String artifactId = TestUtils.generateArtifactId();
Expand Down Expand Up @@ -99,7 +99,7 @@ public void testBasicAuthClientCredentials() throws Exception {

@Test
public void testNoCredentials() throws Exception {
var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx);
var adapter = new VertXRequestAdapter(vertx);
adapter.setBaseUrl(registryV3ApiUrl);
RegistryClient client = new RegistryClient(adapter);
var exception = Assertions.assertThrows(Exception.class, () -> {
Expand Down
Loading

0 comments on commit f2664d7

Please sign in to comment.