From f8a168b8e7de5936a3b8fa990a5aa07f1d6f0cfd Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Fri, 26 Aug 2022 10:10:05 +0300 Subject: [PATCH] Add a few more unit test cases --- utils/user_test.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/utils/user_test.go b/utils/user_test.go index e764d6d..93d4329 100644 --- a/utils/user_test.go +++ b/utils/user_test.go @@ -151,17 +151,47 @@ func TestMatch(t *testing.T) { expectedResult: false, }, { - name: "mxid localpart wildcard match is allowed", + name: "mxid localpart only wildcard match is allowed", checkedValue: "@someone:example.com", allowedUsers: []string{"@*:example.com"}, expectedResult: true, }, + { + name: "mxid localpart with wildcard match is allowed", + checkedValue: "@bot.abc:example.com", + allowedUsers: []string{"@bot.*:example.com"}, + expectedResult: true, + }, + { + name: "mxid localpart with wildcard match is not allowed when it does not match", + checkedValue: "@bot.abc:example.com", + allowedUsers: []string{"@employee.*:example.com"}, + expectedResult: false, + }, { name: "mxid localpart wildcard for another domain is not allowed", checkedValue: "@someone:example.com", allowedUsers: []string{"@*:another.com"}, expectedResult: false, }, + { + name: "mxid domainpart with only wildcard match is allowed", + checkedValue: "@someone:example.com", + allowedUsers: []string{"@someone:*"}, + expectedResult: true, + }, + { + name: "mxid domainpart with wildcard match is allowed", + checkedValue: "@someone:example.organization.com", + allowedUsers: []string{"@someone:*.organization.com"}, + expectedResult: true, + }, + { + name: "mxid domainpart with wildcard match is not allowed when it does not match", + checkedValue: "@someone:example.another.com", + allowedUsers: []string{"@someone:*.organization.com"}, + expectedResult: false, + }, } for _, testData := range tests {