add configuration support for self overrides

This commit is contained in:
Jordan Whited
2021-01-01 17:15:04 -08:00
committed by Jordan Whited
parent 6f78170fbe
commit 77622af207
3 changed files with 132 additions and 31 deletions

View File

@@ -8,24 +8,78 @@ import (
func TestSetup(t *testing.T) {
testCases := []struct {
name string
input string
expectErr bool
name string
input string
expectErr bool
expectSelfAllowedIPs []string
expectSelfEndpoint []string
}{
{
"valid input",
"wgsd example.com. wg0",
false,
nil,
nil,
},
{
"missing token",
"wgsd example.com.",
true,
nil,
nil,
},
{
"too many tokens",
"wgsd example.com. wg0 extra",
true,
nil,
nil,
},
{
"valid self-allowed-ips",
`wgsd example.com. wg0 {
self-allowed-ips 10.0.0.1/32 10.0.0.2/32
}`,
false,
nil,
nil,
},
{
"invalid self-allowed-ips",
`wgsd example.com. wg0 {
self-allowed-ips 10.0.01/32 10.0.0.2/32
}`,
true,
nil,
nil,
},
{
"valid self-endpoint",
`wgsd example.com. wg0 {
self-endpoint 127.0.0.1:51820
}`,
false,
nil,
nil,
},
{
"invalid self-endpoint",
`wgsd example.com. wg0 {
self-endpoint hostname:51820
}`,
true,
nil,
nil,
},
{
"all options",
`wgsd example.com. wg0 {
self-allowed-ips 10.0.0.1/32 10.0.0.2/32
self-endpoint 127.0.0.1:51820
}`,
false,
nil,
nil,
},
}
@@ -36,6 +90,9 @@ func TestSetup(t *testing.T) {
if (err != nil) != tc.expectErr {
t.Fatalf("expectErr: %v, got err=%v", tc.expectErr, err)
}
if tc.expectErr {
return
}
})
}
}