From b51a6af4f729623a3ae302bd9624af6cfa7519a0 Mon Sep 17 00:00:00 2001 From: Gwenneg Lepage Date: Mon, 26 Apr 2021 17:38:39 +0200 Subject: [PATCH] NOTIF-55 Migrate to resteasy-reactive and rest-client-reactive --- pom.xml | 14 +++---------- .../events/EndpointProcessor.java | 3 +-- .../routers/InternalService.java | 6 ++++++ .../routers/AuthenticationTest.java | 20 +++++++++++++++++++ .../routers/NotificationServiceTest.java | 5 +++++ 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 6b9004643c..225e6140ce 100644 --- a/pom.xml +++ b/pom.xml @@ -54,24 +54,20 @@ io.quarkus - quarkus-resteasy + quarkus-resteasy-reactive-jackson io.quarkus - quarkus-rest-client + quarkus-resteasy-reactive-qute io.quarkus - quarkus-resteasy-jackson + quarkus-rest-client-reactive io.quarkus quarkus-mutiny - - io.quarkus - quarkus-resteasy-mutiny - io.quarkus quarkus-smallrye-context-propagation @@ -112,10 +108,6 @@ io.quarkus quarkus-cache - - io.quarkus - quarkus-resteasy-qute - io.quarkus quarkus-hibernate-reactive diff --git a/src/main/java/com/redhat/cloud/notifications/events/EndpointProcessor.java b/src/main/java/com/redhat/cloud/notifications/events/EndpointProcessor.java index 2b38011356..c9ac236437 100644 --- a/src/main/java/com/redhat/cloud/notifications/events/EndpointProcessor.java +++ b/src/main/java/com/redhat/cloud/notifications/events/EndpointProcessor.java @@ -16,7 +16,6 @@ import io.smallrye.mutiny.Multi; import io.smallrye.mutiny.Uni; import org.hibernate.reactive.mutiny.Mutiny; -import org.reactivestreams.Publisher; import javax.annotation.PostConstruct; import javax.enterprise.context.ApplicationScoped; @@ -108,7 +107,7 @@ public EndpointTypeProcessor endpointTypeToProcessor(EndpointType endpointType) // TODO [BG Phase 2] Delete this method public Multi getEndpoints(String tenant, String bundleName, String applicationName, String eventTypeName) { return resources.getTargetEndpoints(tenant, bundleName, applicationName, eventTypeName) - .onItem().transformToMultiAndConcatenate((Function>) endpoint -> { + .onItem().transformToMultiAndConcatenate((Function>) endpoint -> { // If the tenant has a default endpoint for the eventType, then add the target endpoints here if (endpoint.getType() == EndpointType.DEFAULT) { return defaultProcessor.getDefaultEndpoints(endpoint); diff --git a/src/main/java/com/redhat/cloud/notifications/routers/InternalService.java b/src/main/java/com/redhat/cloud/notifications/routers/InternalService.java index 218e23db07..f09f2b385d 100644 --- a/src/main/java/com/redhat/cloud/notifications/routers/InternalService.java +++ b/src/main/java/com/redhat/cloud/notifications/routers/InternalService.java @@ -12,6 +12,7 @@ import javax.inject.Inject; import javax.validation.Valid; import javax.validation.constraints.NotNull; +import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.NotFoundException; @@ -19,11 +20,16 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import javax.ws.rs.core.Response; import java.util.List; import java.util.UUID; +import static javax.ws.rs.core.MediaType.APPLICATION_JSON; + @Path("/internal") +@Consumes(APPLICATION_JSON) +@Produces(APPLICATION_JSON) public class InternalService { @Inject diff --git a/src/test/java/com/redhat/cloud/notifications/routers/AuthenticationTest.java b/src/test/java/com/redhat/cloud/notifications/routers/AuthenticationTest.java index 72f50d2826..5123586dfb 100644 --- a/src/test/java/com/redhat/cloud/notifications/routers/AuthenticationTest.java +++ b/src/test/java/com/redhat/cloud/notifications/routers/AuthenticationTest.java @@ -5,6 +5,9 @@ import com.redhat.cloud.notifications.TestConstants; import com.redhat.cloud.notifications.TestHelpers; import com.redhat.cloud.notifications.TestLifecycleManager; +import io.quarkus.cache.Cache; +import io.quarkus.cache.CacheName; +import io.quarkus.cache.runtime.caffeine.CaffeineCache; import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.junit.QuarkusTest; import io.restassured.RestAssured; @@ -26,6 +29,9 @@ void beforeEach() { @MockServerConfig MockServerClientConfig mockServerConfig; + @CacheName("rbac-cache") + Cache cache; + @Test void testEndpointRoles() { String tenant = "empty"; @@ -40,6 +46,8 @@ void testEndpointRoles() { .then() .statusCode(401); + clearRbacCache(); + // Fetch endpoint without any Rbac details - errors cause 401 given() // Set header to x-rh-identity @@ -48,6 +56,8 @@ void testEndpointRoles() { .then() .statusCode(401); + clearRbacCache(); + // Fetch endpoint with no access - Rbac succeed returns 403 mockServerConfig.addMockRbacAccess(identityHeaderValue, MockServerClientConfig.RbacAccess.NO_ACCESS); @@ -58,6 +68,8 @@ void testEndpointRoles() { .then() .statusCode(403); + clearRbacCache(); + // Test bogus x-rh-identity header that fails Base64 decoding given() .header(new Header("x-rh-identity", "00000")) @@ -65,4 +77,12 @@ void testEndpointRoles() { .then() .statusCode(401); } + + private void clearRbacCache() { + /* + * TODO Replace with real programmatic API call when it will be available. For now we have to rely on this "hack". + * See https://github.com/quarkusio/quarkus/pull/8631 + */ + ((CaffeineCache) cache).invalidateAll(); + } } diff --git a/src/test/java/com/redhat/cloud/notifications/routers/NotificationServiceTest.java b/src/test/java/com/redhat/cloud/notifications/routers/NotificationServiceTest.java index 78779e4b53..198035a7a8 100644 --- a/src/test/java/com/redhat/cloud/notifications/routers/NotificationServiceTest.java +++ b/src/test/java/com/redhat/cloud/notifications/routers/NotificationServiceTest.java @@ -9,6 +9,7 @@ import com.redhat.cloud.notifications.db.DbIsolatedTest; import com.redhat.cloud.notifications.db.ResourceHelpers; import com.redhat.cloud.notifications.models.Application; +import com.redhat.cloud.notifications.models.BehaviorGroup; import com.redhat.cloud.notifications.models.Endpoint; import com.redhat.cloud.notifications.models.EndpointType; import com.redhat.cloud.notifications.models.EventType; @@ -573,6 +574,8 @@ void testInsufficientPrivileges() { given() .header(readAccessIdentityHeader) .contentType(ContentType.JSON) + // TODO Remove the body when https://github.com/quarkusio/quarkus/issues/16897 is fixed + .body(Json.encode(new BehaviorGroup())) .when() .post("/notifications/behaviorGroups") .then() @@ -582,6 +585,8 @@ void testInsufficientPrivileges() { .header(readAccessIdentityHeader) .contentType(ContentType.JSON) .pathParam("id", UUID.randomUUID()) + // TODO Remove the body when https://github.com/quarkusio/quarkus/issues/16897 is fixed + .body(Json.encode(new BehaviorGroup())) .when() .put("/notifications/behaviorGroups/{id}") .then()