feat(config): add /32 if not present for Wireguard addresses
This commit is contained in:
@@ -101,6 +101,9 @@ func parseINIWireguardAddress(section *ini.Section) (
|
||||
addresses = make([]netip.Prefix, len(addressStrings))
|
||||
for i, addressString := range addressStrings {
|
||||
addressString = strings.TrimSpace(addressString)
|
||||
if !strings.ContainsRune(addressString, '/') {
|
||||
addressString += "/32"
|
||||
}
|
||||
addresses[i], err = netip.ParsePrefix(addressString)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parsing address: %w", err)
|
||||
|
||||
@@ -131,7 +131,7 @@ PreSharedKey = x
|
||||
iniData: `[Interface]
|
||||
Address = x
|
||||
`,
|
||||
errMessage: "parsing address: netip.ParsePrefix(\"x\"): no '/'",
|
||||
errMessage: "parsing address: netip.ParsePrefix(\"x/32\"): ParseAddr(\"x\"): unable to parse IP",
|
||||
},
|
||||
"success": {
|
||||
iniData: `
|
||||
@@ -238,7 +238,7 @@ func Test_parseINIWireguardAddress(t *testing.T) {
|
||||
"bad address": {
|
||||
fileContent: `[Interface]
|
||||
Address = x`,
|
||||
errMessage: "parsing address: netip.ParsePrefix(\"x\"): no '/'",
|
||||
errMessage: "parsing address: netip.ParsePrefix(\"x/32\"): ParseAddr(\"x\"): unable to parse IP",
|
||||
},
|
||||
"success": {
|
||||
fileContent: `[Interface]
|
||||
|
||||
Reference in New Issue
Block a user