Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - please ignore | Test the ActiveIssue tests #3007

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,22 +195,49 @@ steps:
displayName: 'Setup SQL Alias [Win]'
condition: ${{parameters.condition }}

- powershell: |
# Create Certificate
$computerDnsName = [System.Net.Dns]::Resolve($null).HostName
$certificate = New-SelfSignedCertificate -DnsName $computerDnsName,localhost -CertStoreLocation cert:\LocalMachine\My -FriendlyName test99 -KeySpec KeyExchange

# Get path to Private key (used later)
$keyPath = $certificate.PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName
$machineKeyPath = "$env:ProgramData\Microsoft\Crypto\RSA\MachineKeys\$keyPath"

# Add certificate to trusted roots
$store = new-object System.Security.Cryptography.X509Certificates.X509Store(
[System.Security.Cryptography.X509Certificates.StoreName]::Root,
"localmachine"
)

$store.open("MaxAllowed")
$store.add($certificate)
$store.close()

# Get SQL Server instances and add the Certificate
$instances = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL'
foreach ($instance in $instances){
$instance | ForEach-Object {
$_.PSObject.Properties | Where-Object { $_.Name -notmatch '^PS.*' } | ForEach-Object {
Write-Output "Configuring instance $($_.Name) (Value: $($_.Value))"
Set-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($_.Value)\MSSQLServer\SuperSocketNetLib" -Name Certificate -Value $certificate.Thumbprint.ToLower()

# Grant read access to Private Key for SQL Service Account
if ($($_.Name) -eq "MSSQLSERVER") {
icacls $machineKeyPath /grant "NT Service\MSSQLSERVER:R"
} else {
icacls $machineKeyPath /grant "NT Service\MSSQL`$$($_.Name):R"
}
}
}
}
displayName: 'Add SQL Certificate [Win]'
condition: ${{parameters.condition }}

- powershell: |
# You need to restart SQL Server for the change to persist
# -Force takes care of any dependent services, like SQL Agent.
# Note: if the instance is named, replace MSSQLSERVER with MSSQL$ followed by
# the name of the instance (e.g. MSSQL$MYINSTANCE)

$serviceName = "${{parameters.instanceName }}"
$InstancePrefix = 'MSSQL$'

if ( "${{parameters.instanceName }}" -ne "MSSQLSERVER" )
{
$serviceName = $InstancePrefix+"${{parameters.instanceName }}"
}

Restart-Service -Name "$serviceName" -Force

Get-Service MSSQL* | Restart-Service -Force
displayName: 'Restart SQL Server [Win]'
condition: ${{parameters.condition }}

Expand Down
2 changes: 2 additions & 0 deletions eng/pipelines/common/templates/steps/run-all-tests-step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ steps:
- ${{if eq(parameters.operatingSystem, 'Windows')}}:
- task: MSBuild@1
displayName: 'Run Functional Tests ${{parameters.msbuildArchitecture }}'
enabled: false
inputs:
solution: build.proj
msbuildArchitecture: ${{parameters.msbuildArchitecture }}
Expand Down Expand Up @@ -84,6 +85,7 @@ steps:
- ${{ else }}: # Linux or macOS
- task: DotNetCoreCLI@2
displayName: 'Run Functional Tests'
enabled: false
inputs:
command: custom
projects: build.proj
Expand Down
6 changes: 3 additions & 3 deletions eng/pipelines/dotnet-sqlclient-ci-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ parameters:
- name: targetFrameworks
displayName: 'Target Frameworks on Windows'
type: object
default: [net462, net8.0, net9.0]
default: [net462, net8.0]

- name: targetFrameworksLinux
displayName: 'Target Frameworks on Non-Windows'
type: object
default: [net8.0, net9.0]
default: [net8.0]

- name: netcoreVersionTestUtils
displayName: 'Netcore Version for Test Utilities'
Expand All @@ -32,7 +32,7 @@ parameters:
- name: testSets
displayName: 'Test Sets'
type: object
default: [1, 2, 3]
default: [2]

- name: useManagedSNI
displayName: |
Expand Down
31 changes: 0 additions & 31 deletions eng/pipelines/dotnet-sqlclient-ci-package-reference-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,6 @@
#################################################################################

name: $(DayOfYear)$(Rev:rr)
trigger:
batch: true
branches:
include:
- main
- internal/main
paths:
include:
- src\Microsoft.Data.SqlClient\netcore\ref
- src\Microsoft.Data.SqlClient\netfx\ref
- src\Microsoft.Data.SqlClient\ref
- eng
- tools
- .config
- Nuget.config

