File tree Expand file tree Collapse file tree 3 files changed +50
-16
lines changed 
System.Net.Http/tests/FunctionalTests 
System.Net.Security/src/System/Net Expand file tree Collapse file tree 3 files changed +50
-16
lines changed Original file line number Diff line number Diff line change @@ -139,5 +139,32 @@ await server.AcceptConnectionAsync(async connection =>
139139                    } ) . ConfigureAwait ( false ) ; 
140140                } ) ; 
141141        } 
142+ 
143+         [ Fact ] 
144+         [ SkipOnPlatform ( TestPlatforms . Browser  |  TestPlatforms . Windows ,  "DefaultCredentials are unsupported for NTLM on Unix / Managed implementation" ) ] 
145+         public  async  Task  DefaultHandler_FakeServer_DefaultCredentials ( ) 
146+         { 
147+             await  LoopbackServer . CreateClientAndServerAsync ( 
148+                 async  uri => 
149+                 { 
150+                     HttpRequestMessage  requestMessage  =  new  HttpRequestMessage ( HttpMethod . Get ,  uri ) ; 
151+                     requestMessage . Version  =  new  Version ( 1 ,  1 ) ; 
152+                     HttpMessageHandler  handler  =  new  HttpClientHandler ( )  {  Credentials  =  CredentialCache . DefaultCredentials  } ; 
153+                     using  ( var  client  =  new  HttpClient ( handler ) ) 
154+                     { 
155+                         HttpResponseMessage  response  =  await  client . SendAsync ( requestMessage ) ; 
156+                         Assert . Equal ( HttpStatusCode . Unauthorized ,  response . StatusCode ) ; 
157+                     } 
158+                 } , 
159+                 async  server => 
160+                 { 
161+                     await  server . AcceptConnectionAsync ( async  connection => 
162+                     { 
163+                         var  authHeader  =  "WWW-Authenticate: NTLM\r \n " ; 
164+                         await  connection . SendResponseAsync ( HttpStatusCode . Unauthorized ,  authHeader ) . ConfigureAwait ( false ) ; 
165+                         connection . CompleteRequestProcessing ( ) ; 
166+                     } ) . ConfigureAwait ( false ) ; 
167+                 } ) ; 
168+         } 
142169    } 
143170} 
Original file line number Diff line number Diff line change @@ -9,16 +9,23 @@ internal abstract partial class NegotiateAuthenticationPal
99    { 
1010        public  static NegotiateAuthenticationPal  Create ( NegotiateAuthenticationClientOptions  clientOptions ) 
1111        { 
12-             switch   ( clientOptions . Package ) 
12+             try 
1313            { 
14-                 case  NegotiationInfoClass . NTLM : 
15-                     return  new  ManagedNtlmNegotiateAuthenticationPal ( clientOptions ) ; 
14+                 switch  ( clientOptions . Package ) 
15+                 { 
16+                     case  NegotiationInfoClass . NTLM : 
17+                         return  new  ManagedNtlmNegotiateAuthenticationPal ( clientOptions ) ; 
1618
17-                 case  NegotiationInfoClass . Negotiate : 
18-                     return  new  ManagedSpnegoNegotiateAuthenticationPal ( clientOptions ) ; 
19+                      case  NegotiationInfoClass . Negotiate : 
20+                          return  new  ManagedSpnegoNegotiateAuthenticationPal ( clientOptions ) ; 
1921
20-                 default : 
21-                     return  new  UnsupportedNegotiateAuthenticationPal ( clientOptions ) ; 
22+                     default : 
23+                         return  new  UnsupportedNegotiateAuthenticationPal ( clientOptions ) ; 
24+                 } 
25+             } 
26+             catch  ( PlatformNotSupportedException ) 
27+             { 
28+                 return  new  UnsupportedNegotiateAuthenticationPal ( clientOptions ) ; 
2229            } 
2330        } 
2431
Original file line number Diff line number Diff line change @@ -23,20 +23,20 @@ internal partial class NegotiateAuthenticationPal
2323
2424        public  static NegotiateAuthenticationPal  Create ( NegotiateAuthenticationClientOptions  clientOptions ) 
2525        { 
26-             if   ( UseManagedNtlm ) 
26+             try 
2727            { 
28-                 switch   ( clientOptions . Package ) 
28+                 if   ( UseManagedNtlm ) 
2929                { 
30-                     case  NegotiationInfoClass . NTLM : 
31-                         return  new  ManagedNtlmNegotiateAuthenticationPal ( clientOptions ) ; 
30+                     switch  ( clientOptions . Package ) 
31+                     { 
32+                         case  NegotiationInfoClass . NTLM : 
33+                             return  new  ManagedNtlmNegotiateAuthenticationPal ( clientOptions ) ; 
3234
33-                     case  NegotiationInfoClass . Negotiate : 
34-                         return  new  ManagedSpnegoNegotiateAuthenticationPal ( clientOptions ,  supportKerberos :  true ) ; 
35+                         case  NegotiationInfoClass . Negotiate : 
36+                             return  new  ManagedSpnegoNegotiateAuthenticationPal ( clientOptions ,  supportKerberos :  true ) ; 
37+                     } 
3538                } 
36-             } 
3739
38-             try 
39-             { 
4040                return  new  UnixNegotiateAuthenticationPal ( clientOptions ) ; 
4141            } 
4242            catch  ( Win32Exception ) 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments