Skip to content

Commit 511a29c

Browse files
committed
Added first unit test: TestDisableVersioningHeaderPassedAlong
1 parent 56e5a8f commit 511a29c

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

go.mod

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/coreos/go-oidc/v3 v3.9.0
1515
github.com/creasty/defaults v1.7.0
1616
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e
17-
github.com/cs3org/go-cs3apis v0.0.0-20240802083356-d617314e1795
17+
github.com/cs3org/go-cs3apis v0.0.0-20240927085705-d50e291cbf4c
1818
github.com/dgraph-io/ristretto v0.1.1
1919
github.com/dolthub/go-mysql-server v0.14.0
2020
github.com/gdexlab/go-render v1.0.1
@@ -94,6 +94,7 @@ require (
9494
github.com/hashicorp/golang-lru v1.0.2 // indirect
9595
github.com/huandu/xstrings v1.4.0 // indirect
9696
github.com/imdario/mergo v0.3.16 // indirect
97+
github.com/jarcoal/httpmock v1.3.1 // indirect
9798
github.com/klauspost/compress v1.17.7 // indirect
9899
github.com/leodido/go-urn v1.4.0 // indirect
99100
github.com/lestrrat-go/strftime v1.0.4 // indirect

go.sum

+6
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,10 @@ github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJff
895895
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
896896
github.com/cs3org/go-cs3apis v0.0.0-20240802083356-d617314e1795 h1:8WkweBxMQ1W6IhcK0X3eWY+aQCjEktGwVt/4KLrtOZ8=
897897
github.com/cs3org/go-cs3apis v0.0.0-20240802083356-d617314e1795/go.mod h1:yyP8PRo0EZou3nSH7H4qjlzQwaydPeIRNgX50npQHpE=
898+
github.com/cs3org/go-cs3apis v0.0.0-20240906084627-d1b1d7653d75 h1:Gcs8Y6T5/rLsUIq8vRymNbxDUpzHvqhVHT0i/LkrjAo=
899+
github.com/cs3org/go-cs3apis v0.0.0-20240906084627-d1b1d7653d75/go.mod h1:yyP8PRo0EZou3nSH7H4qjlzQwaydPeIRNgX50npQHpE=
900+
github.com/cs3org/go-cs3apis v0.0.0-20240927085705-d50e291cbf4c h1:91oR7NL5bBvwHj00a/1aTePzOBheIjeNGqBWzG6try0=
901+
github.com/cs3org/go-cs3apis v0.0.0-20240927085705-d50e291cbf4c/go.mod h1:DedpcqXl193qF/08Y04IO0PpxyyMu8+GrkD6kWK2MEQ=
898902
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
899903
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
900904
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -1202,6 +1206,8 @@ github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
12021206
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
12031207
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
12041208
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
1209+
github.com/jarcoal/httpmock v1.3.1 h1:iUx3whfZWVf3jT01hQTO/Eo5sAYtB2/rqaUuOtpInww=
1210+
github.com/jarcoal/httpmock v1.3.1/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg=
12051211
github.com/jedib0t/go-pretty v4.3.0+incompatible h1:CGs8AVhEKg/n9YbUenWmNStRW2PHJzaeDodcfvRAbIo=
12061212
github.com/jedib0t/go-pretty v4.3.0+incompatible/go.mod h1:XemHduiw8R651AF9Pt4FwCTKeG3oo7hrHJAoznj9nag=
12071213
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Copyright 2018-2024 CERN
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// In applying this license, CERN does not waive the privileges and immunities
16+
// granted to it by virtue of its status as an Intergovernmental Organization
17+
// or submit itself to any jurisdiction.
18+
19+
package ocdav
20+
21+
import (
22+
"context"
23+
"net/http"
24+
"net/http/httptest"
25+
"strconv"
26+
"strings"
27+
"testing"
28+
29+
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
30+
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
31+
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
32+
mockgateway "github.com/cs3org/go-cs3apis/mocks/github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
33+
"github.com/cs3org/reva/pkg/httpclient"
34+
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
35+
"github.com/rs/zerolog"
36+
"github.com/stretchr/testify/mock"
37+
)
38+
39+
func TestDisableVersioningHeaderPassedAlong(t *testing.T) {
40+
41+
gatewayAPIEndpoint := "my-api-endpoint"
42+
incomingPath := "myfile.txt"
43+
input := "Hello world!"
44+
45+
// create HTTP request
46+
request := httptest.NewRequest(http.MethodPut, incomingPath, strings.NewReader(input))
47+
request.Header.Add(HeaderContentLength, strconv.Itoa(len(input)))
48+
request.Header.Add(HeaderDisableVersioning, "true")
49+
50+
// Create fake HTTP server for upload endpoint
51+
// Here we will check whether the header was correctly set
52+
calls := 0
53+
w := httptest.NewRecorder()
54+
mockServerUpload := httptest.NewServer(
55+
http.HandlerFunc(
56+
func(w http.ResponseWriter, r *http.Request) {
57+
if header := r.Header.Get(HeaderDisableVersioning); header == "" {
58+
t.Errorf("expected header %s but header was not set", HeaderDisableVersioning)
59+
}
60+
calls++
61+
},
62+
),
63+
)
64+
endpointPath := mockServerUpload.URL
65+
66+
// Set up mocked GatewayAPIClient
67+
gatewayClient := mockgateway.NewMockGatewayAPIClient(t)
68+
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(&provider.StatResponse{Status: &rpc.Status{Code: rpc.Code_CODE_NOT_FOUND}}, nil)
69+
gatewayClient.On("InitiateFileUpload", mock.Anything, mock.Anything).Return(&gateway.InitiateFileUploadResponse{
70+
Status: &rpc.Status{Code: rpc.Code_CODE_OK},
71+
Protocols: []*gateway.FileUploadProtocol{
72+
{Protocol: "simple", UploadEndpoint: endpointPath, Token: "my-secret-token"},
73+
}}, nil)
74+
pool.RegisterGatewayServiceClient(gatewayClient, gatewayAPIEndpoint)
75+
76+
// Set up OCDAV Service
77+
service := svc{
78+
c: &Config{
79+
GatewaySvc: gatewayAPIEndpoint,
80+
},
81+
client: httpclient.New(),
82+
}
83+
ref := provider.Reference{}
84+
85+
// Do the actual call
86+
service.handlePut(context.Background(), w, request, &ref, zerolog.Logger{})
87+
88+
// If no connection was made to the upload endpoint, something is also wrong
89+
if calls == 0 {
90+
t.Errorf("Upload endpoint was not called. ")
91+
}
92+
}

pkg/rgrpc/todo/pool/pool.go

+7
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ func NewConn(options Options) (*grpc.ClientConn, error) {
9797
return conn, nil
9898
}
9999

100+
func RegisterGatewayServiceClient(client gateway.GatewayAPIClient, endpoint string) {
101+
gatewayProviders.m.Lock()
102+
defer gatewayProviders.m.Unlock()
103+
104+
gatewayProviders.conn[endpoint] = client
105+
}
106+
100107
// GetGatewayServiceClient returns a GatewayServiceClient.
101108
func GetGatewayServiceClient(opts ...Option) (gateway.GatewayAPIClient, error) {
102109
gatewayProviders.m.Lock()

0 commit comments

Comments
 (0)