Skip to content

Commit

Permalink
Fixes issue with recipients query (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
josejulio authored Aug 6, 2021
1 parent 6dc2d9a commit c0f814b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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<String, Secret> 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<>() { }
Expand All @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit c0f814b

Please sign in to comment.