Skip to content

Commit

Permalink
go/mysql: Fix TLS test for Go 1.13+.
Browse files Browse the repository at this point in the history
The default TLS version changed, so we need to check the appropriate
counter.

Signed-off-by: Anthony Yeh <[email protected]>
  • Loading branch information
enisoc committed May 15, 2020
1 parent 17dd6c6 commit 1c81ac2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ MAKEFLAGS = -s

export GOBIN=$(PWD)/bin
export GO111MODULE=on
export GODEBUG=tls13=0
export REWRITER=go/vt/sqlparser/rewriter.go

# Disabled parallel processing of target prerequisites to avoid that integration tests are racing each other (e.g. for ports) and may fail.
Expand Down
3 changes: 3 additions & 0 deletions go/mysql/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
versionTLS10 = "TLS10"
versionTLS11 = "TLS11"
versionTLS12 = "TLS12"
versionTLS13 = "TLS13"
versionTLSUnknown = "UnknownTLSVersion"
versionNoTLS = "None"
)
Expand Down Expand Up @@ -798,6 +799,8 @@ func tlsVersionToString(version uint16) string {
return versionTLS11
case tls.VersionTLS12:
return versionTLS12
case tls.VersionTLS13:
return versionTLS13
default:
return versionTLSUnknown
}
Expand Down
9 changes: 7 additions & 2 deletions go/mysql/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package mysql

import (
"crypto/tls"
"fmt"
"io/ioutil"
"net"
Expand Down Expand Up @@ -1006,7 +1007,11 @@ func TestTLSServer(t *testing.T) {
t.Errorf("Unexpected output for 'ssl echo': %v", results)
}

checkCountForTLSVer(t, versionTLS12, 1)
// Find out which TLS version the connection actually used,
// so we can check that the corresponding counter was incremented.
tlsVersion := conn.conn.(*tls.Conn).ConnectionState().Version

checkCountForTLSVer(t, tlsVersionToString(tlsVersion), 1)
checkCountForTLSVer(t, versionNoTLS, 0)
conn.Close()

Expand Down Expand Up @@ -1101,7 +1106,7 @@ func checkCountForTLSVer(t *testing.T, version string, expected int64) {
t.Errorf("Expected connection count for version %s to be %d, got %d", version, expected, count)
}
} else {
t.Errorf("No count found for version %s", version)
t.Errorf("No count for version %s found in %v", version, connCounts)
}
}

Expand Down

0 comments on commit 1c81ac2

Please sign in to comment.