From 90574268d9a6674a5f28cf20e6ddb0302026748a Mon Sep 17 00:00:00 2001 From: David Christofas Date: Tue, 30 Aug 2022 12:30:12 +0200 Subject: [PATCH] add missing unprotected flag and fix proxy test --- .../pkg/config/defaults/defaultconfig.go | 21 +++++++++++++------ .../proxy/pkg/proxy/proxy_integration_test.go | 10 ++++++--- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/services/proxy/pkg/config/defaults/defaultconfig.go b/services/proxy/pkg/config/defaults/defaultconfig.go index 4a89625d54..97efdb9841 100644 --- a/services/proxy/pkg/config/defaults/defaultconfig.go +++ b/services/proxy/pkg/config/defaults/defaultconfig.go @@ -99,6 +99,12 @@ func DefaultPolicies() []config.Policy { Endpoint: "/ocs/v[12].php/cloud/user/signing-key", // only `user/signing-key` is left in ocis-ocs Backend: "http://localhost:9110", }, + { + Type: config.RegexRoute, + Endpoint: "/ocs/v[12].php/config", + Backend: "http://localhost:9140", + Unprotected: true, + }, { Endpoint: "/ocs/", Backend: "http://localhost:9140", @@ -145,12 +151,14 @@ func DefaultPolicies() []config.Policy { Service: "com.owncloud.web.ocdav", }, { - Endpoint: "/status", - Service: "com.owncloud.web.ocdav", + Endpoint: "/status", + Service: "com.owncloud.web.ocdav", + Unprotected: true, }, { - Endpoint: "/status.php", - Service: "com.owncloud.web.ocdav", + Endpoint: "/status.php", + Service: "com.owncloud.web.ocdav", + Unprotected: true, }, { Endpoint: "/index.php/", @@ -161,8 +169,9 @@ func DefaultPolicies() []config.Policy { Service: "com.owncloud.web.ocdav", }, { - Endpoint: "/data", - Backend: "http://localhost:9140", + Endpoint: "/data", + Backend: "http://localhost:9140", + Unprotected: true, }, { Endpoint: "/app/", // /app or /apps? ocdav only handles /apps diff --git a/services/proxy/pkg/proxy/proxy_integration_test.go b/services/proxy/pkg/proxy/proxy_integration_test.go index 7f173d6894..65a8c037b8 100644 --- a/services/proxy/pkg/proxy/proxy_integration_test.go +++ b/services/proxy/pkg/proxy/proxy_integration_test.go @@ -2,15 +2,17 @@ package proxy import ( "bytes" + "fmt" "io" "io/ioutil" - "log" "net/http" "net/http/httptest" "net/url" "testing" + "github.com/owncloud/ocis/v2/ocis-pkg/log" "github.com/owncloud/ocis/v2/services/proxy/pkg/config" + "github.com/owncloud/ocis/v2/services/proxy/pkg/router" ) func TestProxyIntegration(t *testing.T) { @@ -114,6 +116,8 @@ func TestProxyIntegration(t *testing.T) { t.Run(tests[k].id, func(t *testing.T) { t.Parallel() tc := tests[k] + + rt := router.Middleware(nil, tc.conf, log.NewLogger()) rp := newTestProxy(testConfig(tc.conf), func(req *http.Request) *http.Response { if got, want := req.URL.String(), tc.expect.String(); got != want { t.Errorf("Proxied url should be %v got %v", want, got) @@ -135,7 +139,7 @@ func TestProxyIntegration(t *testing.T) { }) rr := httptest.NewRecorder() - rp.ServeHTTP(rr, tc.input) + rt(rp).ServeHTTP(rr, tc.input) rsp := rr.Result() if rsp.StatusCode != 200 { @@ -204,7 +208,7 @@ func (tc *testCase) withRequest(method string, target string, body io.Reader) *t func (tc *testCase) expectProxyTo(strURL string) testCase { pu, err := url.Parse(strURL) if err != nil { - log.Fatalf("Error parsing %v", strURL) + panic(fmt.Sprintf("Error parsing %v", strURL)) } tc.expect = pu