Make repo whitelist case insensitive.

This is okay to do because it's a better user experience and because
GitLab and GitHub project names are case insensitive as well.
This commit is contained in:
Luke Kysow
2018-03-30 12:59:22 -07:00
parent f016d642ae
commit 3f5ad53af6
2 changed files with 18 additions and 0 deletions

View File

@@ -42,6 +42,10 @@ func (r *RepoWhitelist) IsWhitelisted(repoFullName string, vcsHostname string) b
}
func (r *RepoWhitelist) matchesRule(rule string, candidate string) bool {
// Case insensitive compare.
rule = strings.ToLower(rule)
candidate = strings.ToLower(candidate)
wildcardIdx := strings.Index(rule, Wildcard)
if wildcardIdx == -1 {
// No wildcard so can do a straight up match.

View File

@@ -133,6 +133,20 @@ func TestIsWhitelisted(t *testing.T) {
"github.com",
false,
},
{
"should be case insensitive",
"github.com/owner/repo",
"OwNeR/rEpO",
"github.com",
true,
},
{
"should be case insensitive for wildcards",
"github.com/owner/*",
"OwNeR/rEpO",
"github.com",
true,
},
}
for _, c := range cases {