@@ -16,6 +16,7 @@ public class HttpListenerWebSocketTests : IDisposable
16
16
{
17
17
public static bool IsNotWindows7 { get ; } = ! PlatformDetection . IsWindows7 ;
18
18
public static bool IsNotWindows7AndIsWindowsImplementation => IsNotWindows7 && Helpers . IsWindowsImplementation ;
19
+ public static bool IsWindows8OrLater { get ; } = PlatformDetection . IsWindows8xOrLater ;
19
20
20
21
private HttpListenerFactory Factory { get ; }
21
22
private HttpListener Listener { get ; }
@@ -363,6 +364,41 @@ public async Task Abort_CallAfterAborted_Nop()
363
364
Assert . Equal ( WebSocketState . Aborted , context . WebSocket . State ) ;
364
365
}
365
366
367
+ [ ConditionalFact ( nameof ( IsWindows8OrLater ) ) ]
368
+ public async Task ReceiveAsync_ReadBuffer_WithWindowsAuthScheme_Success ( )
369
+ {
370
+ HttpListenerFactory factory = new HttpListenerFactory ( authenticationSchemes : AuthenticationSchemes . IntegratedWindowsAuthentication ) ;
371
+ var uriBuilder = new UriBuilder ( factory . ListeningUrl ) { Scheme = "ws" } ;
372
+ Task < HttpListenerContext > serverContextTask = factory . GetListener ( ) . GetContextAsync ( ) ;
373
+ ClientWebSocket client = new ClientWebSocket ( ) ;
374
+ client . Options . Credentials = CredentialCache . DefaultCredentials ;
375
+
376
+ Task clientConnectTask = client . ConnectAsync ( uriBuilder . Uri , CancellationToken . None ) ;
377
+ if ( clientConnectTask == await Task . WhenAny ( serverContextTask , clientConnectTask ) )
378
+ {
379
+ await clientConnectTask ;
380
+ Assert . True ( false , "Client should not have completed prior to server sending response" ) ;
381
+ }
382
+
383
+ HttpListenerContext context = await serverContextTask ;
384
+ HttpListenerWebSocketContext wsContext = await context . AcceptWebSocketAsync ( null ) ;
385
+ await clientConnectTask ;
386
+
387
+ const string Text = "Hello Web Socket" ;
388
+ byte [ ] sentBytes = Encoding . ASCII . GetBytes ( Text ) ;
389
+
390
+ await client . SendAsync ( new ArraySegment < byte > ( sentBytes ) , WebSocketMessageType . Text , true , new CancellationToken ( ) ) ;
391
+
392
+ byte [ ] receivedBytes = new byte [ sentBytes . Length ] ;
393
+ WebSocketReceiveResult result = await ReceiveAllAsync ( wsContext . WebSocket , receivedBytes . Length , receivedBytes ) ;
394
+ Assert . Equal ( WebSocketMessageType . Text , result . MessageType ) ;
395
+ Assert . True ( result . EndOfMessage ) ;
396
+ Assert . Null ( result . CloseStatus ) ;
397
+ Assert . Null ( result . CloseStatusDescription ) ;
398
+
399
+ Assert . Equal ( Text , Encoding . ASCII . GetString ( receivedBytes ) ) ;
400
+ }
401
+
366
402
private static async Task < WebSocketReceiveResult > ReceiveAllAsync ( WebSocket webSocket , int expectedBytes , byte [ ] buffer )
367
403
{
368
404
int totalReceived = 0 ;
0 commit comments