|
1 | 1 | package msdsn |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "crypto/tls" |
4 | 5 | "reflect" |
5 | 6 | "testing" |
6 | 7 | "time" |
@@ -59,7 +60,23 @@ func TestValidConnectionString(t *testing.T) { |
59 | 60 | {"failoverpartner=fopartner;failoverport=2000", func(p Config) bool { return p.FailOverPartner == "fopartner" && p.FailOverPort == 2000 }}, |
60 | 61 | {"app name=appname;applicationintent=ReadOnly;database=testdb", func(p Config) bool { return p.AppName == "appname" && p.ReadOnlyIntent }}, |
61 | 62 | {"encrypt=disable", func(p Config) bool { return p.Encryption == EncryptionDisabled }}, |
62 | | - {"encrypt=true", func(p Config) bool { return p.Encryption == EncryptionRequired }}, |
| 63 | + {"encrypt=disable;tlsmin=1.1", func(p Config) bool { return p.Encryption == EncryptionDisabled && p.TLSConfig == nil }}, |
| 64 | + {"encrypt=true", func(p Config) bool { return p.Encryption == EncryptionRequired && p.TLSConfig.MinVersion == 0 }}, |
| 65 | + {"encrypt=true;tlsmin=1.0", func(p Config) bool { |
| 66 | + return p.Encryption == EncryptionRequired && p.TLSConfig.MinVersion == tls.VersionTLS10 |
| 67 | + }}, |
| 68 | + {"encrypt=false;tlsmin=1.0", func(p Config) bool { |
| 69 | + return p.Encryption == EncryptionOff && p.TLSConfig.MinVersion == tls.VersionTLS10 |
| 70 | + }}, |
| 71 | + {"encrypt=true;tlsmin=1.1", func(p Config) bool { |
| 72 | + return p.Encryption == EncryptionRequired && p.TLSConfig.MinVersion == tls.VersionTLS11 |
| 73 | + }}, |
| 74 | + {"encrypt=true;tlsmin=1.2", func(p Config) bool { |
| 75 | + return p.Encryption == EncryptionRequired && p.TLSConfig.MinVersion == tls.VersionTLS12 |
| 76 | + }}, |
| 77 | + {"encrypt=true;tlsmin=1.4", func(p Config) bool { |
| 78 | + return p.Encryption == EncryptionRequired && p.TLSConfig.MinVersion == 0 |
| 79 | + }}, |
63 | 80 | {"encrypt=false", func(p Config) bool { return p.Encryption == EncryptionOff }}, |
64 | 81 | {"connection timeout=3;dial timeout=4;keepalive=5", func(p Config) bool { |
65 | 82 | return p.ConnTimeout == 3*time.Second && p.DialTimeout == 4*time.Second && p.KeepAlive == 5*time.Second |
@@ -159,6 +176,9 @@ func TestValidConnectionString(t *testing.T) { |
159 | 176 | {"sqlserver://someuser@somehost?connection+timeout=30&disableretry=1", func(p Config) bool { |
160 | 177 | return p.Host == "somehost" && p.Port == 0 && p.Instance == "" && p.User == "someuser" && p.Password == "" && p.ConnTimeout == 30*time.Second && p.DisableRetry |
161 | 178 | }}, |
| 179 | + {"sqlserver://somehost?encrypt=true&tlsmin=1.1", func(p Config) bool { |
| 180 | + return p.Host == "somehost" && p.Encryption == EncryptionRequired && p.TLSConfig.MinVersion == tls.VersionTLS11 |
| 181 | + }}, |
162 | 182 | } |
163 | 183 | for _, ts := range connStrings { |
164 | 184 | p, _, err := Parse(ts.connStr) |
|
0 commit comments