schedules:
- cron: '0 4 * * Fri'
displayName: Weekly Thursday 9:00 PM (UTC - 7) Build
branches:
include:
- internal/main
always: true

- cron: '0 0 * * Mon-Fri'
displayName: Daily build 5:00 PM (UTC - 7) Build
branches:
include:
- main
always: true

parameters: # parameters are shown up in ADO UI in a build queue time
- name: 'debug'
displayName: 'Enable debug output'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,8 @@ public static bool IsAdmin
{
get
{
#if !NETFRAMEWORK
System.Diagnostics.Debug.Assert(OperatingSystem.IsWindows());
#endif
return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
return !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|| new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
}
}

Expand Down Expand Up @@ -454,7 +452,18 @@ public static bool IsAADAuthorityURLSetup()

public static bool IsNotAzureServer()
{
return !AreConnStringsSetup() || !Utils.IsAzureSqlServer(new SqlConnectionStringBuilder((TCPConnectionString)).DataSource);
return !AreConnStringsSetup() || !Utils.IsAzureSqlServer(new SqlConnectionStringBuilder(TCPConnectionString).DataSource);
}

public static bool IsNotNamedInstance()
{
return !AreConnStringsSetup() || !new SqlConnectionStringBuilder(TCPConnectionString).DataSource.Contains(@"\");
}

public static bool IsLocalHost()
{
SqlConnectionStringBuilder builder = new(DataTestUtility.TCPConnectionString);
return ParseDataSource(builder.DataSource, out string hostname, out _, out _) && string.Equals("localhost", hostname, StringComparison.OrdinalIgnoreCase);
}

// Synapse: Always Encrypted is not supported with Azure Synapse.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.ServiceProcess;
using System.Text;
using Microsoft.Win32;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Data.SqlClient.ManualTesting.Tests
{
Expand All @@ -38,6 +40,8 @@ public class CertificateTest : IDisposable
// SlashInstance is used to override IPV4 and IPV6 defined about so it includes an instance name
private static string SlashInstanceName = "";

private readonly ITestOutputHelper _testOutputHelper;

private static string ForceEncryptionRegistryPath
{
get
Expand All @@ -59,8 +63,9 @@ private static string ForceEncryptionRegistryPath
}
#endregion

public CertificateTest()
public CertificateTest(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
SqlConnectionStringBuilder builder = new(DataTestUtility.TCPConnectionString);
Assert.True(DataTestUtility.ParseDataSource(builder.DataSource, out string hostname, out _, out string instanceName));
if (!LocalHost.Equals(hostname, StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -166,24 +171,29 @@ public void OpeningConnectionWitHNICTest()
}
}

[ActiveIssue("31754")]
[ConditionalFact(nameof(AreConnStringsSetup), nameof(UseManagedSNIOnWindows), nameof(IsNotAzureServer), nameof(IsLocalHost))]
[ConditionalFact(nameof(AreConnStringsSetup), nameof(IsNotAzureServer), nameof(IsLocalHost), nameof(UseManagedSNIOnWindows))]
[PlatformSpecific(TestPlatforms.Windows)]
public void RemoteCertificateNameMismatchErrorTest()
{
SqlConnectionStringBuilder builder = new(DataTestUtility.TCPConnectionString)
{
DataSource = GetLocalIpAddress(),
Encrypt = SqlConnectionEncryptOption.Mandatory,
TrustServerCertificate = false,
HostNameInCertificate = "BadHostName"
};
using SqlConnection connection = new(builder.ConnectionString);
SqlException exception = Assert.Throws<SqlException>(() => connection.Open());
Assert.StartsWith("A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)", exception.Message);

_testOutputHelper.WriteLine("Actual exception:");
_testOutputHelper.WriteLine(exception.ToString());

_testOutputHelper.WriteLine("Actual inner exception:");
_testOutputHelper.WriteLine(exception.InnerException?.ToString() ?? "None");
Assert.Equal(20, exception.Class);
Assert.StartsWith("A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)", exception.Message);
Assert.IsType<AuthenticationException>(exception.InnerException);
Assert.StartsWith("Certificate name mismatch. The provided 'DataSource' or 'HostNameInCertificate' does not match the name in the certificate.", exception.InnerException.Message);
Console.WriteLine(exception.Message);
}

private static void CreateValidCertificate(string script)
Expand Down
Loading
Loading