Maintenance: generate Openvpn conf for 2.4 or 2.5

This commit is contained in:
Quentin McGaw
2021-05-23 17:40:14 +00:00
parent a8c574219d
commit da65f3b016
18 changed files with 91 additions and 28 deletions

View File

@@ -0,0 +1,15 @@
package utils
import "strings"
func CipherLines(cipher, version string) (lines []string) {
switch {
case strings.HasPrefix(version, "2.4"):
return []string{"cipher " + cipher}
default: // 2.5 and above
return []string{
"data-ciphers-fallback " + cipher,
"data-ciphers " + cipher,
}
}
}

View File

@@ -0,0 +1,45 @@
package utils
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_CipherLines(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
version string
lines []string
}{
"empty version": {
lines: []string{
"data-ciphers-fallback AES",
"data-ciphers AES",
},
},
"2.4.5": {
version: "2.4.5",
lines: []string{"cipher AES"},
},
"2.5.3": {
version: "2.5.3",
lines: []string{
"data-ciphers-fallback AES",
"data-ciphers AES",
},
},
}
for name, testCase := range testCases {
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()
const cipher = "AES"
lines := CipherLines(cipher, testCase.version)
assert.Equal(t, testCase.lines, lines)
})
}
}