Skip to content

Commit 2022d63

Browse files
committed
Use EventFilter to assert SSL validation errors in multi-actor system tests
Updated SSL integration tests to use EventFilter for asserting specific validation errors instead of just checking connection failure. This provides better test precision by verifying the exact reason for connection failure. With mTLS enabled, validation errors occur on the server side (_sys2) when it validates the client certificate, since the client (Sys) has suppressValidation enabled. The EventFilter assertions are correctly targeted to the system where the validation errors occur. Changes: - Added EventFilter assertions to PinnedCertificate rejection test - Added EventFilter assertions to CustomValidator rejection test - Added EventFilter assertions to ValidateSubject rejection test - Modified custom validator to log error for EventFilter detection - Added comments explaining the mTLS validation flow
1 parent 841a8ef commit 2022d63

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/core/Akka.Remote.Tests/Transport/DotNettySslSetupSpec.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ public async Task CustomValidator_that_rejects_should_prevent_connection()
305305
{
306306
validatorCalled = true;
307307
Output.WriteLine($"CustomValidator called for peer: {peer}, rejecting certificate");
308+
log.Error("CustomValidator rejecting certificate for peer: {0}", peer);
308309
return false; // Reject all certificates
309310
};
310311

@@ -334,9 +335,13 @@ public async Task CustomValidator_that_rejects_should_prevent_connection()
334335

335336
var probe = CreateTestProbe();
336337

337-
// Connection should fail due to custom validator rejection - TLS handshake fails, so message never arrives
338-
Sys.ActorSelection(_echoPath).Tell("hello", probe.Ref);
339-
await probe.ExpectNoMsgAsync(TimeSpan.FromSeconds(3));
338+
// Connection should fail due to custom validator rejection
339+
// With mTLS enabled, _sys2 (server) validates Sys's (client) certificate
340+
await EventFilter.Error(contains: "CustomValidator rejecting certificate").ExpectAsync(1, async () =>
341+
{
342+
Sys.ActorSelection(_echoPath).Tell("hello", probe.Ref);
343+
await probe.ExpectNoMsgAsync(TimeSpan.FromSeconds(3));
344+
}, _sys2);
340345

341346
// Verify that CustomValidator was actually called
342347
Assert.True(validatorCalled, "CustomValidator should have been invoked during TLS handshake");
@@ -486,8 +491,13 @@ public async Task PinnedCertificate_should_reject_non_matching_thumbprint()
486491
var probe = CreateTestProbe();
487492

488493
// Connection should fail due to thumbprint mismatch
489-
Sys.ActorSelection(_echoPath).Tell("hello", probe.Ref);
490-
await probe.ExpectNoMsgAsync(TimeSpan.FromSeconds(3));
494+
// With mTLS enabled, _sys2 (server) validates Sys's (client) certificate
495+
// The validation error occurs on _sys2's side when it rejects the client certificate
496+
await EventFilter.Error(contains: "not in allowed list").ExpectAsync(1, async () =>
497+
{
498+
Sys.ActorSelection(_echoPath).Tell("hello", probe.Ref);
499+
await probe.ExpectNoMsgAsync(TimeSpan.FromSeconds(3));
500+
}, _sys2);
491501
}
492502

493503
[Fact(DisplayName = "CertificateValidation.ValidateSubject should accept certificates with matching subject")]
@@ -565,8 +575,12 @@ public async Task ValidateSubject_should_reject_non_matching_subject()
565575
var probe = CreateTestProbe();
566576

567577
// Connection should fail due to subject mismatch
568-
Sys.ActorSelection(_echoPath).Tell("hello", probe.Ref);
569-
await probe.ExpectNoMsgAsync(TimeSpan.FromSeconds(3));
578+
// With mTLS enabled, _sys2 (server) validates Sys's (client) certificate
579+
await EventFilter.Error(contains: "does not match pattern").ExpectAsync(1, async () =>
580+
{
581+
Sys.ActorSelection(_echoPath).Tell("hello", probe.Ref);
582+
await probe.ExpectNoMsgAsync(TimeSpan.FromSeconds(3));
583+
}, _sys2);
570584
}
571585

572586
[Fact(DisplayName = "CertificateValidation.ValidateSubject should support wildcard patterns")]

0 commit comments

Comments
 (0)