@@ -793,6 +793,98 @@ void ConfigureListenOptions(ListenOptions listenOptions)
793793 await AssertConnectionResult ( stream , true , expectedBody ) ;
794794 }
795795
796+ [ ConditionalFact ]
797+ [ OSSkipCondition ( OperatingSystems . MacOSX , SkipReason = "ALPN not supported" ) ]
798+ public async Task ServerOptionsSelectionCallback_SetsALPN ( )
799+ {
800+ static void ConfigureListenOptions ( ListenOptions listenOptions )
801+ {
802+ listenOptions . UseHttps ( ( _ , _ , _ , _ ) =>
803+ ValueTask . FromResult ( new SslServerAuthenticationOptions ( )
804+ {
805+ ServerCertificate = _x509Certificate2 ,
806+ } ) , state : null ) ;
807+ }
808+
809+ await using var server = new TestServer ( context => Task . CompletedTask ,
810+ new TestServiceContext ( LoggerFactory ) , ConfigureListenOptions ) ;
811+
812+ using var connection = server . CreateConnection ( ) ;
813+ var stream = OpenSslStream ( connection . Stream ) ;
814+ await stream . AuthenticateAsClientAsync ( new SslClientAuthenticationOptions ( )
815+ {
816+ // Use a random host name to avoid the TLS session resumption cache.
817+ TargetHost = Guid . NewGuid ( ) . ToString ( ) ,
818+ ApplicationProtocols = new ( ) { SslApplicationProtocol . Http2 , SslApplicationProtocol . Http11 , } ,
819+ } ) ;
820+ Assert . Equal ( SslApplicationProtocol . Http2 , stream . NegotiatedApplicationProtocol ) ;
821+ }
822+
823+ [ ConditionalFact ]
824+ [ OSSkipCondition ( OperatingSystems . MacOSX , SkipReason = "ALPN not supported" ) ]
825+ public async Task TlsHandshakeCallbackOptionsOverload_SetsALPN ( )
826+ {
827+ static void ConfigureListenOptions ( ListenOptions listenOptions )
828+ {
829+ listenOptions . UseHttps ( new TlsHandshakeCallbackOptions ( )
830+ {
831+ OnConnection = context =>
832+ {
833+ return ValueTask . FromResult ( new SslServerAuthenticationOptions ( )
834+ {
835+ ServerCertificate = _x509Certificate2 ,
836+ } ) ;
837+ }
838+ } ) ;
839+ }
840+
841+ await using var server = new TestServer ( context => Task . CompletedTask ,
842+ new TestServiceContext ( LoggerFactory ) , ConfigureListenOptions ) ;
843+
844+ using var connection = server . CreateConnection ( ) ;
845+ var stream = OpenSslStream ( connection . Stream ) ;
846+ await stream . AuthenticateAsClientAsync ( new SslClientAuthenticationOptions ( )
847+ {
848+ // Use a random host name to avoid the TLS session resumption cache.
849+ TargetHost = Guid . NewGuid ( ) . ToString ( ) ,
850+ ApplicationProtocols = new ( ) { SslApplicationProtocol . Http2 , SslApplicationProtocol . Http11 , } ,
851+ } ) ;
852+ Assert . Equal ( SslApplicationProtocol . Http2 , stream . NegotiatedApplicationProtocol ) ;
853+ }
854+
855+ [ ConditionalFact ]
856+ [ OSSkipCondition ( OperatingSystems . MacOSX , SkipReason = "ALPN not supported" ) ]
857+ public async Task TlsHandshakeCallbackOptionsOverload_EmptyAlpnList_DisablesAlpn ( )
858+ {
859+ static void ConfigureListenOptions ( ListenOptions listenOptions )
860+ {
861+ listenOptions . UseHttps ( new TlsHandshakeCallbackOptions ( )
862+ {
863+ OnConnection = context =>
864+ {
865+ return ValueTask . FromResult ( new SslServerAuthenticationOptions ( )
866+ {
867+ ServerCertificate = _x509Certificate2 ,
868+ ApplicationProtocols = new ( ) ,
869+ } ) ;
870+ }
871+ } ) ;
872+ }
873+
874+ await using var server = new TestServer ( context => Task . CompletedTask ,
875+ new TestServiceContext ( LoggerFactory ) , ConfigureListenOptions ) ;
876+
877+ using var connection = server . CreateConnection ( ) ;
878+ var stream = OpenSslStream ( connection . Stream ) ;
879+ await stream . AuthenticateAsClientAsync ( new SslClientAuthenticationOptions ( )
880+ {
881+ // Use a random host name to avoid the TLS session resumption cache.
882+ TargetHost = Guid . NewGuid ( ) . ToString ( ) ,
883+ ApplicationProtocols = new ( ) { SslApplicationProtocol . Http2 , SslApplicationProtocol . Http11 , } ,
884+ } ) ;
885+ Assert . Equal ( default , stream . NegotiatedApplicationProtocol ) ;
886+ }
887+
796888 [ ConditionalFact ]
797889 [ OSSkipCondition ( OperatingSystems . MacOSX | OperatingSystems . Linux , SkipReason = "Not supported yet." ) ]
798890 public async Task CanRenegotiateForClientCertificateOnPostIfDrained ( )
0 commit comments