Maintenance: generate Openvpn conf for 2.4 or 2.5
This commit is contained in:
15
internal/provider/utils/cipher.go
Normal file
15
internal/provider/utils/cipher.go
Normal 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
45
internal/provider/utils/cipher_test.go
Normal file
45
internal/provider/utils/cipher_test.go
Normal 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)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user