2020-02-19 05:15:09 +07:00
|
|
|
package authorization
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2020-05-05 02:39:25 +07:00
|
|
|
func TestShouldMatchACLWithSingleDomain(t *testing.T) {
|
|
|
|
assert.True(t, isDomainMatching("example.com", []string{"example.com"}))
|
2020-02-19 05:15:09 +07:00
|
|
|
|
2020-05-05 02:39:25 +07:00
|
|
|
assert.True(t, isDomainMatching("abc.example.com", []string{"*.example.com"}))
|
|
|
|
assert.True(t, isDomainMatching("abc.def.example.com", []string{"*.example.com"}))
|
|
|
|
}
|
2020-02-19 05:15:09 +07:00
|
|
|
|
2020-05-05 02:39:25 +07:00
|
|
|
func TestShouldNotMatchACLWithSingleDomain(t *testing.T) {
|
|
|
|
assert.False(t, isDomainMatching("example.com", []string{"*.example.com"}))
|
2020-02-19 05:15:09 +07:00
|
|
|
// Character * must be followed by . to be valid.
|
2020-05-05 02:39:25 +07:00
|
|
|
assert.False(t, isDomainMatching("example.com", []string{"*example.com"}))
|
|
|
|
|
|
|
|
assert.False(t, isDomainMatching("example.com", []string{"*.exampl.com"}))
|
2020-02-19 05:15:09 +07:00
|
|
|
|
2020-05-05 02:39:25 +07: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-19 05:15:09 +07:00
|
|
|
|
2020-05-05 02:39:25 +07: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-19 05:15:09 +07:00
|
|
|
}
|