-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented X-Disable-Versioning header to disable versioning on EOS
This commit introduces a new header, `X-Disable-Versioning`, that is available on PUT requests. This header will disable versioning for this file save if the storage backend is EOS. Additionally, this commit introduces two unit tests related to this functionality: - TestDisableVersioningLeadsToCorrectQueryParams: test whether disabling versioning leads to correct query parameteers for the EOS HTTP / GRPC client - TestDisableVersioningHeaderPassedAlong: test whether a header passed to the initial endpoint is propagated to the actual upload endpoint Finally, this commit also fixes a bug that was already present, where the app was not passed along in the case of token-based authz
- Loading branch information
Jesse Geens
committed
Nov 11, 2024
1 parent
a30a0ba
commit 78191f9
Showing
13 changed files
with
219 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Enhancement: Add HTTP header to disable versioning on EOS | ||
|
||
This enhancement introduces a new header, `X-Disable-Versioning`, on PUT requests. EOS will not version this file save whenever this header is set with a truthy value. | ||
See also: https://github.com/cs3org/reva/pull/4864 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright 2018-2024 CERN | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// In applying this license, CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
package ocdav | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/http/httptest" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
|
||
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" | ||
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" | ||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" | ||
mockgateway "github.com/cs3org/go-cs3apis/mocks/github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" | ||
"github.com/cs3org/reva/pkg/httpclient" | ||
"github.com/cs3org/reva/pkg/rgrpc/todo/pool" | ||
"github.com/rs/zerolog" | ||
"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" | ||
incomingPath := "http://my-reva.com/myfile.txt" | ||
input := "Hello world!" | ||
|
||
// create HTTP request | ||
request := httptest.NewRequest(http.MethodPut, incomingPath, strings.NewReader(input)) | ||
request.Header.Add(HeaderContentLength, strconv.Itoa(len(input))) | ||
request.Header.Add(HeaderDisableVersioning, "true") | ||
|
||
// Create fake HTTP server for upload endpoint | ||
// Here we will check whether the header was correctly set | ||
calls := 0 | ||
w := httptest.NewRecorder() | ||
mockServerUpload := httptest.NewServer( | ||
http.HandlerFunc( | ||
func(w http.ResponseWriter, r *http.Request) { | ||
if header := r.Header.Get(HeaderDisableVersioning); header == "" { | ||
t.Errorf("expected header %s but header was not set", HeaderDisableVersioning) | ||
} | ||
calls++ | ||
}, | ||
), | ||
) | ||
endpointPath := mockServerUpload.URL | ||
|
||
// Set up mocked GatewayAPIClient | ||
gatewayClient := mockgateway.NewMockGatewayAPIClient(t) | ||
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(&provider.StatResponse{Status: &rpc.Status{Code: rpc.Code_CODE_NOT_FOUND}}, nil) | ||
gatewayClient.On("InitiateFileUpload", mock.Anything, mock.Anything).Return(&gateway.InitiateFileUploadResponse{ | ||
Status: &rpc.Status{Code: rpc.Code_CODE_OK}, | ||
Protocols: []*gateway.FileUploadProtocol{ | ||
{Protocol: "simple", UploadEndpoint: endpointPath, Token: "my-secret-token"}, | ||
}}, nil) | ||
pool.RegisterGatewayServiceClient(gatewayClient, gatewayAPIEndpoint) | ||
|
||
// Set up OCDAV Service | ||
service := svc{ | ||
c: &Config{ | ||
GatewaySvc: gatewayAPIEndpoint, | ||
}, | ||
client: httpclient.New(), | ||
} | ||
ref := provider.Reference{} | ||
|
||
// Do the actual call | ||
service.handlePut(context.Background(), w, request, &ref, zerolog.Logger{}) | ||
|
||
// If no connection was made to the upload endpoint, something is also wrong | ||
if calls == 0 { | ||
t.Errorf("Upload endpoint was not called. ") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?queryparam=1" | ||
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. ") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters