|
| 1 | +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 2 | +// or more contributor license agreements. Licensed under the Elastic License 2.0; |
| 3 | +// you may not use this file except in compliance with the Elastic License 2.0. |
| 4 | + |
| 5 | +//go:build requirefips |
| 6 | + |
| 7 | +package remote |
| 8 | + |
| 9 | +import ( |
| 10 | + "fmt" |
| 11 | + "testing" |
| 12 | + |
| 13 | + "github.com/stretchr/testify/require" |
| 14 | + |
| 15 | + "github.com/elastic/elastic-agent-libs/transport/httpcommon" |
| 16 | + "github.com/elastic/elastic-agent-libs/transport/tlscommon" |
| 17 | + "github.com/elastic/elastic-agent/pkg/core/logger/loggertest" |
| 18 | +) |
| 19 | + |
| 20 | +func TestClientWithUnsupportedTLSVersions(t *testing.T) { |
| 21 | + testLogger, _ := loggertest.New("TestClientWithUnsupportedTLSVersions") |
| 22 | + const unsupportedErrorMsg = "invalid configuration: unsupported tls version: %s" |
| 23 | + |
| 24 | + cases := map[string]struct { |
| 25 | + versions []tlscommon.TLSVersion |
| 26 | + expectedErrMsg string |
| 27 | + }{ |
| 28 | + "1.0": { |
| 29 | + versions: []tlscommon.TLSVersion{tlscommon.TLSVersion10}, |
| 30 | + expectedErrMsg: fmt.Sprintf(unsupportedErrorMsg, tlscommon.TLSVersion10), |
| 31 | + }, |
| 32 | + "1.1": { |
| 33 | + versions: []tlscommon.TLSVersion{tlscommon.TLSVersion11}, |
| 34 | + expectedErrMsg: fmt.Sprintf(unsupportedErrorMsg, tlscommon.TLSVersion11), |
| 35 | + }, |
| 36 | + "1.2": { |
| 37 | + versions: []tlscommon.TLSVersion{tlscommon.TLSVersion12}, |
| 38 | + expectedErrMsg: "", |
| 39 | + }, |
| 40 | + "1.3": { |
| 41 | + versions: []tlscommon.TLSVersion{tlscommon.TLSVersion13}, |
| 42 | + expectedErrMsg: "", |
| 43 | + }, |
| 44 | + "1.1,1.2": { |
| 45 | + versions: []tlscommon.TLSVersion{tlscommon.TLSVersion11, tlscommon.TLSVersion12}, |
| 46 | + expectedErrMsg: fmt.Sprintf(unsupportedErrorMsg, tlscommon.TLSVersion11), |
| 47 | + }, |
| 48 | + } |
| 49 | + |
| 50 | + for name, test := range cases { |
| 51 | + t.Run(name, func(t *testing.T) { |
| 52 | + tlsEnabled := true |
| 53 | + config := Config{ |
| 54 | + Transport: httpcommon.HTTPTransportSettings{ |
| 55 | + TLS: &tlscommon.Config{ |
| 56 | + Enabled: &tlsEnabled, |
| 57 | + Versions: test.versions, |
| 58 | + }, |
| 59 | + }, |
| 60 | + } |
| 61 | + |
| 62 | + client, err := NewWithConfig(testLogger, config, nil) |
| 63 | + if test.expectedErrMsg == "" { |
| 64 | + require.NotNil(t, client) |
| 65 | + require.NoError(t, err) |
| 66 | + } else { |
| 67 | + require.Nil(t, client) |
| 68 | + require.Equal(t, test.expectedErrMsg, err.Error()) |
| 69 | + } |
| 70 | + }) |
| 71 | + } |
| 72 | +} |
0 commit comments