@@ -111,8 +111,12 @@ ListenerAcceptConnection(
111111 )
112112{
113113 ServerAcceptContext* AcceptContext = (ServerAcceptContext*)Listener->Context ;
114- *AcceptContext->NewConnection = new (std::nothrow) TestConnection (ConnectionHandle);
114+ *AcceptContext->NewConnection = new (std::nothrow) TestConnection (ConnectionHandle, (NEW_STREAM_CALLBACK_HANDLER)AcceptContext-> NewStreamHandler );
115115 (*AcceptContext->NewConnection )->SetExpectedCustomTicketValidationResult (AcceptContext->ExpectedCustomTicketValidationResult );
116+ (*AcceptContext->NewConnection )->SetAsyncCustomValidationResult (AcceptContext->AsyncCustomCertValidation );
117+ if (AcceptContext->IsCustomCertValidationResultSet ) {
118+ (*AcceptContext->NewConnection )->SetExpectedCustomValidationResult (AcceptContext->CustomCertValidationResult );
119+ }
116120 if (*AcceptContext->NewConnection == nullptr || !(*AcceptContext->NewConnection )->IsValid ()) {
117121 TEST_FAILURE (" Failed to accept new TestConnection." );
118122 delete *AcceptContext->NewConnection ;
@@ -744,7 +748,7 @@ QuicTestConnectAndIdle(
744748}
745749
746750void
747- QuicTestCustomCertificateValidation (
751+ QuicTestCustomServerCertificateValidation (
748752 _In_ bool AcceptCert,
749753 _In_ bool AsyncValidation
750754 )
@@ -820,6 +824,122 @@ QuicTestCustomCertificateValidation(
820824 }
821825}
822826
827+ void
828+ NoOpStreamShutdownCallback (
829+ _In_ TestStream* Stream
830+ )
831+ {
832+ UNREFERENCED_PARAMETER (Stream);
833+ }
834+
835+ void
836+ NewStreamCallbackTestFail (
837+ _In_ TestConnection* Connection,
838+ _In_ HQUIC StreamHandle,
839+ _In_ QUIC_STREAM_OPEN_FLAGS Flags
840+ )
841+ {
842+ UNREFERENCED_PARAMETER (Connection);
843+ UNREFERENCED_PARAMETER (Flags);
844+ MsQuic->StreamClose (StreamHandle);
845+ TEST_FAILURE (" Unexpected new Stream received" );
846+ }
847+
848+ void
849+ QuicTestCustomClientCertificateValidation (
850+ _In_ bool AcceptCert,
851+ _In_ bool AsyncValidation
852+ )
853+ {
854+ MsQuicRegistration Registration;
855+ TEST_TRUE (Registration.IsValid ());
856+
857+ MsQuicAlpn Alpn (" MsQuicTest" );
858+
859+ MsQuicSettings Settings;
860+ Settings.SetPeerBidiStreamCount (1 );
861+ Settings.SetIdleTimeoutMs (3000 );
862+
863+ MsQuicConfiguration ServerConfiguration (Registration, Alpn, Settings, ServerSelfSignedCredConfigClientAuth);
864+ TEST_TRUE (ServerConfiguration.IsValid ());
865+
866+ MsQuicConfiguration ClientConfiguration (Registration, Alpn, Settings, ClientCertCredConfig);
867+ TEST_TRUE (ClientConfiguration.IsValid ());
868+
869+ {
870+ TestListener Listener (Registration, ListenerAcceptConnection, ServerConfiguration);
871+ TEST_TRUE (Listener.IsValid ());
872+ TEST_QUIC_SUCCEEDED (Listener.Start (Alpn));
873+
874+ QuicAddr ServerLocalAddr;
875+ TEST_QUIC_SUCCEEDED (Listener.GetLocalAddr (ServerLocalAddr));
876+
877+ {
878+ UniquePtr<TestConnection> Server;
879+ ServerAcceptContext ServerAcceptCtx ((TestConnection**)&Server);
880+ if (!AcceptCert) {
881+ ServerAcceptCtx.ExpectedTransportCloseStatus = QUIC_STATUS_BAD_CERTIFICATE;
882+ ServerAcceptCtx.NewStreamHandler = (void *)NewStreamCallbackTestFail;
883+ }
884+ ServerAcceptCtx.AsyncCustomCertValidation = AsyncValidation;
885+ if (!AsyncValidation) {
886+ ServerAcceptCtx.IsCustomCertValidationResultSet = true ;
887+ ServerAcceptCtx.CustomCertValidationResult = AcceptCert;
888+ }
889+ ServerAcceptCtx.AddExpectedClientCertValidationResult (QUIC_STATUS_CERT_UNTRUSTED_ROOT);
890+ Listener.Context = &ServerAcceptCtx;
891+
892+ {
893+ TestConnection Client (Registration);
894+ TEST_TRUE (Client.IsValid ());
895+
896+ if (!AcceptCert) {
897+ Client.SetExpectedTransportCloseStatus (QUIC_STATUS_BAD_CERTIFICATE);
898+ }
899+
900+ UniquePtr<TestStream> ClientStream (
901+ TestStream::FromConnectionHandle (
902+ Client.GetConnection (),
903+ NoOpStreamShutdownCallback,
904+ QUIC_STREAM_OPEN_FLAG_NONE));
905+
906+ TEST_QUIC_SUCCEEDED (ClientStream->Start (QUIC_STREAM_START_FLAG_IMMEDIATE));
907+
908+ TEST_QUIC_SUCCEEDED (
909+ Client.Start (
910+ ClientConfiguration,
911+ QUIC_ADDRESS_FAMILY_UNSPEC,
912+ QUIC_TEST_LOOPBACK_FOR_AF (
913+ QuicAddrGetFamily (&ServerLocalAddr.SockAddr )),
914+ ServerLocalAddr.GetPort ()));
915+
916+ if (!CxPlatEventWaitWithTimeout (ServerAcceptCtx.NewConnectionReady , TestWaitTimeout)) {
917+ TEST_FAILURE (" Timed out waiting for server accept." );
918+ }
919+
920+ if (AsyncValidation) {
921+ CxPlatSleep (2000 );
922+ TEST_QUIC_SUCCEEDED (Server->SetCustomValidationResult (AcceptCert));
923+ }
924+
925+ if (!Client.WaitForConnectionComplete ()) {
926+ return ;
927+ }
928+
929+ if (AcceptCert) { // Server will be deleted on reject case, so can't validate.
930+ TEST_NOT_EQUAL (nullptr , Server);
931+ if (!Server->WaitForConnectionComplete ()) {
932+ return ;
933+ }
934+ TEST_TRUE (Server->GetIsConnected ());
935+ }
936+ // In all cases, the client "connects", but in the rejection case, it gets disconnected.
937+ TEST_TRUE (Client.GetIsConnected ());
938+ }
939+ }
940+ }
941+ }
942+
823943void
824944QuicTestConnectUnreachable (
825945 _In_ int Family
0 commit comments