Skip to content

Commit

Permalink
New(PrepareIntegrationTests): Useful tests for Registry3
Browse files Browse the repository at this point in the history
  • Loading branch information
rkubis committed Dec 12, 2024
1 parent 3d84d22 commit 0e4056b
Showing 1 changed file with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,34 @@

import io.apicur.registry.v1.ApicurioRegistry3;
import io.apicur.registry.v1.ApicurioRegistry3Builder;
import io.apicurio.registry.systemtests.framework.ApicurioRegistryUtils;
import io.apicurio.registry.systemtests.framework.Base64Utils;
import io.apicurio.registry.systemtests.framework.Certificate;
import io.apicurio.registry.systemtests.framework.CertificateUtils;
import io.apicurio.registry.systemtests.framework.Constants;
import io.apicurio.registry.systemtests.framework.DatabaseUtils;
import io.apicurio.registry.systemtests.framework.Environment;
import io.apicurio.registry.systemtests.framework.KeycloakUtils;
import io.apicurio.registry.systemtests.framework.LoggerUtils;
import io.apicurio.registry.systemtests.operator.OperatorManager;
import io.apicurio.registry.systemtests.operator.types.ApicurioRegistryOLMOperatorType;
import io.apicurio.registry.systemtests.operator.types.KeycloakOLMOperatorType;
import io.apicurio.registry.systemtests.platform.Kubernetes;
import io.apicurio.registry.systemtests.registryinfra.ResourceManager;
import io.apicurio.registry.systemtests.registryinfra.resources.PersistenceKind;
import io.fabric8.kubernetes.api.model.Secret;
import io.fabric8.kubernetes.api.model.SecretBuilder;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;

import java.io.IOException;
import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class PrepareIntegrationTests {
protected static Logger LOGGER = LoggerUtils.getLogger();
Expand Down Expand Up @@ -88,4 +103,62 @@ public void tryRegistry3() {
.endSpec()
.build();
}

@Test
public void installOLMClusterWideRegistryOperator() throws InterruptedException {
ApicurioRegistryOLMOperatorType operator = new ApicurioRegistryOLMOperatorType(Environment.CATALOG_IMAGE, true);

operator.install();
}

@Test
public void prepareTruststore() throws InterruptedException {
Secret routerCertsDefaultSecret = Kubernetes.getSecret("openshift-config-managed", Constants.ROUTER_CERTS);
String clusterBaseUrl = Objects.requireNonNull(
Kubernetes.getRouteHost("openshift-console", "console")
).replace("console-openshift-console.", "");
ArrayList<Certificate> certificates = CertificateUtils.readCertificates(
Base64Utils.decode(routerCertsDefaultSecret.getData().get(clusterBaseUrl))
);
Secret newSecret = new SecretBuilder()
.withNewMetadata()
.withName(routerCertsDefaultSecret.getMetadata().getName())
.withNamespace(Environment.NAMESPACE)
.endMetadata()
.withType("Opaque")
.withData(new HashMap<>() {{
put(Constants.TRUSTSTORE_DATA_NAME, Base64Utils.encode(CertificateUtils.getCertificates(certificates)));
}})
.build();

Kubernetes.createSecret(Environment.NAMESPACE, newSecret);

String timestamp = String.valueOf(Instant.now().getEpochSecond());
String caCertSecretValue = CertificateUtils.decodeBase64Secret(Environment.NAMESPACE, Constants.ROUTER_CERTS, Constants.TRUSTSTORE_DATA_NAME);
Path caPath = Environment.getTmpPath("tls-" + timestamp + ".crt");

CertificateUtils.writeToFile(caCertSecretValue, caPath);

Path truststorePath = Environment.getTmpPath("truststore-" + timestamp + ".p12");

CertificateUtils.runTruststoreCmd(truststorePath, "password", caPath);

Secret secret = new SecretBuilder()
.withNewMetadata()
.withName(Constants.TRUSTSTORE_SECRET_NAME)
.withNamespace(Environment.NAMESPACE)
.endMetadata()
.addToData(new HashMap<>() {{
put(Constants.TRUSTSTORE_DATA_NAME, Base64Utils.encode(truststorePath));
}})
.build();

Kubernetes.createSecret(Environment.NAMESPACE, secret);
}

@Test
public void prepareRegistry3SqlNoIAM() throws InterruptedException {
// Deploy and get registry
ApicurioRegistry3 apicurioRegistry3 = ApicurioRegistryUtils.deployDefaultApicurioRegistrySql(false);
}
}

0 comments on commit 0e4056b

Please sign in to comment.