Skip to content

Commit 8937cb7

Browse files
committed
add test
1 parent 7a1f3ff commit 8937cb7

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/SqlConnectionPoolKey.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ internal SqlConnectionPoolKey(
4040
SqlCredential credential,
4141
string accessToken,
4242
Func<SqlAuthenticationParameters, CancellationToken, Task<SqlAuthenticationToken>> accessTokenCallback,
43-
SspiContextProvider sspiContextProvider
44-
) : base(connectionString)
43+
SspiContextProvider sspiContextProvider) : base(connectionString)
4544
{
4645
Debug.Assert(credential == null || accessToken == null || accessTokenCallback == null, "Credential, AccessToken, and Callback can't have a value at the same time.");
4746
_credential = credential;

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)