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

feat(flagd): ssl e2e tests #1111

Merged
merged 2 commits into from
Dec 23, 2024
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
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[submodule "providers/flagd/test-harness"]
path = providers/flagd/test-harness
url = https://github.com/open-feature/test-harness.git
branch = v0.5.19
aepfli marked this conversation as resolved.
Show resolved Hide resolved
[submodule "providers/flagd/spec"]
path = providers/flagd/spec
url = https://github.com/open-feature/spec.git
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
package dev.openfeature.contrib.providers.flagd.e2e;

import org.apache.logging.log4j.util.Strings;
import org.jetbrains.annotations.NotNull;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

import java.io.IOException;
import java.util.Properties;
import java.io.File;
import java.nio.file.Files;
import java.util.List;

public class ContainerConfig {
private static final String version;
private static final Network network = Network.newNetwork();

static {
Properties properties = new Properties();
String path = "test-harness/version.txt";
File file = new File(path);
try {
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("flagdTestbed.properties"));
version = properties.getProperty("version");
} catch (IOException e) {
List<String> lines = Files.readAllLines(file.toPath());
version = lines.get(0);
} catch (Exception e) {
throw new RuntimeException(e);
}
}


/**
*
* @return a {@link org.testcontainers.containers.GenericContainer} instance of a stable sync flagd server with the port 9090 exposed
*/
public static GenericContainer sync() {
public static GenericContainer sync() {
return sync(false, false);
}

/**
*
* @param unstable if an unstable version of the container, which terminates the connection regularly should be used.
* @param unstable if an unstable version of the container, which terminates the connection regularly should be used.
* @param addNetwork if set to true a custom network is attached for cross container access e.g. envoy --> sync:8015
* @return a {@link org.testcontainers.containers.GenericContainer} instance of a sync flagd server with the port 8015 exposed
*/
public static GenericContainer sync(boolean unstable, boolean addNetwork) {
String container = generateContainerName("flagd", unstable);
String container = generateContainerName("flagd", unstable ? "unstable" : "");
GenericContainer genericContainer = new GenericContainer(DockerImageName.parse(container))
.withExposedPorts(8015);

Expand All @@ -51,20 +53,18 @@ public static GenericContainer sync(boolean unstable, boolean addNetwork) {
}

/**
*
* @return a {@link org.testcontainers.containers.GenericContainer} instance of a stable flagd server with the port 8013 exposed
*/
public static GenericContainer flagd() {
return flagd(false);
}

/**
*
* @param unstable if an unstable version of the container, which terminates the connection regularly should be used.
* @return a {@link org.testcontainers.containers.GenericContainer} instance of a flagd server with the port 8013 exposed
*/
public static GenericContainer flagd(boolean unstable) {
String container = generateContainerName("flagd", unstable);
String container = generateContainerName("flagd", unstable ? "unstable" : "");
return new GenericContainer(DockerImageName.parse(container))
.withExposedPorts(8013);
}
Expand All @@ -73,7 +73,6 @@ public static GenericContainer flagd(boolean unstable) {
/**
* @return a {@link org.testcontainers.containers.GenericContainer} instance of envoy container using
* flagd sync service as backend expose on port 9211
*
*/
public static GenericContainer envoy() {
final String container = "envoyproxy/envoy:v1.31.0";
Expand All @@ -85,14 +84,14 @@ public static GenericContainer envoy() {
.withNetworkAliases("envoy");
}

private static @NotNull String generateContainerName(String type, boolean unstable) {
public static @NotNull String generateContainerName(String type, String addition) {
String container = "ghcr.io/open-feature/";
container += type;
container += "-testbed";
if (unstable) {
container += "-unstable";
if (!Strings.isBlank(addition)) {
container += "-" + addition;
}
container += ":" + version;
container += ":v" + version;
return container;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.openfeature.contrib.providers.flagd.e2e;

import org.apache.logging.log4j.core.config.Order;
import org.junit.jupiter.api.Disabled;
import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;
import org.testcontainers.junit.jupiter.Testcontainers;

import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;

/**
* Class for running the reconnection tests for the RPC provider
*/
@Order(value = Integer.MAX_VALUE)
@Suite(failIfNoTests = false)
@IncludeEngines("cucumber")
//@SelectClasspathResource("features/evaluation.feature")
aepfli marked this conversation as resolved.
Show resolved Hide resolved
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.ssl.process,dev.openfeature.contrib.providers.flagd.e2e.steps")
@Testcontainers
public class RunFlagdInProcessSSLCucumberTest {

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.openfeature.contrib.providers.flagd.e2e;

import org.apache.logging.log4j.core.config.Order;
import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;
import org.testcontainers.junit.jupiter.Testcontainers;

import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME;
import static io.cucumber.junit.platform.engine.Constants.PLUGIN_PROPERTY_NAME;

/**
* Class for running the reconnection tests for the RPC provider
*/
@Order(value = Integer.MAX_VALUE)
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features/evaluation.feature")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.ssl.rpc,dev.openfeature.contrib.providers.flagd.e2e.steps")
@Testcontainers
public class RunFlagdRpcSSLCucumberTest {

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package dev.openfeature.contrib.providers.flagd.e2e.ssl.process;

import dev.openfeature.contrib.providers.flagd.Config;
import dev.openfeature.contrib.providers.flagd.FlagdOptions;
import dev.openfeature.contrib.providers.flagd.FlagdProvider;
import dev.openfeature.contrib.providers.flagd.e2e.ContainerConfig;
import dev.openfeature.contrib.providers.flagd.e2e.steps.StepDefinitions;
import dev.openfeature.contrib.providers.flagd.resolver.grpc.cache.CacheType;
import dev.openfeature.sdk.FeatureProvider;
import io.cucumber.java.AfterAll;
import io.cucumber.java.Before;
import io.cucumber.java.BeforeAll;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.parallel.Isolated;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.DockerImageName;

import java.io.File;

@Isolated()
@Order(value = Integer.MAX_VALUE)
public class FlagdInProcessSetup {
private static final GenericContainer flagdContainer =
new GenericContainer(
DockerImageName.parse(
ContainerConfig.generateContainerName("flagd", "ssl")
)
).withExposedPorts(8015);

@BeforeAll()
public static void setups() throws InterruptedException {
flagdContainer.start();
}

@Before()
public static void setupTest() throws InterruptedException {
String path = "test-harness/ssl/custom-root-cert.crt";

File file = new File(path);
String absolutePath = file.getAbsolutePath();
FeatureProvider workingProvider = new FlagdProvider(FlagdOptions.builder()
.resolverType(Config.Resolver.IN_PROCESS)
.port(flagdContainer.getFirstMappedPort())
.deadline(10000)
.streamDeadlineMs(0) // this makes reconnect tests more predictable
.tls(true)
.certPath(absolutePath)
.build());
StepDefinitions.setProvider(workingProvider);

}

@AfterAll
public static void tearDown() {
flagdContainer.stop();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package dev.openfeature.contrib.providers.flagd.e2e.ssl.rpc;

import dev.openfeature.contrib.providers.flagd.Config;
import dev.openfeature.contrib.providers.flagd.FlagdOptions;
import dev.openfeature.contrib.providers.flagd.FlagdProvider;
import dev.openfeature.contrib.providers.flagd.e2e.ContainerConfig;
import dev.openfeature.contrib.providers.flagd.e2e.steps.StepDefinitions;
import dev.openfeature.contrib.providers.flagd.resolver.grpc.cache.CacheType;
import dev.openfeature.sdk.FeatureProvider;
import io.cucumber.java.AfterAll;
import io.cucumber.java.Before;
import io.cucumber.java.BeforeAll;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.parallel.Isolated;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.DockerImageName;

import java.io.File;

@Isolated()
@Order(value = Integer.MAX_VALUE)
public class FlagdRpcSetup {
private static final GenericContainer flagdContainer =
new GenericContainer(
DockerImageName.parse(
ContainerConfig.generateContainerName("flagd", "ssl")
)
).withExposedPorts(8013);

@BeforeAll()
public static void setups() throws InterruptedException {
flagdContainer.start();
}

@Before()
public static void setupTest() throws InterruptedException {
String path = "test-harness/ssl/custom-root-cert.crt";

File file = new File(path);
String absolutePath = file.getAbsolutePath();
FeatureProvider workingProvider = new FlagdProvider(FlagdOptions.builder()
.resolverType(Config.Resolver.RPC)
.port(flagdContainer.getFirstMappedPort())
.deadline(10000)
.streamDeadlineMs(0) // this makes reconnect tests more predictable
.tls(true)
.certPath(absolutePath)
.build());
StepDefinitions.setProvider(workingProvider);

}

@AfterAll
public static void tearDown() {
flagdContainer.stop();
}
}
Loading
Loading