Skip to content

Commit b5be848

Browse files
authored
Remove empty string as default value for VerificationMode (#59)
* remove empty option * add test * go lint * go lint
1 parent 9e0189f commit b5be848

File tree

4 files changed

+80
-2
lines changed

4 files changed

+80
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
build/
1+
build/
2+
.idea

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1616

1717
### Fixed
1818

19+
## [0.2.5]
20+
21+
### Fixed
22+
23+
- Remove VerificationMode option to empty string. Default will be `full` #49
24+
1925
## [0.2.4]
2026

2127
### Fixed

transport/tlscommon/types.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ const (
133133
)
134134

135135
var tlsVerificationModes = map[string]TLSVerificationMode{
136-
"": VerifyFull,
137136
"full": VerifyFull,
138137
"strict": VerifyStrict,
139138
"none": VerifyNone,
@@ -166,6 +165,10 @@ func (m *TLSVerificationMode) Unpack(in interface{}) error {
166165
if !ok {
167166
return fmt.Errorf("verification mode must be an identifier")
168167
}
168+
if s == "" {
169+
*m = VerifyFull
170+
return nil
171+
}
169172

170173
mode, found := tlsVerificationModes[s]
171174
if !found {

transport/tlscommon/types_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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

Comments
 (0)