Skip to content

Commit

Permalink
NOTIF-55 Migrate to resteasy-reactive and rest-client-reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenneg committed May 17, 2021
1 parent 2989168 commit 9bb1d10
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
14 changes: 3 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,20 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
<artifactId>quarkus-resteasy-reactive-qute</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
<artifactId>quarkus-rest-client-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-mutiny</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-mutiny</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-context-propagation</artifactId>
Expand Down Expand Up @@ -112,10 +108,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-cache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-qute</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-reactive</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@
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;
import javax.ws.rs.POST;
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +29,9 @@ void beforeEach() {
@MockServerConfig
MockServerClientConfig mockServerConfig;

@CacheName("rbac-cache")
Cache cache;

@Test
void testEndpointRoles() {
String tenant = "empty";
Expand All @@ -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
Expand All @@ -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);

Expand All @@ -58,11 +68,21 @@ void testEndpointRoles() {
.then()
.statusCode(403);

clearRbacCache();

// Test bogus x-rh-identity header that fails Base64 decoding
given()
.header(new Header("x-rh-identity", "00000"))
.when().get("/endpoints")
.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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 9bb1d10

Please sign in to comment.