Add 'proxy/' from commit '201b9a652685cdfb72ba81c7e7b00ba1c60a0e35'

git-subtree-dir: proxy
git-subtree-mainline: 571d96e856
git-subtree-split: 201b9a6526
This commit is contained in:
A.Unger
2020-09-18 12:47:26 +02:00
107 changed files with 8151 additions and 0 deletions
+112
View File
@@ -0,0 +1,112 @@
package proxy
import (
"net/url"
"testing"
"github.com/owncloud/ocis-proxy/pkg/config"
)
func TestPrefixRouteMatcher(t *testing.T) {
cfg := config.New()
p := NewMultiHostReverseProxy(Config(cfg))
endpoint := "/foobar"
u, _ := url.Parse("/foobar/baz/some/url")
matched := p.prefixRouteMatcher(endpoint, *u)
if !matched {
t.Errorf("Endpoint %s and URL %s should match", endpoint, u.String())
}
}
func TestQueryRouteMatcher(t *testing.T) {
cfg := config.New()
p := NewMultiHostReverseProxy(Config(cfg))
endpoint := "/foobar?parameter=true"
u, _ := url.Parse("/foobar/baz/some/url?parameter=true")
matched := p.queryRouteMatcher(endpoint, *u)
if !matched {
t.Errorf("Endpoint %s and URL %s should match", endpoint, u.String())
}
}
func TestQueryRouteMatcherWithoutParameters(t *testing.T) {
cfg := config.New()
p := NewMultiHostReverseProxy(Config(cfg))
endpoint := "/foobar"
u, _ := url.Parse("/foobar/baz/some/url?parameter=true")
matched := p.queryRouteMatcher(endpoint, *u)
if matched {
t.Errorf("Endpoint %s and URL %s should not match", endpoint, u.String())
}
}
func TestQueryRouteMatcherWithDifferingParameters(t *testing.T) {
cfg := config.New()
p := NewMultiHostReverseProxy(Config(cfg))
endpoint := "/foobar?parameter=false"
u, _ := url.Parse("/foobar/baz/some/url?parameter=true")
matched := p.queryRouteMatcher(endpoint, *u)
if matched {
t.Errorf("Endpoint %s and URL %s should not match", endpoint, u.String())
}
}
func TestQueryRouteMatcherWithMultipleDifferingParameters(t *testing.T) {
cfg := config.New()
p := NewMultiHostReverseProxy(Config(cfg))
endpoint := "/foobar?parameter=false&other=true"
u, _ := url.Parse("/foobar/baz/some/url?parameter=true")
matched := p.queryRouteMatcher(endpoint, *u)
if matched {
t.Errorf("Endpoint %s and URL %s should not match", endpoint, u.String())
}
}
func TestQueryRouteMatcherWithMultipleParameters(t *testing.T) {
cfg := config.New()
p := NewMultiHostReverseProxy(Config(cfg))
endpoint := "/foobar?parameter=false&other=true"
u, _ := url.Parse("/foobar/baz/some/url?parameter=false&other=true")
matched := p.queryRouteMatcher(endpoint, *u)
if !matched {
t.Errorf("Endpoint %s and URL %s should match", endpoint, u.String())
}
}
func TestRegexRouteMatcher(t *testing.T) {
cfg := config.New()
p := NewMultiHostReverseProxy(Config(cfg))
endpoint := ".*some\\/url.*parameter=true"
u, _ := url.Parse("/foobar/baz/some/url?parameter=true")
matched := p.regexRouteMatcher(endpoint, *u)
if !matched {
t.Errorf("Endpoint %s and URL %s should match", endpoint, u.String())
}
}
func TestRegexRouteMatcherWithInvalidPattern(t *testing.T) {
cfg := config.New()
p := NewMultiHostReverseProxy(Config(cfg))
endpoint := "([\\])\\w+"
u, _ := url.Parse("/foobar/baz/some/url?parameter=true")
matched := p.regexRouteMatcher(endpoint, *u)
if matched {
t.Errorf("Endpoint %s and URL %s should not match", endpoint, u.String())
}
}