Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOTIF-55 Migrate to resteasy-reactive and rest-client-reactive #202

Merged
merged 1 commit into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was the default and we didn't need to specify it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true for quarkus-resteasy but apparently we have to add these annotations back with quarkus-reasteasy-reactive. I suspect the reactive extension is missing some bytecode enhancement. I'll investigate that later (or talk with the resteasy-reactive team).

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