forked from TrueCloudLab/frostfs-http-gw
[#174] Add slash clipping for FileName attribute
According to the FrostFS API specification, the FileName attribute cannot contain a slash at the beginning. Signed-off-by: Roman Loginov <r.loginov@yadro.com>
This commit is contained in:
parent
20319418cc
commit
47d74a5a77
3 changed files with 44 additions and 3 deletions
|
@ -239,6 +239,10 @@ func TestBasic(t *testing.T) {
|
|||
r = prepareGetByAttributeRequest(ctx, bktName, keyAttr, valAttr)
|
||||
hc.Handler().DownloadByAttribute(r)
|
||||
require.Equal(t, content, string(r.Response.Body()))
|
||||
|
||||
r = prepareGetByAttributeRequest(ctx, bktName, attrFileName, "/"+objFileName)
|
||||
hc.Handler().DownloadByAttribute(r)
|
||||
require.Equal(t, content, string(r.Response.Body()))
|
||||
})
|
||||
|
||||
t.Run("head by attribute", func(t *testing.T) {
|
||||
|
@ -246,6 +250,11 @@ func TestBasic(t *testing.T) {
|
|||
hc.Handler().HeadByAttribute(r)
|
||||
require.Equal(t, putRes.ObjectID, string(r.Response.Header.Peek(hdrObjectID)))
|
||||
require.Equal(t, putRes.ContainerID, string(r.Response.Header.Peek(hdrContainerID)))
|
||||
|
||||
r = prepareGetByAttributeRequest(ctx, bktName, attrFileName, "/"+objFileName)
|
||||
hc.Handler().HeadByAttribute(r)
|
||||
require.Equal(t, putRes.ObjectID, string(r.Response.Header.Peek(hdrObjectID)))
|
||||
require.Equal(t, putRes.ContainerID, string(r.Response.Header.Peek(hdrContainerID)))
|
||||
})
|
||||
|
||||
t.Run("zip", func(t *testing.T) {
|
||||
|
@ -293,8 +302,8 @@ func TestFindObjectByAttribute(t *testing.T) {
|
|||
err = json.Unmarshal(r.Response.Body(), &putRes)
|
||||
require.NoError(t, err)
|
||||
|
||||
testAttrVal1 := "test-attr-val1"
|
||||
testAttrVal2 := "test-attr-val2"
|
||||
testAttrVal1 := "/folder/cat.jpg"
|
||||
testAttrVal2 := "cat.jpg"
|
||||
testAttrVal3 := "test-attr-val3"
|
||||
|
||||
for _, tc := range []struct {
|
||||
|
@ -340,6 +349,14 @@ func TestFindObjectByAttribute(t *testing.T) {
|
|||
err: "not found",
|
||||
additionalSearch: true,
|
||||
},
|
||||
{
|
||||
name: "success search by FilePath with leading slash (with additional search)",
|
||||
firstAttr: prepareObjectAttributes(attrFilePath, testAttrVal1),
|
||||
secondAttr: prepareObjectAttributes(attrFileName, testAttrVal2),
|
||||
reqAttrKey: attrFilePath,
|
||||
reqAttrValue: "/cat.jpg",
|
||||
additionalSearch: true,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
obj := hc.frostfs.objects[putRes.ContainerID+"/"+putRes.ObjectID]
|
||||
|
@ -422,6 +439,17 @@ func TestNeedSearchByFileName(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPrepareFileName(t *testing.T) {
|
||||
fileName := "/cat.jpg"
|
||||
expected := "cat.jpg"
|
||||
actual := prepareFileName(fileName)
|
||||
require.Equal(t, expected, actual)
|
||||
|
||||
fileName = "cat.jpg"
|
||||
actual = prepareFileName(fileName)
|
||||
require.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
func prepareUploadRequest(ctx context.Context, bucket, content string) (*fasthttp.RequestCtx, error) {
|
||||
r := new(fasthttp.RequestCtx)
|
||||
utils.SetContextToRequest(ctx, r)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue