|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.IO; |
| 7 | +using Microsoft.SqlServer.TDS.PreLogin; |
| 8 | + |
| 9 | +namespace Microsoft.Data.SqlClient.ManualTesting.Tests.DataCommon |
| 10 | +{ |
| 11 | + public class ConnectionTestParametersData |
| 12 | + { |
| 13 | + private const int CASES = 30; |
| 14 | + private string _empty = string.Empty; |
| 15 | + // It was advised to store the client certificate in its own folder. |
| 16 | + private static readonly string s_fullPathToCer = Path.Combine(Directory.GetCurrentDirectory(), "clientcert", "localhostcert.cer"); |
| 17 | + private static readonly string s_mismatchedcert = Path.Combine(Directory.GetCurrentDirectory(), "clientcert", "mismatchedcert.cer"); |
| 18 | + |
| 19 | + private static readonly string s_hostName = System.Net.Dns.GetHostName(); |
| 20 | + public static ConnectionTestParametersData Data { get; } = new ConnectionTestParametersData(); |
| 21 | + public List<ConnectionTestParameters> ConnectionTestParametersList { get; set; } |
| 22 | + |
| 23 | + public static IEnumerable<object[]> GetConnectionTestParameters() |
| 24 | + { |
| 25 | + for (int i = 0; i < CASES; i++) |
| 26 | + { |
| 27 | + yield return new object[] { Data.ConnectionTestParametersList[i] }; |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + public ConnectionTestParametersData() |
| 32 | + { |
| 33 | + // Test cases possible field values for connection parameters: |
| 34 | + // These combinations are based on the possible values of Encrypt, TrustServerCertificate, Certificate, HostNameInCertificate |
| 35 | + /* |
| 36 | + * TDSEncryption | Encrypt | TrustServerCertificate | Certificate | HNIC | TestResults |
| 37 | + * ---------------------------------------------------------------------------------------------- |
| 38 | + * Off | Optional | true | valid | valid name | true |
| 39 | + * On | Mandatory | false | mismatched | empty | false |
| 40 | + * Required | | x | ChainError? | wrong name? | |
| 41 | + */ |
| 42 | + ConnectionTestParametersList = new List<ConnectionTestParameters> |
| 43 | + { |
| 44 | + // TDSPreLoginTokenEncryptionType.Off |
| 45 | + new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Optional, false, _empty, _empty, true), |
| 46 | + new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, false, _empty, _empty, false), |
| 47 | + new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Optional, true, _empty, _empty, true), |
| 48 | + new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, true, _empty, _empty, true), |
| 49 | + new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, false, s_fullPathToCer, _empty, true), |
| 50 | + new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, true, s_fullPathToCer, _empty, true), |
| 51 | + new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, false, _empty, s_hostName, false), |
| 52 | + new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, true, _empty, s_hostName, true), |
| 53 | + |
| 54 | + // TDSPreLoginTokenEncryptionType.On |
| 55 | + new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Optional, false, _empty, _empty, false), |
| 56 | + new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Mandatory, false, _empty, _empty, false), |
| 57 | + new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Optional, true, _empty, _empty, true), |
| 58 | + new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Mandatory, true, _empty, _empty, true), |
| 59 | + new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Mandatory, false, s_fullPathToCer, _empty, true), |
| 60 | + new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Mandatory, true, s_fullPathToCer, _empty, true), |
| 61 | + new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Mandatory, false, _empty, s_hostName, false), |
| 62 | + new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Mandatory, true, _empty, s_hostName, true), |
| 63 | + |
| 64 | + // TDSPreLoginTokenEncryptionType.Required |
| 65 | + new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Optional, false, _empty, _empty, false), |
| 66 | + new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Mandatory, false, _empty, _empty, false), |
| 67 | + new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Optional, true, _empty, _empty, true), |
| 68 | + new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Mandatory, true, _empty, _empty, true), |
| 69 | + new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Mandatory, false, s_fullPathToCer, _empty, true), |
| 70 | + new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Mandatory, true, s_fullPathToCer, _empty, true), |
| 71 | + new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Mandatory, false, _empty, s_hostName, false), |
| 72 | + new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Mandatory, true, _empty, s_hostName, true), |
| 73 | + |
| 74 | + // Mismatched certificate test |
| 75 | + new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, false, s_mismatchedcert, _empty, false), |
| 76 | + new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, true, s_mismatchedcert, _empty, false), |
| 77 | + new(TDSPreLoginTokenEncryptionType.Off, SqlConnectionEncryptOption.Mandatory, true, s_mismatchedcert, _empty, true), |
| 78 | + new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Mandatory, false, s_mismatchedcert, _empty, false), |
| 79 | + new(TDSPreLoginTokenEncryptionType.On, SqlConnectionEncryptOption.Mandatory, true, s_mismatchedcert, _empty, true), |
| 80 | + new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Mandatory, false, s_mismatchedcert, _empty, false), |
| 81 | + new(TDSPreLoginTokenEncryptionType.Required, SqlConnectionEncryptOption.Mandatory, true, s_mismatchedcert, _empty, true), |
| 82 | + }; |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments