mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-06 19:40:42 -05:00
Add 'proxy/' from commit '201b9a652685cdfb72ba81c7e7b00ba1c60a0e35'
git-subtree-dir: proxy git-subtree-mainline:571d96e856git-subtree-split:201b9a6526
This commit is contained in:
@@ -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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user