Skip to content

Commit

Permalink
Enhance test vault and test exporter (#1333)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfallows authored Nov 20, 2024
1 parent 3695c9f commit bc34b23
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static io.aklivity.zilla.runtime.engine.EngineConfiguration.ENGINE_WORKERS;
import static java.nio.file.FileVisitOption.FOLLOW_LINKS;
import static java.nio.file.Files.exists;
import static java.util.Collections.synchronizedList;
import static java.util.Objects.requireNonNull;
import static org.junit.runners.model.MultipleFailureException.assertEmpty;

Expand Down Expand Up @@ -317,7 +318,7 @@ public void evaluate() throws Throwable
{
final EngineConfiguration config = configuration();
final Thread baseThread = Thread.currentThread();
final List<Throwable> errors = new ArrayList<>();
final List<Throwable> errors = synchronizedList(new ArrayList<>());
final ErrorHandler errorHandler = ex ->
{
ex.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public void stop()
{
readEvent.read(this::handleEvent, Integer.MAX_VALUE);
}

if (options.events == null ||
options.events.isEmpty())
{
readEvent.read(this::handleEvent, 1);
}
}
catch (Exception ex)
{
Expand All @@ -87,7 +93,12 @@ private void handleEvent(
String name = context.supplyEventName(event.id());
String message = formatter.format(msgTypeId, buffer, index, length);

if (options.events != null && eventIndex < options.events.size())
if (options.events == null || options.events.isEmpty())
{
throw new IllegalStateException(String.format("event not expected: %s %s %s %s",
qname, id, name, message));
}
else if (eventIndex < options.events.size())
{
TestExporterOptionsConfig.Event e = options.events.get(eventIndex);
if (!qname.equals(e.qName) || !id.equals(e.id) || !name.equals(e.name) || !message.equals(e.message))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public final class TestVaultHandler implements VaultHandler
{
private static final Pattern PATTERN_KEY_ENTRY =
Pattern.compile(
"(?<key>-----BEGIN PRIVATE KEY-----\n[^-]+-----END PRIVATE KEY-----\n)" +
"(?<chain>(?:-----BEGIN CERTIFICATE-----\n[^-]+-----END CERTIFICATE-----\n)+)");
"(?<key>-----BEGIN PRIVATE KEY-----[^-]+-----END PRIVATE KEY-----[^-]+)" +
"(?<chain>(?:-----BEGIN CERTIFICATE-----[^-]+-----END CERTIFICATE-----[^-]+)+)");

private final TestVaultEntryConfig key;
private final TestVaultEntryConfig signer;
Expand Down Expand Up @@ -87,8 +87,8 @@ public KeyManagerFactory initKeys(

String base64 = encodedKey
.replace("-----BEGIN PRIVATE KEY-----", "")
.replaceAll(System.lineSeparator(), "")
.replace("-----END PRIVATE KEY-----", "");
.replace("-----END PRIVATE KEY-----", "")
.replaceAll("[^a-zA-Z0-9+/=]", "");
byte[] encoded = Base64.getMimeDecoder().decode(base64);

KeySpec keySpec = new PKCS8EncodedKeySpec(encoded);
Expand Down

0 comments on commit bc34b23

Please sign in to comment.