Skip to content

Commit 5bb128f

Browse files
committed
add test
1 parent 7a1f3ff commit 5bb128f

File tree

1 file changed

+39
-0
lines changed
  • src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/KerberosTests

1 file changed

+39
-0
lines changed

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/KerberosTests/KerberosTest.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System;
6+
using System.Buffers;
57
using System.Collections;
68
using System.Collections.Generic;
79
using Xunit;
@@ -24,6 +26,43 @@ public void IsKerBerosSetupTestAsync(string connectionStr)
2426
Assert.True(reader.Read(), "Expected to receive one row data");
2527
Assert.Equal("KERBEROS", reader.GetString(0));
2628
}
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+
}
2766
}
2867

2968
public class ConnectionStringsProvider : IEnumerable<object[]>

0 commit comments

Comments
 (0)