78a008daf6
types: add TLS constants types: distinguish between human and Envoy serialization for TLSVersion constants types: add DeprecatedAgentTLSVersions for backwards compatibility types: add methods for printing TLSVersion as strings types: add TLSVersionInvalid error value types: add a basic test for TLSVersion comparison types: add TLS cihper suite mapping using IANA constant names and values types: adding ConsulAutoConfigTLSVersionStrings changelog: add entry for TLSVersion and TLSCipherSuite types types: initialize TLSVerison constants starting at zero types: remove TLSVersionInvalid < 0 test types: update note for ConsulAutoConfigTLSVersionStrings types: programmatically invert TLSCipherSuites for HumanTLSCipherSuiteStrings lookup map Co-authored-by: Dan Upton <daniel@floppy.co> types: add test for TLSVersion zero-value types: remove unused EnvoyTLSVersionStrings types: implement MarshalJSON for TLSVersion types: implement TLSVersionUnspecified as zero value types: delegate TLS.MarshalJSON to json.Marshal, use ConsulConfigTLSVersionStrings as default String() values Co-authored-by: Dan Upton <daniel@floppy.co>
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package types
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestTLSVersion_PartialEq(t *testing.T) {
|
|
require.Greater(t, TLSv1_3, TLSv1_2)
|
|
require.Greater(t, TLSv1_2, TLSv1_1)
|
|
require.Greater(t, TLSv1_1, TLSv1_0)
|
|
|
|
require.Less(t, TLSv1_2, TLSv1_3)
|
|
require.Less(t, TLSv1_1, TLSv1_2)
|
|
require.Less(t, TLSv1_0, TLSv1_1)
|
|
}
|
|
|
|
func TestTLSVersion_Invalid(t *testing.T) {
|
|
var zeroValue TLSVersion
|
|
require.NotEqual(t, TLSVersionInvalid, zeroValue)
|
|
require.NotEqual(t, TLSVersionInvalid, TLSVersionUnspecified)
|
|
require.NotEqual(t, TLSVersionInvalid, TLSVersionAuto)
|
|
}
|
|
|
|
func TestTLSVersion_Zero(t *testing.T) {
|
|
var zeroValue TLSVersion
|
|
require.Equal(t, TLSVersionUnspecified, zeroValue)
|
|
require.NotEqual(t, TLSVersionUnspecified, TLSVersionInvalid)
|
|
require.NotEqual(t, TLSVersionUnspecified, TLSVersionAuto)
|
|
}
|
|
|
|
func TestTLSVersion_ToJSON(t *testing.T) {
|
|
var tlsVersion TLSVersion
|
|
err := tlsVersion.UnmarshalJSON([]byte(`"foo"`))
|
|
require.Error(t, err)
|
|
require.Equal(t, tlsVersion, TLSVersionInvalid)
|
|
|
|
for str, version := range TLSVersions {
|
|
versionJSON, err := json.Marshal(version)
|
|
require.NoError(t, err)
|
|
require.Equal(t, versionJSON, []byte(`"`+str+`"`))
|
|
|
|
err = tlsVersion.UnmarshalJSON([]byte(`"` + str + `"`))
|
|
require.NoError(t, err)
|
|
require.Equal(t, tlsVersion, version)
|
|
}
|
|
}
|