Compare commits

..

2 commits

Author SHA1 Message Date
82c40412c7 [#135] Add fuzzing tests for handlers
Signed-off-by: Roman Ognev <r.ognev@yadro.com>
2024-09-02 15:08:09 +03:00
151e5bc1c8 [#132] Update Go version
Signed-off-by: Nikita Zinkevich <n.zinkevich@yadro.com>
2024-08-29 10:42:20 +03:00
11 changed files with 63 additions and 64 deletions

View file

@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go_versions: [ '1.21', '1.22' ]
go_versions: [ '1.22', '1.23' ]
fail-fast: false
steps:
- uses: actions/checkout@v3

View file

@ -12,7 +12,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.21'
go-version: '1.23'
- name: Run commit format checker
uses: https://git.frostfs.info/TrueCloudLab/dco-go@v3

View file

@ -10,7 +10,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.22'
go-version: '1.23'
cache: true
- name: Install linters
@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go_versions: [ '1.21', '1.22' ]
go_versions: [ '1.22', '1.23' ]
fail-fast: false
steps:
- uses: actions/checkout@v3
@ -38,4 +38,4 @@ jobs:
run: make dep
- name: Run tests
run: make test
run: make test

View file

@ -12,7 +12,8 @@ run:
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: tab
formats:
- format: tab
# all available settings of specific linters
linters-settings:

View file

@ -30,11 +30,6 @@ repos:
hooks:
- id: shellcheck
- repo: https://github.com/golangci/golangci-lint
rev: v1.51.2
hooks:
- id: golangci-lint
- repo: local
hooks:
- id: make-lint-install

View file

@ -4,6 +4,9 @@ This document outlines major changes between releases.
## [Unreleased]
### Changed
- Update go version to 1.22 (#132)
## [0.30.0] - Kangshung - 2024-07-22
### Fixed

View file

@ -3,8 +3,8 @@
REPO ?= $(shell go list -m)
VERSION ?= $(shell git describe --tags --match "v*" --dirty --always --abbrev=8 2>/dev/null || cat VERSION 2>/dev/null || echo "develop")
GO_VERSION ?= 1.22
LINT_VERSION ?= 1.54.0
TRUECLOUDLAB_LINT_VERSION ?= 0.0.2
LINT_VERSION ?= 1.60.3
TRUECLOUDLAB_LINT_VERSION ?= 0.0.6
BUILD ?= $(shell date -u --iso=seconds)
HUB_IMAGE ?= truecloudlab/frostfs-http-gw

2
go.mod
View file

@ -1,6 +1,6 @@
module git.frostfs.info/TrueCloudLab/frostfs-http-gw
go 1.21
go 1.22
require (
git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20240716113920-f517e3949164

View file

@ -7,7 +7,7 @@ import (
"bytes"
"context"
"encoding/json"
syserrors "errors"
"errors"
"io"
"mime/multipart"
"net/http"
@ -24,8 +24,8 @@ import (
)
const (
fuzzSuccessExitCode = 1
fuzzFailExitCode = 0
fuzzSuccessExitCode = 0
fuzzFailExitCode = -1
)
func prepareStrings(tp *go_fuzz_utils.TypeProvider, count int) ([]string, error) {
@ -110,24 +110,24 @@ func generateHeaders(tp *go_fuzz_utils.TypeProvider, r *fasthttp.Request, params
return nil
}
func maybeFillRandom(tp *go_fuzz_utils.TypeProvider, initValue string) (error, string) {
func maybeFillRandom(tp *go_fuzz_utils.TypeProvider, initValue string) (string, error) {
rnd, err := tp.GetBool()
if err != nil {
return err, ""
return "", err
}
if rnd == true {
initValue, err = tp.GetString()
if err != nil {
return err, ""
return "", err
}
}
return nil, initValue
return initValue, nil
}
func upload(tp *go_fuzz_utils.TypeProvider) (error, context.Context, *handlerContext, cid.ID, *fasthttp.RequestCtx, string, string, string) {
func upload(tp *go_fuzz_utils.TypeProvider) (context.Context, *handlerContext, cid.ID, *fasthttp.RequestCtx, string, string, string, error) {
hc, err := prepareHandlerContext()
if err != nil {
return err, nil, nil, cid.ID{}, nil, "", "", ""
return nil, nil, cid.ID{}, nil, "", "", "", err
}
aclList := []acl.Basic{
@ -143,13 +143,13 @@ func upload(tp *go_fuzz_utils.TypeProvider) (error, context.Context, *handlerCon
pos, err := getRandomDeterministicPositiveIntInRange(tp, len(aclList))
if err != nil {
return err, nil, nil, cid.ID{}, nil, "", "", ""
return nil, nil, cid.ID{}, nil, "", "", "", err
}
acl := aclList[pos]
strings, err := prepareStrings(tp, 6)
if err != nil {
return err, nil, nil, cid.ID{}, nil, "", "", ""
return nil, nil, cid.ID{}, nil, "", "", "", err
}
bktName := strings[0]
objFileName := strings[1]
@ -157,12 +157,12 @@ func upload(tp *go_fuzz_utils.TypeProvider) (error, context.Context, *handlerCon
keyAttr := strings[3]
if len(bktName) == 0 {
return syserrors.New("not enought buckets"), nil, nil, cid.ID{}, nil, "", "", ""
return nil, nil, cid.ID{}, nil, "", "", "", errors.New("not enought buckets")
}
cnrID, cnr, err := hc.prepareContainer(bktName, acl)
if err != nil {
return err, nil, nil, cid.ID{}, nil, "", "", ""
return nil, nil, cid.ID{}, nil, "", "", "", err
}
hc.frostfs.SetContainer(cnrID, cnr)
@ -183,20 +183,20 @@ func upload(tp *go_fuzz_utils.TypeProvider) (error, context.Context, *handlerCon
w := multipart.NewWriter(&buff)
fw, err := w.CreateFormFile("file", attributes[object.AttributeFileName])
if err != nil {
return err, nil, nil, cid.ID{}, nil, "", "", ""
return nil, nil, cid.ID{}, nil, "", "", "", err
}
content, err := tp.GetBytes()
if err != nil {
return err, nil, nil, cid.ID{}, nil, "", "", ""
return nil, nil, cid.ID{}, nil, "", "", "", err
}
if _, err = io.Copy(fw, bytes.NewReader(content)); err != nil {
return err, nil, nil, cid.ID{}, nil, "", "", ""
return nil, nil, cid.ID{}, nil, "", "", "", err
}
if err = w.Close(); err != nil {
return err, nil, nil, cid.ID{}, nil, "", "", ""
return nil, nil, cid.ID{}, nil, "", "", "", err
}
r.Request.SetBodyStream(&buff, buff.Len())
@ -205,16 +205,16 @@ func upload(tp *go_fuzz_utils.TypeProvider) (error, context.Context, *handlerCon
err = generateHeaders(tp, &r.Request, []string{"X-Attribute-", "X-Attribute-DupKey", "X-Attribute-MyAttribute", "X-Attribute-System-DupKey", "X-Attribute-System-Expiration-Epoch1", "X-Attribute-SYSTEM-Expiration-Epoch2", "X-Attribute-system-Expiration-Epoch3", "X-Attribute-User-Attribute", "X-Attribute-", "X-Attribute-FileName", "X-Attribute-FROSTFS", "X-Attribute-neofs", "X-Attribute-SYSTEM", "X-Attribute-System-Expiration-Duration", "X-Attribute-System-Expiration-Epoch", "X-Attribute-System-Expiration-RFC3339", "X-Attribute-System-Expiration-Timestamp", "X-Attribute-Timestamp", "X-Attribute-" + strings[4], "X-Attribute-System-" + strings[5]})
if err != nil {
return err, nil, nil, cid.ID{}, nil, "", "", ""
return nil, nil, cid.ID{}, nil, "", "", "", err
}
hc.Handler().Upload(r)
if r.Response.StatusCode() != http.StatusOK {
return syserrors.New("error on upload"), nil, nil, cid.ID{}, nil, "", "", ""
return nil, nil, cid.ID{}, nil, "", "", "", errors.New("error on upload")
}
return nil, ctx, hc, cnrID, r, objFileName, keyAttr, valAttr
return ctx, hc, cnrID, r, objFileName, keyAttr, valAttr, nil
}
func InitFuzzUpload() {
@ -232,7 +232,7 @@ func DoFuzzUpload(input []byte) int {
return fuzzFailExitCode
}
err, _, _, _, _, _, _, _ = upload(tp)
_, _, _, _, _, _, _, err = upload(tp)
if err != nil {
return fuzzFailExitCode
}
@ -246,7 +246,7 @@ func FuzzUpload(f *testing.F) {
})
}
func downloadOrHead(tp *go_fuzz_utils.TypeProvider, ctx context.Context, hc *handlerContext, cnrID cid.ID, resp *fasthttp.RequestCtx, filename string) (error, *fasthttp.RequestCtx) {
func downloadOrHead(tp *go_fuzz_utils.TypeProvider, ctx context.Context, hc *handlerContext, cnrID cid.ID, resp *fasthttp.RequestCtx, filename string) (*fasthttp.RequestCtx, error) {
var putRes putResponse
@ -260,16 +260,16 @@ func downloadOrHead(tp *go_fuzz_utils.TypeProvider, ctx context.Context, hc *han
err := json.Unmarshal(data, &putRes)
if err != nil {
return err, nil
return nil, err
}
obj := hc.frostfs.objects[putRes.ContainerID+"/"+putRes.ObjectID]
attr := object.NewAttribute()
attr.SetKey(object.AttributeFilePath)
err, filename = maybeFillRandom(tp, filename)
filename, err = maybeFillRandom(tp, filename)
if err != nil {
return err, nil
return nil, err
}
attr.SetValue(filename)
@ -279,27 +279,27 @@ func downloadOrHead(tp *go_fuzz_utils.TypeProvider, ctx context.Context, hc *han
utils.SetContextToRequest(ctx, r)
cid := cnrID.EncodeToString()
err, cid = maybeFillRandom(tp, cid)
cid, err = maybeFillRandom(tp, cid)
if err != nil {
return err, nil
return nil, err
}
oid := putRes.ObjectID
err, oid = maybeFillRandom(tp, oid)
oid, err = maybeFillRandom(tp, oid)
if err != nil {
return err, nil
return nil, err
}
r.SetUserValue("cid", cid)
r.SetUserValue("oid", oid)
rnd, err := tp.GetBool()
if err != nil {
return err, nil
return nil, err
}
if rnd == true {
r.SetUserValue("download", "true")
}
return nil, r
return r, nil
}
func InitFuzzGet() {
@ -316,12 +316,12 @@ func DoFuzzGet(input []byte) int {
return fuzzFailExitCode
}
err, ctx, hc, cnrID, resp, filename, _, _ := upload(tp)
ctx, hc, cnrID, resp, filename, _, _, err := upload(tp)
if err != nil {
return fuzzFailExitCode
}
err, r := downloadOrHead(tp, ctx, hc, cnrID, resp, filename)
r, err := downloadOrHead(tp, ctx, hc, cnrID, resp, filename)
if err != nil {
return fuzzFailExitCode
}
@ -351,12 +351,12 @@ func DoFuzzHead(input []byte) int {
return fuzzFailExitCode
}
err, ctx, hc, cnrID, resp, filename, _, _ := upload(tp)
ctx, hc, cnrID, resp, filename, _, _, err := upload(tp)
if err != nil {
return fuzzFailExitCode
}
err, r := downloadOrHead(tp, ctx, hc, cnrID, resp, filename)
r, err := downloadOrHead(tp, ctx, hc, cnrID, resp, filename)
if err != nil {
return fuzzFailExitCode
}
@ -386,23 +386,23 @@ func DoFuzzDownloadByAttribute(input []byte) int {
return fuzzFailExitCode
}
err, ctx, hc, cnrID, _, _, attrKey, attrVal := upload(tp)
ctx, hc, cnrID, _, _, attrKey, attrVal, err := upload(tp)
if err != nil {
return fuzzFailExitCode
}
cid := cnrID.EncodeToString()
err, cid = maybeFillRandom(tp, cid)
cid, err = maybeFillRandom(tp, cid)
if err != nil {
return fuzzFailExitCode
}
err, attrKey = maybeFillRandom(tp, attrKey)
attrKey, err = maybeFillRandom(tp, attrKey)
if err != nil {
return fuzzFailExitCode
}
err, attrVal = maybeFillRandom(tp, attrVal)
attrVal, err = maybeFillRandom(tp, attrVal)
if err != nil {
return fuzzFailExitCode
}
@ -438,23 +438,23 @@ func DoFuzzHeadByAttribute(input []byte) int {
return fuzzFailExitCode
}
err, ctx, hc, cnrID, _, _, attrKey, attrVal := upload(tp)
ctx, hc, cnrID, _, _, attrKey, attrVal, err := upload(tp)
if err != nil {
return fuzzFailExitCode
}
cid := cnrID.EncodeToString()
err, cid = maybeFillRandom(tp, cid)
cid, err = maybeFillRandom(tp, cid)
if err != nil {
return fuzzFailExitCode
}
err, attrKey = maybeFillRandom(tp, attrKey)
attrKey, err = maybeFillRandom(tp, attrKey)
if err != nil {
return fuzzFailExitCode
}
err, attrVal = maybeFillRandom(tp, attrVal)
attrVal, err = maybeFillRandom(tp, attrVal)
if err != nil {
return fuzzFailExitCode
}
@ -490,19 +490,19 @@ func DoFuzzDownloadZipped(input []byte) int {
return fuzzFailExitCode
}
err, ctx, hc, cnrID, _, _, _, _ := upload(tp)
ctx, hc, cnrID, _, _, _, _, err := upload(tp)
if err != nil {
return fuzzFailExitCode
}
cid := cnrID.EncodeToString()
err, cid = maybeFillRandom(tp, cid)
cid, err = maybeFillRandom(tp, cid)
if err != nil {
return fuzzFailExitCode
}
prefix := ""
err, prefix = maybeFillRandom(tp, prefix)
prefix, err = maybeFillRandom(tp, prefix)
if err != nil {
return fuzzFailExitCode
}
@ -538,7 +538,7 @@ func DoFuzzStoreBearerTokenAppCtx(input []byte) int {
}
prefix := ""
err, prefix = maybeFillRandom(tp, prefix)
prefix, err = maybeFillRandom(tp, prefix)
if err != nil {
return fuzzFailExitCode
}

View file

@ -35,7 +35,7 @@ func TestDetector(t *testing.T) {
} {
t.Run(tc.Name, func(t *testing.T) {
contentType, data, err := readContentType(uint64(len(tc.Expected)),
func(sz uint64) (io.Reader, error) {
func(uint64) (io.Reader, error) {
return strings.NewReader(tc.Expected), nil
},
)

View file

@ -30,12 +30,12 @@ func (c *httpCarrier) Set(key string, value string) {
func (c *httpCarrier) Keys() []string {
dict := make(map[string]interface{})
c.r.Request.Header.VisitAll(
func(key, value []byte) {
func(key, _ []byte) {
dict[string(key)] = true
},
)
c.r.Response.Header.VisitAll(
func(key, value []byte) {
func(key, _ []byte) {
dict[string(key)] = true
},
)