mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-29 18:36:30 +02:00
* config: add support for wildcards * update policy matching, header generation * remove deprecated field * fix test
38 lines
1 KiB
Go
38 lines
1 KiB
Go
package config
|
|
|
|
import (
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/pomerium/pomerium/internal/urlutil"
|
|
)
|
|
|
|
func TestFromURLMatchesRequestURL(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
for _, tc := range []struct {
|
|
pattern string
|
|
input string
|
|
matches bool
|
|
}{
|
|
{"https://from.example.com", "https://from.example.com/some/path", true},
|
|
{"https://from.example.com", "https://to.example.com/some/path", false},
|
|
{"https://*.example.com", "https://from.example.com/some/path", true},
|
|
{"https://*.example.com", "https://example.com/some/path", false},
|
|
} {
|
|
fromURL := urlutil.MustParseAndValidateURL(tc.pattern)
|
|
requestURL := urlutil.MustParseAndValidateURL(tc.input)
|
|
assert.Equal(t, tc.matches, FromURLMatchesRequestURL(&fromURL, &requestURL),
|
|
"from-url: %s\nrequest-url: %s", tc.pattern, tc.input)
|
|
}
|
|
}
|
|
|
|
func TestWildcardToRegex(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
re, err := regexp.Compile(WildcardToRegex("*.internal.*.example.com"))
|
|
assert.NoError(t, err)
|
|
assert.True(t, re.MatchString("a.internal.b.example.com"))
|
|
}
|