|
| 1 | +// Licensed to Elasticsearch B.V. under one or more contributor |
| 2 | +// license agreements. See the NOTICE file distributed with |
| 3 | +// this work for additional information regarding copyright |
| 4 | +// ownership. Elasticsearch B.V. licenses this file to you under |
| 5 | +// the Apache License, Version 2.0 (the "License"); you may |
| 6 | +// not use this file except in compliance with the License. |
| 7 | +// You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package tlscommon |
| 19 | + |
| 20 | +import ( |
| 21 | + "testing" |
| 22 | + |
| 23 | + "github.com/stretchr/testify/assert" |
| 24 | + |
| 25 | + "github.com/stretchr/testify/require" |
| 26 | +) |
| 27 | + |
| 28 | +func TestMarshallText(t *testing.T) { |
| 29 | + var verification TLSVerificationMode |
| 30 | + bytes, err := verification.MarshalText() |
| 31 | + require.NoError(t, err) |
| 32 | + require.NotNil(t, bytes) |
| 33 | + require.Equal(t, "full", string(bytes)) |
| 34 | + |
| 35 | + verification = VerifyNone |
| 36 | + bytes, err = verification.MarshalText() |
| 37 | + require.NoError(t, err) |
| 38 | + require.NotNil(t, bytes) |
| 39 | + require.Equal(t, "none", string(bytes)) |
| 40 | +} |
| 41 | + |
| 42 | +func TestLoadWithEmptyStringVerificationMode(t *testing.T) { |
| 43 | + cfg, err := load(` |
| 44 | + enabled: true |
| 45 | + certificate: mycert.pem |
| 46 | + key: mycert.key |
| 47 | + verification_mode: "" |
| 48 | + supported_protocols: [TLSv1.1, TLSv1.2] |
| 49 | + renegotiation: freely |
| 50 | + `) |
| 51 | + |
| 52 | + assert.NoError(t, err) |
| 53 | + assert.Equal(t, cfg.VerificationMode, VerifyFull) |
| 54 | +} |
| 55 | + |
| 56 | +func TestLoadWithEmptyVerificationMode(t *testing.T) { |
| 57 | + cfg, err := load(` |
| 58 | + enabled: true |
| 59 | + verification_mode: |
| 60 | + supported_protocols: [TLSv1.1, TLSv1.2] |
| 61 | + curve_types: |
| 62 | + - P-521 |
| 63 | + renegotiation: freely |
| 64 | + `) |
| 65 | + |
| 66 | + assert.NoError(t, err) |
| 67 | + assert.Equal(t, cfg.VerificationMode, VerifyFull) |
| 68 | +} |
0 commit comments