From bb754f9aa8ab81427c459c2d546629c0cbd3e48e Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Fri, 26 Aug 2022 10:19:33 +0300 Subject: [PATCH] Simplify MatchUserWithAllowedRegexes This used to return an error back when it was dealing with wildcards (which may or may not have compiled to a valid regex). But it now deals with pre-compiled regexes and has no chance of failing, so we need no `error` returns. --- utils/user.go | 8 ++++---- utils/user_test.go | 5 +---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/utils/user.go b/utils/user.go index 5f7f4e9..2b68ebe 100644 --- a/utils/user.go +++ b/utils/user.go @@ -23,19 +23,19 @@ func WildcardUserPatternsToRegexPatterns(wildCardPatterns []string) (*[]*regexp. // MatchUserWithAllowedRegexes tells if the given user id is allowed to use the bot, according to the given whitelist // An empty whitelist means "everyone is allowed" -func MatchUserWithAllowedRegexes(userID string, allowed []*regexp.Regexp) (bool, error) { +func MatchUserWithAllowedRegexes(userID string, allowed []*regexp.Regexp) bool { // No whitelisted users means everyone is whitelisted if len(allowed) == 0 { - return true, nil + return true } for _, regex := range allowed { if regex.MatchString(userID) { - return true, nil + return true } } - return false, nil + return false } // parseAllowedUserRule parses a user whitelisting rule and returns a regular expression which corresponds to it diff --git a/utils/user_test.go b/utils/user_test.go index 93d4329..ed6de85 100644 --- a/utils/user_test.go +++ b/utils/user_test.go @@ -202,10 +202,7 @@ func TestMatch(t *testing.T) { t.Error(err) } - actualResult, err := MatchUserWithAllowedRegexes(testData.checkedValue, *allowedUserRegexes) - if err != nil { - t.Error(err) - } + actualResult := MatchUserWithAllowedRegexes(testData.checkedValue, *allowedUserRegexes) if actualResult == testData.expectedResult { return