2020-02-18 22:15:09 +00:00
|
|
|
package authorization
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2020-05-04 19:39:25 +00:00
|
|
|
func TestShouldMatchACLWithSingleDomain(t *testing.T) {
|
|
|
|
assert.True(t, isDomainMatching("example.com", []string{"example.com"}))
|
2020-02-18 22:15:09 +00:00
|
|
|
|
2020-05-04 19:39:25 +00:00
|
|
|
assert.True(t, isDomainMatching("abc.example.com", []string{"*.example.com"}))
|
|
|
|
assert.True(t, isDomainMatching("abc.def.example.com", []string{"*.example.com"}))
|
|
|
|
}
|
2020-02-18 22:15:09 +00:00
|
|
|
|
2020-05-04 19:39:25 +00:00
|
|
|
func TestShouldNotMatchACLWithSingleDomain(t *testing.T) {
|
|
|
|
assert.False(t, isDomainMatching("example.com", []string{"*.example.com"}))
|
2020-02-18 22:15:09 +00:00
|
|
|
// Character * must be followed by . to be valid.
|
2020-05-04 19:39:25 +00:00
|
|
|
assert.False(t, isDomainMatching("example.com", []string{"*example.com"}))
|
|
|
|
|
|
|
|
assert.False(t, isDomainMatching("example.com", []string{"*.exampl.com"}))
|
2020-02-18 22:15:09 +00:00
|
|
|
|
2020-05-04 19:39:25 +00:00
|
|
|
assert.False(t, isDomainMatching("example.com", []string{"*.other.net"}))
|
|
|
|
assert.False(t, isDomainMatching("example.com", []string{"*other.net"}))
|
|
|
|
assert.False(t, isDomainMatching("example.com", []string{"other.net"}))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldMatchACLWithMultipleDomains(t *testing.T) {
|
|
|
|
assert.True(t, isDomainMatching("example.com", []string{"*.example.com", "example.com"}))
|
|
|
|
assert.True(t, isDomainMatching("apple.example.com", []string{"*.example.com", "example.com"}))
|
|
|
|
}
|
2020-02-18 22:15:09 +00:00
|
|
|
|
2020-05-04 19:39:25 +00:00
|
|
|
func TestShouldNotMatchACLWithMultipleDomains(t *testing.T) {
|
|
|
|
assert.False(t, isDomainMatching("example.com", []string{"*.example.com", "*example.com"}))
|
|
|
|
assert.False(t, isDomainMatching("apple.example.com", []string{"*example.com", "example.com"}))
|
2020-02-18 22:15:09 +00:00
|
|
|
}
|