From f3d76cf35dfe0c6fbf135faaedbbce6d9fb58ee4 Mon Sep 17 00:00:00 2001 From: Britt Dodd Date: Mon, 10 Jan 2022 11:18:04 -0500 Subject: [PATCH] moved length test to util, tests fine --- handler/routes.go | 2 +- util/util.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/handler/routes.go b/handler/routes.go index 57fe67e..f418a61 100644 --- a/handler/routes.go +++ b/handler/routes.go @@ -280,7 +280,7 @@ func UpdateClient(db store.IStore) echo.HandlerFunc { return c.JSON(http.StatusBadRequest, jsonHTTPResponse{false, "Allowed IPs must be in CIDR format"}) } - if len(_client.ExtraAllowedIPs) > 0 && util.ValidateAllowedIPs(_client.ExtraAllowedIPs) == false { + if util.ValidateAllowedIPs(_client.ExtraAllowedIPs) == false { log.Warnf("Invalid Allowed IPs input from user: %v", _client.ExtraAllowedIPs) return c.JSON(http.StatusBadRequest, jsonHTTPResponse{false, "Extra Allowed IPs must be in CIDR format"}) } diff --git a/util/util.go b/util/util.go index 2269537..aad0c7b 100644 --- a/util/util.go +++ b/util/util.go @@ -78,8 +78,10 @@ func ValidateCIDR(cidr string) bool { // ValidateCIDRList to validate a list of network CIDR func ValidateCIDRList(cidrs []string) bool { for _, cidr := range cidrs { - if ValidateCIDR(cidr) == false { - return false + if len(cidr) > 0 { + if ValidateCIDR(cidr) == false { + return false + } } } return true