2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
// See the LICENSE file in the project root for more information.
4
4
5
+ using System ;
6
+ using System . Buffers ;
5
7
using System . Collections ;
6
8
using System . Collections . Generic ;
7
9
using Xunit ;
@@ -24,6 +26,43 @@ public void IsKerBerosSetupTestAsync(string connectionStr)
24
26
Assert . True ( reader . Read ( ) , "Expected to receive one row data" ) ;
25
27
Assert . Equal ( "KERBEROS" , reader . GetString ( 0 ) ) ;
26
28
}
29
+
30
+ [ PlatformSpecific ( TestPlatforms . AnyUnix ) ]
31
+ [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . IsKerberosTest ) ) ]
32
+ [ ClassData ( typeof ( ConnectionStringsProvider ) ) ]
33
+ public void CustomSspiContextGeneratorTest ( string connectionStr )
34
+ {
35
+ KerberosTicketManagemnt . Init ( DataTestUtility . KerberosDomainUser , DataTestUtility . KerberosDomainPassword ) ;
36
+
37
+ using SqlConnection conn = new ( connectionStr )
38
+ {
39
+ SspiContextProvider = new TestSspiContextProvider ( ) ,
40
+ } ;
41
+
42
+ try
43
+ {
44
+ conn . Open ( ) ;
45
+ using SqlCommand command = new ( "SELECT auth_scheme from sys.dm_exec_connections where session_id = @@spid" , conn ) ;
46
+ using SqlDataReader reader = command . ExecuteReader ( ) ;
47
+
48
+ Assert . Fail ( "Expected to use custom SSPI context provider" ) ;
49
+ }
50
+ catch ( SspiTestException )
51
+ {
52
+ }
53
+ }
54
+
55
+ private sealed class TestSspiContextProvider : SspiContextProvider
56
+ {
57
+ protected override bool GenerateContext ( ReadOnlySpan < byte > incomingBlob , IBufferWriter < byte > outgoingBlobWriter , SspiAuthenticationParameters authParams )
58
+ {
59
+ throw new SspiTestException ( ) ;
60
+ }
61
+ }
62
+
63
+ private sealed class SspiTestException : Exception
64
+ {
65
+ }
27
66
}
28
67
29
68
public class ConnectionStringsProvider : IEnumerable < object [ ] >
0 commit comments