Skip to content

Commit

Permalink
Fix PolarisPrincipalSecrets injection in tests (#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
adutra authored Dec 2, 2024
1 parent afd14d9 commit c7ec45f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.apache.polaris.service.admin;

import static io.dropwizard.jackson.Jackson.newObjectMapper;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.polaris.service.context.DefaultContextResolver.REALM_PROPERTY_KEY;
import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -30,9 +29,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.dropwizard.testing.ConfigOverride;
import io.dropwizard.testing.ResourceHelpers;
import io.dropwizard.testing.junit5.DropwizardAppExtension;
Expand All @@ -45,7 +41,6 @@
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -90,6 +85,7 @@
import org.apache.polaris.core.admin.model.UpdatePrincipalRequest;
import org.apache.polaris.core.admin.model.UpdatePrincipalRoleRequest;
import org.apache.polaris.core.entity.PolarisEntityConstants;
import org.apache.polaris.core.entity.PolarisPrincipalSecrets;
import org.apache.polaris.service.PolarisApplication;
import org.apache.polaris.service.auth.BasePolarisAuthenticator;
import org.apache.polaris.service.auth.TokenUtils;
Expand Down Expand Up @@ -141,17 +137,13 @@ public class PolarisServiceImplIntegrationTest {

@BeforeAll
public static void setup(
PolarisConnectionExtension.PolarisToken adminToken, @PolarisRealm String polarisRealm)
PolarisConnectionExtension.PolarisToken adminToken,
PolarisPrincipalSecrets adminSecrets,
@PolarisRealm String polarisRealm)
throws IOException {
userToken = adminToken.token();
realm = polarisRealm;

Base64.Decoder decoder = Base64.getUrlDecoder();
String[] chunks = adminToken.token().split("\\.");
String payload = new String(decoder.decode(chunks[1]), UTF_8);
JsonElement jsonElement = JsonParser.parseString(payload);
clientId = String.valueOf(((JsonObject) jsonElement).get("client_id"));

clientId = adminSecrets.getPrincipalClientId();
// Set up test location
PolarisConnectionExtension.createTestDir(realm);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ public Object resolveParameter(
} else if (parameterContext.getParameter().getType().equals(String.class)
&& parameterContext.getParameter().isAnnotationPresent(PolarisRealm.class)) {
return realm;
} else if (parameterContext.getParameter().getType().equals(PolarisPrincipalSecrets.class)) {
return adminSecrets;
} else {
return metaStoreManagerFactory;
}
Expand Down

0 comments on commit c7ec45f

Please sign in to comment.