Skip to content

Commit a1186bd

Browse files
committed
Implemtented TestDisableVersioningLeadsToCorrectQueryParams test for EOS HTTP / GRPC client
1 parent 85e05c8 commit a1186bd

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

internal/http/services/owncloud/ocdav/put_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import (
3636
"github.com/stretchr/testify/mock"
3737
)
3838

39+
// Test that when calls come in to the PUT endpoint with a X-Disable-Versioning header,
40+
// this header is propagated to the actual upload endpoint
3941
func TestDisableVersioningHeaderPassedAlong(t *testing.T) {
4042

4143
gatewayAPIEndpoint := "my-api-endpoint"

pkg/eosclient/eosgrpc/eoshttp.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,13 @@ func (c *EOSHTTPClient) PUTFile(ctx context.Context, remoteuser string, auth eos
370370

371371
// Now send the req and see what happens
372372
tempUrl, err := c.buildFullURL(urlpath, auth)
373-
parsedUrl, err := url.Parse(tempUrl)
374-
queryValues := parsedUrl.Query()
373+
base, err := url.Parse(tempUrl)
374+
queryValues := base.Query()
375375

376376
if disableVersioning {
377377
queryValues.Add("eos.versioning", strconv.Itoa(0))
378378
}
379-
finalurl := queryValues.Encode()
379+
finalurl := base.String() + queryValues.Encode()
380380

381381
if err != nil {
382382
log.Error().Str("func", "PUTFile").Str("url", finalurl).Str("err", err.Error()).Msg("can't create request")

pkg/eosclient/eosgrpc/eoshttp_test.go

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package eosgrpc
2+
3+
import (
4+
"context"
5+
"io"
6+
"net/http"
7+
"net/http/httptest"
8+
"strconv"
9+
"strings"
10+
"testing"
11+
12+
"github.com/cs3org/reva/pkg/eosclient"
13+
)
14+
15+
// Test that, when the PUTFile method is called with disableVersioning
16+
// set to true, the url for the EOS endpoint contains the right query param
17+
func TestDisableVersioningLeadsToCorrectQueryParams(t *testing.T) {
18+
19+
stream := io.NopCloser(strings.NewReader("Hello world!"))
20+
length := int64(12)
21+
app := "my-app"
22+
urlpath := "/my-file.txt"
23+
token := "my-secret-token"
24+
25+
// Create fake HTTP server that acts as the EOS endpoint
26+
calls := 0
27+
mockServerUpload := httptest.NewServer(
28+
http.HandlerFunc(
29+
func(w http.ResponseWriter, r *http.Request) {
30+
calls++
31+
queryValues := r.URL.Query()
32+
if queryValues.Get("eos.versioning") == "" {
33+
t.Errorf("Query parameter eos.versioning not set")
34+
}
35+
if q := queryValues.Get("eos.versioning"); q != strconv.Itoa(0) {
36+
t.Errorf("Query parameter eos.versioning set to wrong value; got %s, expected 0", q)
37+
}
38+
},
39+
),
40+
)
41+
42+
// Create EOS HTTP Client
43+
// TODO: right now, expects files to be on the FS
44+
client, err := NewEOSHTTPClient(&HTTPOptions{
45+
BaseURL: mockServerUpload.URL,
46+
})
47+
if err != nil {
48+
t.Errorf("Failed to construct client: %s", err.Error())
49+
}
50+
51+
// Test actual PUTFile call
52+
client.PUTFile(context.Background(), "remote-user", eosclient.Authorization{
53+
Token: token}, urlpath, stream, length, app, true)
54+
55+
// If no connection was made to the EOS endpoint, something is wrong
56+
if calls == 0 {
57+
t.Errorf("EOS endpoint was not called. ")
58+
}
59+
}

0 commit comments

Comments
 (0)