mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-09-17 01:45:27 +02:00
cmd/cli: make widcard rules match case-insensitively
Domain name comparisons are done in case-insensitive manner. See: https://datatracker.ietf.org/doc/html/rfc1034#section-3.1
This commit is contained in:
@@ -630,14 +630,15 @@ func canonicalName(fqdn string) string {
|
|||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
// wildcardMatches reports whether string str matches the wildcard pattern.
|
// wildcardMatches reports whether string str matches the wildcard pattern in case-insensitive manner.
|
||||||
func wildcardMatches(wildcard, str string) bool {
|
func wildcardMatches(wildcard, str string) bool {
|
||||||
// Wildcard match.
|
// Wildcard match.
|
||||||
wildCardParts := strings.Split(wildcard, "*")
|
wildCardParts := strings.Split(strings.ToLower(wildcard), "*")
|
||||||
if len(wildCardParts) != 2 {
|
if len(wildCardParts) != 2 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
str = strings.ToLower(str)
|
||||||
switch {
|
switch {
|
||||||
case len(wildCardParts[0]) > 0 && len(wildCardParts[1]) > 0:
|
case len(wildCardParts[0]) > 0 && len(wildCardParts[1]) > 0:
|
||||||
// Domain must match both prefix and suffix.
|
// Domain must match both prefix and suffix.
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ func Test_wildcardMatches(t *testing.T) {
|
|||||||
{"domain - suffix not match other", "suffix.*", "suffix1.windscribe.com", false},
|
{"domain - suffix not match other", "suffix.*", "suffix1.windscribe.com", false},
|
||||||
{"domain - both", "suffix.*.windscribe.com", "suffix.anything.windscribe.com", true},
|
{"domain - both", "suffix.*.windscribe.com", "suffix.anything.windscribe.com", true},
|
||||||
{"domain - both not match", "suffix.*.windscribe.com", "suffix1.suffix.windscribe.com", false},
|
{"domain - both not match", "suffix.*.windscribe.com", "suffix1.suffix.windscribe.com", false},
|
||||||
|
{"domain - case-insensitive", "*.WINDSCRIBE.com", "anything.windscribe.com", true},
|
||||||
{"mac - prefix", "*:98:05:b4:2b", "d4:67:98:05:b4:2b", true},
|
{"mac - prefix", "*:98:05:b4:2b", "d4:67:98:05:b4:2b", true},
|
||||||
{"mac - prefix not match other s", "*:98:05:b4:2b", "0d:ba:54:09:94:2c", false},
|
{"mac - prefix not match other s", "*:98:05:b4:2b", "0d:ba:54:09:94:2c", false},
|
||||||
{"mac - prefix not match s in name", "*:98:05:b4:2b", "e4:67:97:05:b4:2b", false},
|
{"mac - prefix not match s in name", "*:98:05:b4:2b", "e4:67:97:05:b4:2b", false},
|
||||||
|
|||||||
Reference in New Issue
Block a user