From c0f814bb05a4e3313f73967cbe30762b4fea46ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josejulio=20Mart=C3=ADnez?= Date: Fri, 6 Aug 2021 10:29:22 -0500 Subject: [PATCH] Fixes issue with recipients query (#459) --- .../recipients/rbac/AuthRequestFilter.java | 19 +++++++------------ .../rbac/AuthRequestFilterTest.java | 12 +----------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/backend/src/main/java/com/redhat/cloud/notifications/recipients/rbac/AuthRequestFilter.java b/backend/src/main/java/com/redhat/cloud/notifications/recipients/rbac/AuthRequestFilter.java index ec86777281..41f3a73866 100644 --- a/backend/src/main/java/com/redhat/cloud/notifications/recipients/rbac/AuthRequestFilter.java +++ b/backend/src/main/java/com/redhat/cloud/notifications/recipients/rbac/AuthRequestFilter.java @@ -7,9 +7,6 @@ import org.eclipse.microprofile.config.ConfigProvider; import org.jboss.logmanager.Level; -import javax.annotation.PostConstruct; -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestFilter; import java.io.IOException; @@ -18,7 +15,6 @@ import java.util.Map; import java.util.logging.Logger; -@ApplicationScoped class AuthRequestFilter implements ClientRequestFilter { static final String RBAC_SERVICE_TO_SERVICE_APPLICATION_KEY = "rbac.service-to-service.application"; @@ -34,23 +30,20 @@ private static class Secret { public String secret; } - @Inject - ObjectMapper objectMapper; - - private String authInfo; - private String secret; - private String application; + private final String authInfo; + private final String secret; + private final String application; private final Logger log = Logger.getLogger(this.getClass().getName()); - @PostConstruct - void init() { + AuthRequestFilter() { Config config = ConfigProvider.getConfig(); application = config.getOptionalValue(RBAC_SERVICE_TO_SERVICE_APPLICATION_KEY, String.class).orElse(RBAC_SERVICE_TO_SERVICE_APPLICATION_DEFAULT); Map rbacServiceToServiceSecretMap; try { + ObjectMapper objectMapper = new ObjectMapper(); rbacServiceToServiceSecretMap = objectMapper.readValue( config.getOptionalValue(RBAC_SERVICE_TO_SERVICE_SECRET_MAP_KEY, String.class).orElse(RBAC_SERVICE_TO_SERVICE_SECRET_MAP_DEFAULT), new TypeReference<>() { } @@ -68,6 +61,8 @@ void init() { String tmp = System.getProperty(RBAC_SERVICE_TO_SERVICE_DEV_EXCEPTIONAL_AUTH_KEY); if (tmp != null && !tmp.isEmpty()) { authInfo = new String(Base64.getEncoder().encode(tmp.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); + } else { + authInfo = null; } } diff --git a/backend/src/test/java/com/redhat/cloud/notifications/recipients/rbac/AuthRequestFilterTest.java b/backend/src/test/java/com/redhat/cloud/notifications/recipients/rbac/AuthRequestFilterTest.java index b33ddcf395..28fb7ed527 100644 --- a/backend/src/test/java/com/redhat/cloud/notifications/recipients/rbac/AuthRequestFilterTest.java +++ b/backend/src/test/java/com/redhat/cloud/notifications/recipients/rbac/AuthRequestFilterTest.java @@ -1,13 +1,11 @@ package com.redhat.cloud.notifications.recipients.rbac; -import com.fasterxml.jackson.databind.ObjectMapper; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import javax.inject.Inject; import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; @@ -21,9 +19,6 @@ public class AuthRequestFilterTest { private static final String testToken = "{\"approval\":{\"secret\":\"123\"},\"advisor\":{\"secret\":\"456\"},\"notifications\":{\"secret\":\"789\"}}"; - @Inject - ObjectMapper objectMapper; - @BeforeEach public void clean() { System.clearProperty(AuthRequestFilter.RBAC_SERVICE_TO_SERVICE_DEV_EXCEPTIONAL_AUTH_KEY); @@ -32,12 +27,7 @@ public void clean() { } private AuthRequestFilter getAuthRequestFilter() { - // Injecting doesn't seem to take into account the System.setProperty calls. - // Probably related to: https://quarkus.io/blog/quarkus-test-profiles/ - AuthRequestFilter rbacAuthRequestFilter = new AuthRequestFilter(); - rbacAuthRequestFilter.objectMapper = objectMapper; - rbacAuthRequestFilter.init(); - return rbacAuthRequestFilter; + return new AuthRequestFilter(); } @Test