mirror of
https://github.com/OpenMaxIO/openmaxio-object-browser
synced 2026-07-01 07:41:18 -07:00
Use automatic URI encoding (#3352)
This commit is contained in:
@@ -18,7 +18,6 @@ package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
b64 "encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -36,14 +35,6 @@ import (
|
||||
|
||||
var token string
|
||||
|
||||
func encodeBase64(fileName string) string {
|
||||
/*
|
||||
Helper function to encode in base64 the file name so we can get the path
|
||||
*/
|
||||
path := b64.StdEncoding.EncodeToString([]byte(fileName))
|
||||
return path
|
||||
}
|
||||
|
||||
func inspectHTTPResponse(httpResponse *http.Response) string {
|
||||
/*
|
||||
Helper function to inspect the content of a HTTP response.
|
||||
|
||||
@@ -18,11 +18,11 @@ package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -114,7 +114,7 @@ func Test_GetGroupAPI(t *testing.T) {
|
||||
{
|
||||
name: "Get Group - Valid",
|
||||
args: args{
|
||||
api: base64.StdEncoding.EncodeToString([]byte("getgroup1")),
|
||||
api: "getgroup1",
|
||||
},
|
||||
expectedStatus: 200,
|
||||
expectedError: nil,
|
||||
@@ -122,7 +122,7 @@ func Test_GetGroupAPI(t *testing.T) {
|
||||
{
|
||||
name: "Get Group - Invalid",
|
||||
args: args{
|
||||
api: base64.StdEncoding.EncodeToString([]byte("askfjalkd")),
|
||||
api: "askfjalkd",
|
||||
},
|
||||
expectedStatus: 500,
|
||||
expectedError: nil,
|
||||
@@ -140,7 +140,7 @@ func Test_GetGroupAPI(t *testing.T) {
|
||||
requestDataJSON, _ := json.Marshal(requestDataPolicy)
|
||||
requestDataBody := bytes.NewReader(requestDataJSON)
|
||||
request, err := http.NewRequest(
|
||||
"GET", fmt.Sprintf("http://localhost:9090/api/v1/group/%s", tt.args.api), requestDataBody)
|
||||
"GET", fmt.Sprintf("http://localhost:9090/api/v1/group/%s", url.PathEscape(tt.args.api)), requestDataBody)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
@@ -224,7 +224,7 @@ func Test_PutGroupsAPI(t *testing.T) {
|
||||
{
|
||||
name: "Put Group - Valid",
|
||||
args: args{
|
||||
api: base64.StdEncoding.EncodeToString([]byte("putgroup1")),
|
||||
api: "putgroup1",
|
||||
members: []string{"member3"},
|
||||
status: "enabled",
|
||||
},
|
||||
@@ -234,7 +234,7 @@ func Test_PutGroupsAPI(t *testing.T) {
|
||||
{
|
||||
name: "Put Group - Invalid",
|
||||
args: args{
|
||||
api: base64.StdEncoding.EncodeToString([]byte("gdgfdfgd")),
|
||||
api: "gdgfdfgd",
|
||||
members: []string{"member3"},
|
||||
status: "enabled",
|
||||
},
|
||||
@@ -257,7 +257,7 @@ func Test_PutGroupsAPI(t *testing.T) {
|
||||
requestDataJSON, _ := json.Marshal(requestDataPolicy)
|
||||
requestDataBody := bytes.NewReader(requestDataJSON)
|
||||
request, err := http.NewRequest(
|
||||
"PUT", fmt.Sprintf("http://localhost:9090/api/v1/group/%s", tt.args.api), requestDataBody)
|
||||
"PUT", fmt.Sprintf("http://localhost:9090/api/v1/group/%s", url.PathEscape(tt.args.api)), requestDataBody)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
@@ -294,7 +294,7 @@ func Test_DeleteGroupAPI(t *testing.T) {
|
||||
{
|
||||
name: "Delete Group - Valid",
|
||||
args: args{
|
||||
api: base64.StdEncoding.EncodeToString([]byte("grouptests1")),
|
||||
api: "grouptests1",
|
||||
},
|
||||
verb: "DELETE",
|
||||
expectedStatus: 204,
|
||||
@@ -303,7 +303,7 @@ func Test_DeleteGroupAPI(t *testing.T) {
|
||||
{
|
||||
name: "Delete Group - Invalid",
|
||||
args: args{
|
||||
api: base64.StdEncoding.EncodeToString([]byte("grouptests12345")),
|
||||
api: "grouptests12345",
|
||||
},
|
||||
verb: "DELETE",
|
||||
expectedStatus: 404,
|
||||
@@ -312,7 +312,7 @@ func Test_DeleteGroupAPI(t *testing.T) {
|
||||
{
|
||||
name: "Access Group After Delete - Invalid",
|
||||
args: args{
|
||||
api: base64.StdEncoding.EncodeToString([]byte("grouptests1")),
|
||||
api: "grouptests1",
|
||||
},
|
||||
verb: "GET",
|
||||
expectedStatus: 500,
|
||||
@@ -331,7 +331,7 @@ func Test_DeleteGroupAPI(t *testing.T) {
|
||||
requestDataJSON, _ := json.Marshal(requestDataPolicy)
|
||||
requestDataBody := bytes.NewReader(requestDataJSON)
|
||||
request, err := http.NewRequest(
|
||||
tt.verb, fmt.Sprintf("http://localhost:9090/api/v1/group/%s", tt.args.api), requestDataBody)
|
||||
tt.verb, fmt.Sprintf("http://localhost:9090/api/v1/group/%s", url.PathEscape(tt.args.api)), requestDataBody)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
|
||||
@@ -19,12 +19,12 @@ package integration
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -90,7 +90,7 @@ func TestObjectGet(t *testing.T) {
|
||||
{
|
||||
name: "Preview Object",
|
||||
args: args{
|
||||
encodedPrefix: base64.StdEncoding.EncodeToString([]byte("myobject")),
|
||||
encodedPrefix: "myobject",
|
||||
},
|
||||
expectedStatus: 200,
|
||||
expectedError: nil,
|
||||
@@ -98,7 +98,7 @@ func TestObjectGet(t *testing.T) {
|
||||
{
|
||||
name: "Preview image",
|
||||
args: args{
|
||||
encodedPrefix: base64.StdEncoding.EncodeToString([]byte("myobject.jpg")),
|
||||
encodedPrefix: "myobject.jpg",
|
||||
},
|
||||
expectedStatus: 200,
|
||||
expectedError: nil,
|
||||
@@ -106,7 +106,7 @@ func TestObjectGet(t *testing.T) {
|
||||
{
|
||||
name: "Get Range of bytes",
|
||||
args: args{
|
||||
encodedPrefix: base64.StdEncoding.EncodeToString([]byte("myobject.jpg")),
|
||||
encodedPrefix: "myobject.jpg",
|
||||
bytesRange: "bytes=1-4",
|
||||
},
|
||||
expectedStatus: 206,
|
||||
@@ -115,7 +115,7 @@ func TestObjectGet(t *testing.T) {
|
||||
{
|
||||
name: "Get Range of bytes empty start",
|
||||
args: args{
|
||||
encodedPrefix: base64.StdEncoding.EncodeToString([]byte("myobject.jpg")),
|
||||
encodedPrefix: "myobject.jpg",
|
||||
bytesRange: "bytes=-4",
|
||||
},
|
||||
expectedStatus: 206,
|
||||
@@ -124,7 +124,7 @@ func TestObjectGet(t *testing.T) {
|
||||
{
|
||||
name: "Get Invalid Range of bytes",
|
||||
args: args{
|
||||
encodedPrefix: base64.StdEncoding.EncodeToString([]byte("myobject.jpg")),
|
||||
encodedPrefix: "myobject.jpg",
|
||||
bytesRange: "bytes=9-12",
|
||||
},
|
||||
expectedStatus: 500,
|
||||
@@ -133,7 +133,7 @@ func TestObjectGet(t *testing.T) {
|
||||
{
|
||||
name: "Get Larger Range of bytes empty start",
|
||||
args: args{
|
||||
encodedPrefix: base64.StdEncoding.EncodeToString([]byte("myobject.jpg")),
|
||||
encodedPrefix: "myobject.jpg",
|
||||
bytesRange: "bytes=-12",
|
||||
},
|
||||
expectedStatus: 206,
|
||||
@@ -142,29 +142,12 @@ func TestObjectGet(t *testing.T) {
|
||||
{
|
||||
name: "Get invalid seek start Range of bytes",
|
||||
args: args{
|
||||
encodedPrefix: base64.StdEncoding.EncodeToString([]byte("myobject.jpg")),
|
||||
encodedPrefix: "myobject.jpg",
|
||||
bytesRange: "bytes=12-16",
|
||||
},
|
||||
expectedStatus: 500,
|
||||
expectedError: nil,
|
||||
},
|
||||
{
|
||||
name: "Bad Preview Object",
|
||||
args: args{
|
||||
encodedPrefix: "garble",
|
||||
},
|
||||
expectedStatus: 400,
|
||||
expectedError: nil,
|
||||
},
|
||||
{
|
||||
name: "Bad Version Preview Object",
|
||||
args: args{
|
||||
encodedPrefix: base64.StdEncoding.EncodeToString([]byte("myobject")),
|
||||
versionID: "garble",
|
||||
},
|
||||
expectedStatus: 500,
|
||||
expectedError: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -172,7 +155,7 @@ func TestObjectGet(t *testing.T) {
|
||||
client := &http.Client{
|
||||
Timeout: 3 * time.Second,
|
||||
}
|
||||
destination := fmt.Sprintf("/api/v1/buckets/%s/objects/download?preview=true&prefix=%s&version_id=%s", bucketName, tt.args.encodedPrefix, tt.args.versionID)
|
||||
destination := fmt.Sprintf("/api/v1/buckets/%s/objects/download?preview=true&prefix=%s&version_id=%s", url.PathEscape(bucketName), url.QueryEscape(tt.args.encodedPrefix), url.QueryEscape(tt.args.versionID))
|
||||
finalURL := fmt.Sprintf("http://localhost:9090%s", destination)
|
||||
request, err := http.NewRequest("GET", finalURL, nil)
|
||||
if err != nil {
|
||||
@@ -198,7 +181,7 @@ func TestObjectGet(t *testing.T) {
|
||||
}
|
||||
|
||||
func downloadMultipleFiles(bucketName string, objects []string) (*http.Response, error) {
|
||||
requestURL := fmt.Sprintf("http://localhost:9090/api/v1/buckets/%s/objects/download-multiple", bucketName)
|
||||
requestURL := fmt.Sprintf("http://localhost:9090/api/v1/buckets/%s/objects/download-multiple", url.PathEscape(bucketName))
|
||||
|
||||
postReqParams, _ := json.Marshal(objects)
|
||||
reqBody := bytes.NewReader(postReqParams)
|
||||
|
||||
@@ -18,12 +18,12 @@ package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -179,6 +179,31 @@ func Test_AddPolicyAPI(t *testing.T) {
|
||||
expectedStatus: 400,
|
||||
expectedError: nil,
|
||||
},
|
||||
{
|
||||
name: "Create Policy - Reserved character in name",
|
||||
args: args{
|
||||
api: "/policies",
|
||||
name: "space/test?",
|
||||
policy: swag.String(`
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": [
|
||||
"s3:GetBucketLocation",
|
||||
"s3:GetObject"
|
||||
],
|
||||
"Resource": [
|
||||
"arn:aws:s3:::*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}`),
|
||||
},
|
||||
expectedStatus: 201,
|
||||
expectedError: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -491,7 +516,7 @@ func Test_ListPoliciesAPI(t *testing.T) {
|
||||
func Test_GetPolicyAPI(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
AddPolicy("getpolicytest", `
|
||||
AddPolicy("test/policy?", `
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
@@ -520,7 +545,7 @@ func Test_GetPolicyAPI(t *testing.T) {
|
||||
{
|
||||
name: "Get Policies - Invalid",
|
||||
args: args{
|
||||
api: base64.StdEncoding.EncodeToString([]byte("test3")),
|
||||
api: "test3",
|
||||
},
|
||||
expectedStatus: 500,
|
||||
expectedError: nil,
|
||||
@@ -528,7 +553,7 @@ func Test_GetPolicyAPI(t *testing.T) {
|
||||
{
|
||||
name: "Get Policies - Valid",
|
||||
args: args{
|
||||
api: base64.StdEncoding.EncodeToString([]byte("getpolicytest")),
|
||||
api: "test/policy?",
|
||||
},
|
||||
expectedStatus: 200,
|
||||
expectedError: nil,
|
||||
@@ -542,7 +567,7 @@ func Test_GetPolicyAPI(t *testing.T) {
|
||||
}
|
||||
|
||||
request, err := http.NewRequest(
|
||||
"GET", fmt.Sprintf("http://localhost:9090/api/v1/policy/%s", tt.args.api), nil)
|
||||
"GET", fmt.Sprintf("http://localhost:9090/api/v1/policy/%s", url.PathEscape(tt.args.api)), nil)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
@@ -595,7 +620,7 @@ func Test_PolicyListUsersAPI(t *testing.T) {
|
||||
{
|
||||
name: "List Users for Policy - Valid",
|
||||
args: args{
|
||||
api: "/policies/" + base64.StdEncoding.EncodeToString([]byte("policylistusers")) + "/users",
|
||||
api: "/policies/" + url.PathEscape("policylistusers") + "/users",
|
||||
},
|
||||
expectedStatus: 200,
|
||||
expectedError: nil,
|
||||
@@ -603,7 +628,7 @@ func Test_PolicyListUsersAPI(t *testing.T) {
|
||||
{
|
||||
name: "List Users for Policy - Invalid",
|
||||
args: args{
|
||||
api: "/policies/" + base64.StdEncoding.EncodeToString([]byte("test2")) + "/users",
|
||||
api: "/policies/" + url.PathEscape("test2") + "/users",
|
||||
},
|
||||
expectedStatus: 404,
|
||||
expectedError: nil,
|
||||
@@ -674,7 +699,7 @@ func Test_PolicyListGroupsAPI(t *testing.T) {
|
||||
{
|
||||
name: "List Users for Policy - Valid",
|
||||
args: args{
|
||||
api: "/policies/" + base64.StdEncoding.EncodeToString([]byte("policylistgroups")) + "/groups",
|
||||
api: "/policies/" + url.PathEscape("policylistgroups") + "/groups",
|
||||
},
|
||||
expectedStatus: 200,
|
||||
expectedError: nil,
|
||||
@@ -682,7 +707,7 @@ func Test_PolicyListGroupsAPI(t *testing.T) {
|
||||
{
|
||||
name: "List Users for Policy - Invalid",
|
||||
args: args{
|
||||
api: "/policies/" + base64.StdEncoding.EncodeToString([]byte("test3")) + "/groups",
|
||||
api: "/policies/" + url.PathEscape("test3") + "/groups",
|
||||
},
|
||||
expectedStatus: 404,
|
||||
expectedError: nil,
|
||||
@@ -751,7 +776,7 @@ func Test_DeletePolicyAPI(t *testing.T) {
|
||||
{
|
||||
name: "Delete Policies - Valid",
|
||||
args: args{
|
||||
api: base64.StdEncoding.EncodeToString([]byte("testdelete")),
|
||||
api: "testdelete",
|
||||
method: "DELETE",
|
||||
},
|
||||
expectedStatus: 204,
|
||||
@@ -760,7 +785,7 @@ func Test_DeletePolicyAPI(t *testing.T) {
|
||||
{
|
||||
name: "Get Policy After Delete - Invalid",
|
||||
args: args{
|
||||
api: base64.StdEncoding.EncodeToString([]byte("testdelete")),
|
||||
api: "testdelete",
|
||||
method: "GET",
|
||||
},
|
||||
expectedStatus: 500,
|
||||
@@ -775,7 +800,7 @@ func Test_DeletePolicyAPI(t *testing.T) {
|
||||
}
|
||||
|
||||
request, err := http.NewRequest(
|
||||
tt.args.method, fmt.Sprintf("http://localhost:9090/api/v1/policy/%s", tt.args.api), nil)
|
||||
tt.args.method, fmt.Sprintf("http://localhost:9090/api/v1/policy/%s", url.PathEscape(tt.args.api)), nil)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
@@ -804,11 +829,6 @@ func Test_GetAUserPolicyAPI(t *testing.T) {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
// encode usernames to pass to api
|
||||
bName := []byte("getuserpolicyuser")
|
||||
fName := []byte("failname")
|
||||
encodedName := base64.URLEncoding.EncodeToString(bName)
|
||||
encodedFailName := base64.URLEncoding.EncodeToString(fName)
|
||||
|
||||
type args struct {
|
||||
api string
|
||||
@@ -822,7 +842,7 @@ func Test_GetAUserPolicyAPI(t *testing.T) {
|
||||
{
|
||||
name: "Get User Policy - Invalid",
|
||||
args: args{
|
||||
api: "/user/" + encodedFailName + "/policies",
|
||||
api: "/user/" + url.PathEscape("failname") + "/policies",
|
||||
},
|
||||
expectedStatus: 401,
|
||||
expectedError: nil,
|
||||
@@ -830,7 +850,7 @@ func Test_GetAUserPolicyAPI(t *testing.T) {
|
||||
{
|
||||
name: "Get User Policy - Valid",
|
||||
args: args{
|
||||
api: "/user/" + encodedName + "/policies",
|
||||
api: "/user/" + url.PathEscape("getuserpolicyuser") + "/policies",
|
||||
},
|
||||
expectedStatus: 200,
|
||||
expectedError: nil,
|
||||
|
||||
@@ -18,11 +18,11 @@ package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -92,7 +92,7 @@ func TestAddServiceAccount(t *testing.T) {
|
||||
// {{baseUrl}}/user?name=proident velit
|
||||
// Investiga como se borra en el browser.
|
||||
request, err = http.NewRequest(
|
||||
"DELETE", "http://localhost:9090/api/v1/service-accounts/"+base64.StdEncoding.EncodeToString([]byte("testuser1")), nil)
|
||||
"DELETE", "http://localhost:9090/api/v1/service-accounts/"+url.PathEscape("testuser1"), nil)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
|
||||
@@ -21,13 +21,13 @@ package integration
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -396,7 +396,7 @@ func UploadAnObject(bucketName, fileName string) (*http.Response, error) {
|
||||
contentType + boundaryEnd
|
||||
arrayOfBytes := []byte(file)
|
||||
requestDataBody := bytes.NewReader(arrayOfBytes)
|
||||
apiURL := "http://localhost:9090/api/v1/buckets/" + bucketName + "/objects/upload" + "?prefix=" + base64.StdEncoding.EncodeToString([]byte(fileName))
|
||||
apiURL := "http://localhost:9090/api/v1/buckets/" + url.PathEscape(bucketName) + "/objects/upload" + "?prefix=" + url.QueryEscape(fileName)
|
||||
request, err := http.NewRequest(
|
||||
"POST",
|
||||
apiURL,
|
||||
@@ -423,9 +423,8 @@ func DeleteObject(bucketName, path string, recursive, allVersions bool) (*http.R
|
||||
DELETE:
|
||||
{{baseUrl}}/buckets/bucketName/objects?path=Y2VzYXJpby50eHQ=&recursive=false&all_versions=false
|
||||
*/
|
||||
prefixEncoded := base64.StdEncoding.EncodeToString([]byte(path))
|
||||
url := "http://localhost:9090/api/v1/buckets/" + bucketName + "/objects?prefix=" +
|
||||
prefixEncoded + "&recursive=" + strconv.FormatBool(recursive) + "&all_versions=" +
|
||||
url := "http://localhost:9090/api/v1/buckets/" + url.PathEscape(bucketName) + "/objects?prefix=" +
|
||||
url.QueryEscape(path) + "&recursive=" + strconv.FormatBool(recursive) + "&all_versions=" +
|
||||
strconv.FormatBool(allVersions)
|
||||
request, err := http.NewRequest(
|
||||
"DELETE",
|
||||
@@ -444,13 +443,13 @@ func DeleteObject(bucketName, path string, recursive, allVersions bool) (*http.R
|
||||
return response, err
|
||||
}
|
||||
|
||||
func ListObjects(bucketName, prefix, withVersions string) (*http.Response, error) {
|
||||
func ListObjects(bucketName, prefix string, withVersions bool) (*http.Response, error) {
|
||||
/*
|
||||
Helper function to list objects in a bucket.
|
||||
GET: {{baseUrl}}/buckets/:bucket_name/objects
|
||||
*/
|
||||
request, err := http.NewRequest("GET",
|
||||
"http://localhost:9090/api/v1/buckets/"+bucketName+"/objects?prefix="+prefix+"&with_versions="+withVersions,
|
||||
"http://localhost:9090/api/v1/buckets/"+url.PathEscape(bucketName)+"/objects?prefix="+url.QueryEscape(prefix)+"&with_versions="+strconv.FormatBool(withVersions),
|
||||
nil)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@@ -753,8 +752,8 @@ func TestPutObjectsLegalholdStatus(t *testing.T) {
|
||||
// Variables
|
||||
assert := assert.New(t)
|
||||
bucketName := "testputobjectslegalholdstatus"
|
||||
objName := "testputobjectslegalholdstatus.txt" // // encoded base64 of testputobjectslegalholdstatus.txt = dGVzdHB1dG9iamVjdHNsZWdhbGhvbGRzdGF0dXMudHh0
|
||||
objectNameEncoded := "dGVzdHB1dG9iamVjdHNsZWdhbGhvbGRzdGF0dXMudHh0"
|
||||
objName := "testputobjectslegalholdstatus.txt"
|
||||
objectNameEncoded := url.QueryEscape(objName)
|
||||
status := "enabled"
|
||||
|
||||
// 1. Create bucket
|
||||
@@ -782,7 +781,7 @@ func TestPutObjectsLegalholdStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
// Get versionID
|
||||
listResponse, _ := ListObjects(bucketName, "", "true")
|
||||
listResponse, _ := ListObjects(bucketName, "", true)
|
||||
bodyBytes, _ := io.ReadAll(listResponse.Body)
|
||||
listObjs := models.ListObjectsResponse{}
|
||||
err := json.Unmarshal(bodyBytes, &listObjs)
|
||||
@@ -807,13 +806,6 @@ func TestPutObjectsLegalholdStatus(t *testing.T) {
|
||||
versionID: validVersionID,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Invalid VersionID when putting object's legal hold status",
|
||||
expectedStatus: 500,
|
||||
args: args{
|
||||
versionID: "*&^###Test1ThisMightBeInvalid555",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(_ *testing.T) {
|
||||
@@ -1036,7 +1028,7 @@ func TestDeleteObjectsRetentionStatus(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
bucketName := "testdeleteobjectslegalholdstatus"
|
||||
fileName := "testdeleteobjectslegalholdstatus.txt"
|
||||
validPrefix := encodeBase64(fileName)
|
||||
validPrefix := url.QueryEscape(fileName)
|
||||
|
||||
// 1. Create bucket
|
||||
if !setupBucket(bucketName, true, map[string]interface{}{"enabled": true}, nil, nil, assert, 200) {
|
||||
@@ -1063,7 +1055,7 @@ func TestDeleteObjectsRetentionStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
// Get versionID
|
||||
listResponse, _ := ListObjects(bucketName, validPrefix, "true")
|
||||
listResponse, _ := ListObjects(bucketName, validPrefix, true)
|
||||
bodyBytes, _ := io.ReadAll(listResponse.Body)
|
||||
listObjs := models.ListObjectsResponse{}
|
||||
err := json.Unmarshal(bodyBytes, &listObjs)
|
||||
@@ -1204,7 +1196,7 @@ func TestRestoreObjectToASelectedVersion(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
bucketName := "testrestoreobjectstoselectedversion"
|
||||
fileName := "testrestoreobjectstoselectedversion.txt"
|
||||
validPrefix := encodeBase64(fileName)
|
||||
validPrefix := url.QueryEscape(fileName)
|
||||
|
||||
// 1. Create bucket
|
||||
if !setupBucket(bucketName, true, map[string]interface{}{"enabled": true}, nil, nil, assert, 200) {
|
||||
@@ -1231,7 +1223,7 @@ func TestRestoreObjectToASelectedVersion(t *testing.T) {
|
||||
}
|
||||
|
||||
// 3. Get versionID
|
||||
listResponse, _ := ListObjects(bucketName, validPrefix, "true")
|
||||
listResponse, _ := ListObjects(bucketName, validPrefix, true)
|
||||
bodyBytes, _ := io.ReadAll(listResponse.Body)
|
||||
listObjs := models.ListObjectsResponse{}
|
||||
err := json.Unmarshal(bodyBytes, &listObjs)
|
||||
@@ -1348,7 +1340,7 @@ func TestGetsTheMetadataOfAnObject(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
bucketName := "testgetsthemetadataofanobject"
|
||||
fileName := "testshareobjectonurl.txt"
|
||||
validPrefix := encodeBase64(fileName)
|
||||
validPrefix := url.QueryEscape(fileName)
|
||||
tags := make(map[string]string)
|
||||
tags["tag"] = "testputobjecttagbucketonetagone"
|
||||
|
||||
@@ -1421,7 +1413,7 @@ func TestPutObjectsRetentionStatus(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
bucketName := "testputobjectsretentionstatus"
|
||||
fileName := "testputobjectsretentionstatus.txt"
|
||||
prefix := encodeBase64(fileName)
|
||||
prefix := url.QueryEscape(fileName)
|
||||
|
||||
// 1. Create bucket
|
||||
if !setupBucket(bucketName, true, map[string]interface{}{"enabled": true}, nil, nil, assert, 200) {
|
||||
@@ -1448,7 +1440,7 @@ func TestPutObjectsRetentionStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
// Get versionID
|
||||
listResponse, _ := ListObjects(bucketName, prefix, "true")
|
||||
listResponse, _ := ListObjects(bucketName, prefix, true)
|
||||
bodyBytes, _ := io.ReadAll(listResponse.Body)
|
||||
listObjs := models.ListObjectsResponse{}
|
||||
err := json.Unmarshal(bodyBytes, &listObjs)
|
||||
@@ -1470,14 +1462,7 @@ func TestPutObjectsRetentionStatus(t *testing.T) {
|
||||
name: "Valid VersionID when putting object's retention status",
|
||||
expectedStatus: 200,
|
||||
args: args{
|
||||
versionID: validVersionID,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Invalid VersionID when putting object's retention status",
|
||||
expectedStatus: 500,
|
||||
args: args{
|
||||
versionID: "*&^###Test1ThisMightBeInvalid555",
|
||||
versionID: url.QueryEscape(validVersionID),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1516,7 +1501,7 @@ func TestShareObjectOnURL(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
bucketName := "testshareobjectonurl"
|
||||
fileName := "testshareobjectonurl.txt"
|
||||
validPrefix := encodeBase64(fileName)
|
||||
validPrefix := url.QueryEscape(fileName)
|
||||
tags := make(map[string]string)
|
||||
tags["tag"] = "testputobjecttagbucketonetagone"
|
||||
versionID := "null"
|
||||
@@ -1556,13 +1541,6 @@ func TestShareObjectOnURL(t *testing.T) {
|
||||
prefix: validPrefix,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Share file with invalid prefix",
|
||||
expectedStatus: 500,
|
||||
args: args{
|
||||
prefix: "invalidprefix",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(_ *testing.T) {
|
||||
@@ -1613,7 +1591,7 @@ func TestListObjects(t *testing.T) {
|
||||
}
|
||||
|
||||
// 3. List the object
|
||||
listResponse, listError := ListObjects(bucketName, "", "false")
|
||||
listResponse, listError := ListObjects(bucketName, "", false)
|
||||
assert.Nil(listError)
|
||||
if listError != nil {
|
||||
log.Println(listError)
|
||||
@@ -1676,7 +1654,7 @@ func TestDeleteObject(t *testing.T) {
|
||||
}
|
||||
|
||||
// 4. List the objects in the bucket and make sure the object is gone
|
||||
listResponse, listError := ListObjects(bucketName, "", "false")
|
||||
listResponse, listError := ListObjects(bucketName, "", false)
|
||||
assert.Nil(listError)
|
||||
if listError != nil {
|
||||
log.Println(listError)
|
||||
@@ -1738,7 +1716,7 @@ func TestDownloadObject(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
bucketName := "testdownloadobjbucketone"
|
||||
fileName := "testdownloadobjectfilenameone"
|
||||
path := encodeBase64(fileName)
|
||||
path := url.QueryEscape(fileName)
|
||||
workingDirectory, getWdErr := os.Getwd()
|
||||
if getWdErr != nil {
|
||||
assert.Fail("Couldn't get the directory")
|
||||
@@ -1852,7 +1830,7 @@ func TestDeleteMultipleObjects(t *testing.T) {
|
||||
}
|
||||
|
||||
// 4. List the objects, empty list is expected!
|
||||
listResponse, listError := ListObjects(bucketName, "", "false")
|
||||
listResponse, listError := ListObjects(bucketName, "", false)
|
||||
assert.Nil(listError)
|
||||
if listError != nil {
|
||||
log.Println(listError)
|
||||
@@ -1878,7 +1856,7 @@ func TestPutObjectTag(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
bucketName := "testputobjecttagbucketone"
|
||||
fileName := "testputobjecttagbucketone.txt"
|
||||
path := encodeBase64(fileName)
|
||||
path := url.QueryEscape(fileName)
|
||||
tags := make(map[string]string)
|
||||
tags["tag"] = "testputobjecttagbucketonetagone"
|
||||
versionID := "null"
|
||||
@@ -1918,7 +1896,7 @@ func TestPutObjectTag(t *testing.T) {
|
||||
}
|
||||
|
||||
// 4. Verify the object's tag is set
|
||||
listResponse, listError := ListObjects(bucketName, path, "false")
|
||||
listResponse, listError := ListObjects(bucketName, path, false)
|
||||
assert.Nil(listError)
|
||||
if listError != nil {
|
||||
log.Println(listError)
|
||||
|
||||
@@ -18,12 +18,12 @@ package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -63,7 +63,6 @@ func AddUser(accessKey, secretKey string, groups, policies []string) (*http.Resp
|
||||
}
|
||||
|
||||
func DeleteUser(userName string) (*http.Response, error) {
|
||||
userName = base64.StdEncoding.EncodeToString([]byte(userName))
|
||||
/*
|
||||
This is an atomic function to delete user and can be reused across
|
||||
different functions.
|
||||
@@ -72,7 +71,7 @@ func DeleteUser(userName string) (*http.Response, error) {
|
||||
Timeout: 3 * time.Second,
|
||||
}
|
||||
request, err := http.NewRequest(
|
||||
"DELETE", "http://localhost:9090/api/v1/user/"+userName, nil)
|
||||
"DELETE", "http://localhost:9090/api/v1/user/"+url.PathEscape(userName), nil)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
@@ -104,7 +103,6 @@ func ListUsers(offset, limit string) (*http.Response, error) {
|
||||
}
|
||||
|
||||
func GetUserInformation(userName string) (*http.Response, error) {
|
||||
userName = base64.StdEncoding.EncodeToString([]byte(userName))
|
||||
/*
|
||||
Helper function to get user information via API:
|
||||
{{baseUrl}}/user?name=proident velit
|
||||
@@ -114,7 +112,7 @@ func GetUserInformation(userName string) (*http.Response, error) {
|
||||
}
|
||||
request, err := http.NewRequest(
|
||||
"GET",
|
||||
"http://localhost:9090/api/v1/user/"+userName,
|
||||
"http://localhost:9090/api/v1/user/"+url.PathEscape(userName),
|
||||
nil)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
@@ -126,7 +124,6 @@ func GetUserInformation(userName string) (*http.Response, error) {
|
||||
}
|
||||
|
||||
func UpdateUserInformation(name, status string, groups []string) (*http.Response, error) {
|
||||
name = base64.StdEncoding.EncodeToString([]byte(name))
|
||||
/*
|
||||
Helper function to update user information:
|
||||
PUT: {{baseUrl}}/user?name=proident velit
|
||||
@@ -149,7 +146,7 @@ func UpdateUserInformation(name, status string, groups []string) (*http.Response
|
||||
requestDataJSON, _ := json.Marshal(requestDataAdd)
|
||||
requestDataBody := bytes.NewReader(requestDataJSON)
|
||||
request, err := http.NewRequest(
|
||||
"PUT", "http://localhost:9090/api/v1/user/"+name, requestDataBody)
|
||||
"PUT", "http://localhost:9090/api/v1/user/"+url.PathEscape(name), requestDataBody)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
@@ -160,7 +157,6 @@ func UpdateUserInformation(name, status string, groups []string) (*http.Response
|
||||
}
|
||||
|
||||
func RemoveUser(name string) (*http.Response, error) {
|
||||
name = base64.StdEncoding.EncodeToString([]byte(name))
|
||||
/*
|
||||
Helper function to remove user.
|
||||
DELETE: {{baseUrl}}/user?name=proident velit
|
||||
@@ -169,7 +165,7 @@ func RemoveUser(name string) (*http.Response, error) {
|
||||
Timeout: 3 * time.Second,
|
||||
}
|
||||
request, err := http.NewRequest(
|
||||
"DELETE", "http://localhost:9090/api/v1/user/"+name, nil)
|
||||
"DELETE", "http://localhost:9090/api/v1/user/"+url.PathEscape(name), nil)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
@@ -180,7 +176,6 @@ func RemoveUser(name string) (*http.Response, error) {
|
||||
}
|
||||
|
||||
func UpdateGroupsForAUser(userName string, groups []string) (*http.Response, error) {
|
||||
userName = base64.StdEncoding.EncodeToString([]byte(userName))
|
||||
/*
|
||||
Helper function to update groups for a user
|
||||
PUT: {{baseUrl}}/user/groups?name=username
|
||||
@@ -201,7 +196,7 @@ func UpdateGroupsForAUser(userName string, groups []string) (*http.Response, err
|
||||
requestDataBody := bytes.NewReader(requestDataJSON)
|
||||
request, err := http.NewRequest(
|
||||
"PUT",
|
||||
"http://localhost:9090/api/v1/user/"+userName+"/groups",
|
||||
"http://localhost:9090/api/v1/user/"+url.PathEscape(userName)+"/groups",
|
||||
requestDataBody,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -214,7 +209,6 @@ func UpdateGroupsForAUser(userName string, groups []string) (*http.Response, err
|
||||
}
|
||||
|
||||
func CreateServiceAccountForUser(userName, policy string) (*http.Response, error) {
|
||||
userName = base64.StdEncoding.EncodeToString([]byte(userName))
|
||||
/*
|
||||
Helper function to Create Service Account for user
|
||||
POST: api/v1/user/username/service-accounts
|
||||
@@ -232,7 +226,7 @@ func CreateServiceAccountForUser(userName, policy string) (*http.Response, error
|
||||
requestDataBody := bytes.NewReader(requestDataJSON)
|
||||
request, err := http.NewRequest(
|
||||
"POST",
|
||||
"http://localhost:9090/api/v1/user/"+userName+"/service-accounts",
|
||||
"http://localhost:9090/api/v1/user/"+url.PathEscape(userName)+"/service-accounts",
|
||||
requestDataBody,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -245,7 +239,6 @@ func CreateServiceAccountForUser(userName, policy string) (*http.Response, error
|
||||
}
|
||||
|
||||
func CreateServiceAccountForUserWithCredentials(userName, policy, accessKey, secretKey string) (*http.Response, error) {
|
||||
userName = base64.StdEncoding.EncodeToString([]byte(userName))
|
||||
// Helper function to test "Create Service Account for User With Credentials" end point.
|
||||
client := &http.Client{
|
||||
Timeout: 3 * time.Second,
|
||||
@@ -259,7 +252,7 @@ func CreateServiceAccountForUserWithCredentials(userName, policy, accessKey, sec
|
||||
requestDataBody := bytes.NewReader(requestDataJSON)
|
||||
request, err := http.NewRequest(
|
||||
"POST",
|
||||
"http://localhost:9090/api/v1/user/"+userName+"/service-account-credentials",
|
||||
"http://localhost:9090/api/v1/user/"+url.PathEscape(userName)+"/service-account-credentials",
|
||||
requestDataBody,
|
||||
)
|
||||
if err != nil {
|
||||
@@ -272,7 +265,6 @@ func CreateServiceAccountForUserWithCredentials(userName, policy, accessKey, sec
|
||||
}
|
||||
|
||||
func ReturnsAListOfServiceAccountsForAUser(userName string) (*http.Response, error) {
|
||||
userName = base64.StdEncoding.EncodeToString([]byte(userName))
|
||||
/*
|
||||
Helper function to return a list of service accounts for a user.
|
||||
GET: {{baseUrl}}/user/:name/service-accounts
|
||||
@@ -282,7 +274,7 @@ func ReturnsAListOfServiceAccountsForAUser(userName string) (*http.Response, err
|
||||
}
|
||||
request, err := http.NewRequest(
|
||||
"GET",
|
||||
"http://localhost:9090/api/v1/user/"+userName+"/service-accounts",
|
||||
"http://localhost:9090/api/v1/user/"+url.PathEscape(userName)+"/service-accounts",
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user