Skip to content

Commit 6de1d88

Browse files
authored
Use url-safe base64 encoding for download-shared-object api (#3305)
1 parent de19b6f commit 6de1d88

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

api/user_objects.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ func getShareObjectURL(ctx context.Context, client MCClient, r *http.Request, ve
11001100
return nil, pErr.Cause
11011101
}
11021102

1103-
encodedMinIOURL := b64.StdEncoding.EncodeToString([]byte(minioURL))
1103+
encodedMinIOURL := b64.URLEncoding.EncodeToString([]byte(minioURL))
11041104
requestURL := getRequestURLWithScheme(r)
11051105
objURL := fmt.Sprintf("%s/api/v1/download-shared-object/%s", requestURL, encodedMinIOURL)
11061106
return &objURL, nil

api/user_objects_test.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ func Test_shareObject(t *testing.T) {
927927
expected string
928928
}{
929929
{
930-
test: "Get share object url",
930+
test: "return sharefunc url base64 encoded with host name",
931931
args: args{
932932
r: &http.Request{
933933
TLS: nil,
@@ -944,7 +944,7 @@ func Test_shareObject(t *testing.T) {
944944
expected: "http://localhost:9090/api/v1/download-shared-object/aHR0cDovL3NvbWV1cmw=",
945945
},
946946
{
947-
test: "URL with TLS uses https scheme",
947+
test: "return https scheme if url uses TLS",
948948
args: args{
949949
r: &http.Request{
950950
TLS: &tls.ConnectionState{},
@@ -961,7 +961,7 @@ func Test_shareObject(t *testing.T) {
961961
expected: "https://localhost:9090/api/v1/download-shared-object/aHR0cDovL3NvbWV1cmw=",
962962
},
963963
{
964-
test: "handle invalid expire duration",
964+
test: "returns invalid expire duration if expiration is invalid",
965965
args: args{
966966
r: &http.Request{
967967
TLS: nil,
@@ -976,7 +976,7 @@ func Test_shareObject(t *testing.T) {
976976
wantError: errors.New("time: invalid duration \"invalid\""),
977977
},
978978
{
979-
test: "handle empty expire duration",
979+
test: "add default expiration if expiration is empty",
980980
args: args{
981981
r: &http.Request{
982982
TLS: nil,
@@ -992,7 +992,7 @@ func Test_shareObject(t *testing.T) {
992992
expected: "http://localhost:9090/api/v1/download-shared-object/aHR0cDovL3NvbWV1cmw=",
993993
},
994994
{
995-
test: "handle error on share func",
995+
test: "return error if sharefunc returns error",
996996
args: args{
997997
r: &http.Request{
998998
TLS: nil,
@@ -1006,6 +1006,23 @@ func Test_shareObject(t *testing.T) {
10061006
},
10071007
wantError: errors.New("probe error"),
10081008
},
1009+
{
1010+
test: "return shareFunc url base64 encoded url-safe",
1011+
args: args{
1012+
r: &http.Request{
1013+
TLS: nil,
1014+
Host: "localhost:9090",
1015+
},
1016+
versionID: "2121434",
1017+
expires: "3h",
1018+
shareFunc: func(_ context.Context, _ string, _ time.Duration) (string, *probe.Error) {
1019+
// https://127.0.0.1:9000/cestest/Audio%20icon.svg?X-Amz-Algorithm=AWS4-HMAC-SHA256 using StdEncoding adds an extra `/` making it not url safe
1020+
return "https://127.0.0.1:9000/cestest/Audio%20icon.svg?X-Amz-Algorithm=AWS4-HMAC-SHA256", nil
1021+
},
1022+
},
1023+
wantError: nil,
1024+
expected: "http://localhost:9090/api/v1/download-shared-object/aHR0cHM6Ly8xMjcuMC4wLjE6OTAwMC9jZXN0ZXN0L0F1ZGlvJTIwaWNvbi5zdmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTY=",
1025+
},
10091026
}
10101027

10111028
for _, tt := range tests {

0 commit comments

Comments
 (0)