Skip to content

Commit

Permalink
Implemtented TestDisableVersioningLeadsToCorrectQueryParams test for …
Browse files Browse the repository at this point in the history
…EOS HTTP / GRPC client
  • Loading branch information
Jesse Geens committed Sep 30, 2024
1 parent 85e05c8 commit a1186bd
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
2 changes: 2 additions & 0 deletions internal/http/services/owncloud/ocdav/put_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import (
"github.com/stretchr/testify/mock"
)

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

gatewayAPIEndpoint := "my-api-endpoint"
Expand Down
6 changes: 3 additions & 3 deletions pkg/eosclient/eosgrpc/eoshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,13 @@ func (c *EOSHTTPClient) PUTFile(ctx context.Context, remoteuser string, auth eos

// Now send the req and see what happens
tempUrl, err := c.buildFullURL(urlpath, auth)
parsedUrl, err := url.Parse(tempUrl)
queryValues := parsedUrl.Query()
base, err := url.Parse(tempUrl)
queryValues := base.Query()

if disableVersioning {
queryValues.Add("eos.versioning", strconv.Itoa(0))
}
finalurl := queryValues.Encode()
finalurl := base.String() + queryValues.Encode()

if err != nil {
log.Error().Str("func", "PUTFile").Str("url", finalurl).Str("err", err.Error()).Msg("can't create request")
Expand Down
59 changes: 59 additions & 0 deletions pkg/eosclient/eosgrpc/eoshttp_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package eosgrpc

import (
"context"
"io"
"net/http"
"net/http/httptest"
"strconv"
"strings"
"testing"

"github.com/cs3org/reva/pkg/eosclient"
)

// Test that, when the PUTFile method is called with disableVersioning
// set to true, the url for the EOS endpoint contains the right query param
func TestDisableVersioningLeadsToCorrectQueryParams(t *testing.T) {

stream := io.NopCloser(strings.NewReader("Hello world!"))
length := int64(12)
app := "my-app"
urlpath := "/my-file.txt"
token := "my-secret-token"

// Create fake HTTP server that acts as the EOS endpoint
calls := 0
mockServerUpload := httptest.NewServer(
http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
calls++
queryValues := r.URL.Query()
if queryValues.Get("eos.versioning") == "" {
t.Errorf("Query parameter eos.versioning not set")
}
if q := queryValues.Get("eos.versioning"); q != strconv.Itoa(0) {
t.Errorf("Query parameter eos.versioning set to wrong value; got %s, expected 0", q)
}
},
),
)

// Create EOS HTTP Client
// TODO: right now, expects files to be on the FS
client, err := NewEOSHTTPClient(&HTTPOptions{
BaseURL: mockServerUpload.URL,
})
if err != nil {
t.Errorf("Failed to construct client: %s", err.Error())
}

// Test actual PUTFile call
client.PUTFile(context.Background(), "remote-user", eosclient.Authorization{
Token: token}, urlpath, stream, length, app, true)

// If no connection was made to the EOS endpoint, something is wrong
if calls == 0 {
t.Errorf("EOS endpoint was not called. ")
}
}

0 comments on commit a1186bd

Please sign in to comment.