|
| 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 | +//go:build requirefips |
| 19 | + |
| 20 | +package tlscommon |
| 21 | + |
| 22 | +import ( |
| 23 | + "crypto/tls" |
| 24 | + "testing" |
| 25 | + |
| 26 | + "github.com/stretchr/testify/require" |
| 27 | +) |
| 28 | + |
| 29 | +func TestFIPSTLSVersion(t *testing.T) { |
| 30 | + // These tests are a bit verbose, but given the sensitivity to changes here, it's not a bad idea. |
| 31 | + tests := []struct { |
| 32 | + name string |
| 33 | + v uint16 |
| 34 | + expectErr string |
| 35 | + }{ |
| 36 | + { |
| 37 | + name: "TLSv1.0", |
| 38 | + v: tls.VersionTLS10, |
| 39 | + expectErr: "unsupported tls version: TLSv1.0", |
| 40 | + }, |
| 41 | + { |
| 42 | + name: "TLSv1.1", |
| 43 | + v: tls.VersionTLS11, |
| 44 | + expectErr: "unsupported tls version: TLSv1.1", |
| 45 | + }, |
| 46 | + { |
| 47 | + name: "TLSv1.2", |
| 48 | + v: tls.VersionTLS12, |
| 49 | + }, |
| 50 | + { |
| 51 | + name: "TLSv1.3", |
| 52 | + v: tls.VersionTLS13, |
| 53 | + }, |
| 54 | + } |
| 55 | + for _, tt := range tests { |
| 56 | + t.Run(tt.name, func(t *testing.T) { |
| 57 | + tv := TLSVersion(tt.v) |
| 58 | + if tt.expectErr != "" { |
| 59 | + require.EqualError(t, tv.Validate(), tt.expectErr) |
| 60 | + } else { |
| 61 | + require.NoError(t, tv.Validate()) |
| 62 | + } |
| 63 | + }) |
| 64 | + } |
| 65 | +} |
0 commit comments