proxy tests

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer
2025-01-14 17:15:39 +01:00
parent bcfe44bfb6
commit 04099bc9a7
3 changed files with 22 additions and 22 deletions

View File

@@ -99,7 +99,7 @@ func LoadSelector(cfg *config.PolicySelector) (Selector, error) {
// Configuration:
//
// "policy_selector": {
// "static": {"policy" : "ocis"}
// "static": {"policy" : "opencloud"}
// },
func NewStaticSelector(cfg *config.StaticSelectorConf) Selector {
return func(r *http.Request) (s string, err error) {
@@ -112,7 +112,7 @@ func NewStaticSelector(cfg *config.StaticSelectorConf) Selector {
//
// "policy_selector": {
// "migration": {
// "default_policy" : "ocis",
// "default_policy" : "opencloud",
// "unauthenticated_policy": "oc10"
// }
// },
@@ -160,11 +160,11 @@ func NewClaimsSelector(cfg *config.ClaimsSelectorConf) Selector {
// "policy_selector": {
// "regex": {
// "matches_policies": [
// {"priority": 10, "property": "mail", "match": "marie@example.org", "policy": "ocis"},
// {"priority": 10, "property": "mail", "match": "marie@example.org", "policy": "opencloud"},
// {"priority": 20, "property": "mail", "match": "[^@]+@example.org", "policy": "oc10"},
// {"priority": 30, "property": "username", "match": "(einstein|feynman)", "policy": "ocis"},
// {"priority": 30, "property": "username", "match": "(einstein|feynman)", "policy": "opencloud"},
// {"priority": 40, "property": "username", "match": ".+", "policy": "oc10"},
// {"priority": 50, "property": "id", "match": "4c510ada-c86b-4815-8820-42cdf82c3d51", "policy": "ocis"},
// {"priority": 50, "property": "id", "match": "4c510ada-c86b-4815-8820-42cdf82c3d51", "policy": "opencloud"},
// {"priority": 60, "property": "id", "match": "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c", "policy": "oc10"}
// ],
// "unauthenticated_policy": "oc10"

View File

@@ -38,9 +38,9 @@ func TestLoadSelector(t *testing.T) {
}
func TestStaticSelector(t *testing.T) {
sel := NewStaticSelector(&config.StaticSelectorConf{Policy: "ocis"})
sel := NewStaticSelector(&config.StaticSelectorConf{Policy: "opencloud"})
req := httptest.NewRequest("GET", "https://example.org/foo", nil)
want := "ocis"
want := "opencloud"
got, err := sel(req)
if got != want {
t.Errorf("Expected policy %v got %v", want, got)
@@ -105,11 +105,11 @@ func TestRegexSelector(t *testing.T) {
sel := NewRegexSelector(&config.RegexSelectorConf{
DefaultPolicy: "default",
MatchesPolicies: []config.RegexRuleConf{
{Priority: 10, Property: "mail", Match: "marie@example.org", Policy: "ocis"},
{Priority: 10, Property: "mail", Match: "marie@example.org", Policy: "opencloud"},
{Priority: 20, Property: "mail", Match: "[^@]+@example.org", Policy: "oc10"},
{Priority: 30, Property: "username", Match: "(einstein|feynman)", Policy: "ocis"},
{Priority: 30, Property: "username", Match: "(einstein|feynman)", Policy: "opencloud"},
{Priority: 40, Property: "username", Match: ".+", Policy: "oc10"},
{Priority: 50, Property: "id", Match: "4c510ada-c86b-4815-8820-42cdf82c3d51", Policy: "ocis"},
{Priority: 50, Property: "id", Match: "4c510ada-c86b-4815-8820-42cdf82c3d51", Policy: "opencloud"},
{Priority: 60, Property: "id", Match: "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c", Policy: "oc10"},
},
UnauthenticatedPolicy: "unauthenticated",
@@ -118,13 +118,13 @@ func TestRegexSelector(t *testing.T) {
var tests = []testCase{
{"unauthenticated", context.Background(), nil, "unauthenticated"},
{"default", revactx.ContextSetUser(context.Background(), &userv1beta1.User{}), nil, "default"},
{"mail-ocis", revactx.ContextSetUser(context.Background(), &userv1beta1.User{Mail: "marie@example.org"}), nil, "ocis"},
{"mail-ocis", revactx.ContextSetUser(context.Background(), &userv1beta1.User{Mail: "marie@example.org"}), nil, "opencloud"},
{"mail-oc10", revactx.ContextSetUser(context.Background(), &userv1beta1.User{Mail: "einstein@example.org"}), nil, "oc10"},
{"username-einstein", revactx.ContextSetUser(context.Background(), &userv1beta1.User{Username: "einstein"}), nil, "ocis"},
{"username-feynman", revactx.ContextSetUser(context.Background(), &userv1beta1.User{Username: "feynman"}), nil, "ocis"},
{"username-einstein", revactx.ContextSetUser(context.Background(), &userv1beta1.User{Username: "einstein"}), nil, "opencloud"},
{"username-feynman", revactx.ContextSetUser(context.Background(), &userv1beta1.User{Username: "feynman"}), nil, "opencloud"},
{"username-marie", revactx.ContextSetUser(context.Background(), &userv1beta1.User{Username: "marie"}), nil, "oc10"},
{"id-nil", revactx.ContextSetUser(context.Background(), &userv1beta1.User{Id: &userv1beta1.UserId{}}), nil, "default"},
{"id-1", revactx.ContextSetUser(context.Background(), &userv1beta1.User{Id: &userv1beta1.UserId{OpaqueId: "4c510ada-c86b-4815-8820-42cdf82c3d51"}}), nil, "ocis"},
{"id-1", revactx.ContextSetUser(context.Background(), &userv1beta1.User{Id: &userv1beta1.UserId{OpaqueId: "4c510ada-c86b-4815-8820-42cdf82c3d51"}}), nil, "opencloud"},
{"id-2", revactx.ContextSetUser(context.Background(), &userv1beta1.User{Id: &userv1beta1.UserId{OpaqueId: "f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c"}}), nil, "oc10"},
}

View File

@@ -19,7 +19,7 @@ import (
func TestProxyIntegration(t *testing.T) {
var tests = []testCase{
// Simple prefix route
test("simple_prefix", withPolicy("ocis", withRoutes{{
test("simple_prefix", withPolicy("opencloud", withRoutes{{
Type: config.PrefixRoute,
Endpoint: "/api",
Backend: "http://api.example.com"},
@@ -27,7 +27,7 @@ func TestProxyIntegration(t *testing.T) {
expectProxyTo("http://api.example.com/api"),
// Complex prefix route, different method
test("complex_prefix_post", withPolicy("ocis", withRoutes{{
test("complex_prefix_post", withPolicy("opencloud", withRoutes{{
Type: config.PrefixRoute,
Endpoint: "/api",
Backend: "http://api.example.com/service1/"},
@@ -35,7 +35,7 @@ func TestProxyIntegration(t *testing.T) {
expectProxyTo("http://api.example.com/service1/api"),
// Query route
test("query_route", withPolicy("ocis", withRoutes{{
test("query_route", withPolicy("opencloud", withRoutes{{
Type: config.QueryRoute,
Endpoint: "/api?format=json",
Backend: "http://backend/"},
@@ -43,7 +43,7 @@ func TestProxyIntegration(t *testing.T) {
expectProxyTo("http://backend/api?format=json"),
// Regex route
test("regex_route", withPolicy("ocis", withRoutes{{
test("regex_route", withPolicy("opencloud", withRoutes{{
Type: config.RegexRoute,
Endpoint: `\/user\/(\d+)`,
Backend: "http://backend/"},
@@ -51,7 +51,7 @@ func TestProxyIntegration(t *testing.T) {
expectProxyTo("http://backend/user/1234"),
// Multiple prefix routes 1
test("multiple_prefix", withPolicy("ocis", withRoutes{
test("multiple_prefix", withPolicy("opencloud", withRoutes{
{
Type: config.PrefixRoute,
Endpoint: "/api",
@@ -66,7 +66,7 @@ func TestProxyIntegration(t *testing.T) {
expectProxyTo("http://payment.example.com/payment"),
// Multiple prefix routes 2
test("multiple_prefix", withPolicy("ocis", withRoutes{
test("multiple_prefix", withPolicy("opencloud", withRoutes{
{
Type: config.PrefixRoute,
Endpoint: "/api",
@@ -81,7 +81,7 @@ func TestProxyIntegration(t *testing.T) {
expectProxyTo("http://api.example.com/api"),
// Mixed route types
test("mixed_types", withPolicy("ocis", withRoutes{
test("mixed_types", withPolicy("opencloud", withRoutes{
{
Type: config.PrefixRoute,
Endpoint: "/api",
@@ -97,7 +97,7 @@ func TestProxyIntegration(t *testing.T) {
expectProxyTo("http://api.example.com/api"),
// Mixed route types
test("mixed_types", withPolicy("ocis", withRoutes{
test("mixed_types", withPolicy("opencloud", withRoutes{
{
Type: config.PrefixRoute,
Endpoint: "/api",