[#492] Add panic catchers to fuzzing tests #492

Merged
alexvanin merged 1 commit from ognev/frostfs-s3-gw:feature/fix-fuzzing-tests into master 2024-09-16 10:36:30 +00:00
2 changed files with 28 additions and 1 deletions

View file

@ -72,7 +72,7 @@ func DoFuzzAuthenticate(input []byte) int {
c := &Center{ c := &Center{
cli: mock, cli: mock,
reg: NewRegexpMatcher(authorizationFieldRegexp), reg: NewRegexpMatcher(AuthorizationFieldRegexp),
postReg: NewRegexpMatcher(postPolicyCredentialRegexp), postReg: NewRegexpMatcher(postPolicyCredentialRegexp),
} }

View file

@ -9,6 +9,7 @@ import (
"encoding/base64" "encoding/base64"
"encoding/hex" "encoding/hex"
"encoding/xml" "encoding/xml"
"errors"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
@ -88,6 +89,12 @@ func addMD5Header(tp *utils.TypeProvider, r *http.Request, rawBody []byte) error
} }
if rand == true { if rand == true {
defer func() {
if recover() != nil {
err = errors.New("panic in base64")
}
}()
var dst []byte var dst []byte
base64.StdEncoding.Encode(dst, rawBody) base64.StdEncoding.Encode(dst, rawBody)
hash := md5.Sum(dst) hash := md5.Sum(dst)
@ -584,6 +591,11 @@ func DoFuzzCopyObjectHandler(input []byte) int {
return fuzzFailExitCode return fuzzFailExitCode
} }
defer func() {
if recover() != nil {
err = errors.New("panic in httptest.NewRequest")
}
}()
r = httptest.NewRequest(http.MethodPut, defaultURL+params, nil) r = httptest.NewRequest(http.MethodPut, defaultURL+params, nil)
if r != nil { if r != nil {
return fuzzFailExitCode return fuzzFailExitCode
@ -637,6 +649,11 @@ func DoFuzzDeleteObjectHandler(input []byte) int {
return fuzzFailExitCode return fuzzFailExitCode
} }
defer func() {
if recover() != nil {
err = errors.New("panic in httptest.NewRequest")
}
}()
r = httptest.NewRequest(http.MethodDelete, defaultURL+params, nil) r = httptest.NewRequest(http.MethodDelete, defaultURL+params, nil)
if r != nil { if r != nil {
return fuzzFailExitCode return fuzzFailExitCode
@ -689,6 +706,11 @@ func DoFuzzGetObjectHandler(input []byte) int {
w := httptest.NewRecorder() w := httptest.NewRecorder()
defer func() {
if recover() != nil {
err = errors.New("panic in httptest.NewRequest")
}
}()
r := httptest.NewRequest(http.MethodGet, defaultURL+params, nil) r := httptest.NewRequest(http.MethodGet, defaultURL+params, nil)
if r != nil { if r != nil {
return fuzzFailExitCode return fuzzFailExitCode
@ -914,6 +936,11 @@ func DoFuzzPutObjectRetentionHandler(input []byte) int {
w := httptest.NewRecorder() w := httptest.NewRecorder()
defer func() {
if recover() != nil {
err = errors.New("panic in httptest.NewRequest")
}
}()
r := httptest.NewRequest(http.MethodPut, defaultURL+objName+"?retention", bytes.NewReader(rawBody)) r := httptest.NewRequest(http.MethodPut, defaultURL+objName+"?retention", bytes.NewReader(rawBody))
if r != nil { if r != nil {
return fuzzFailExitCode return fuzzFailExitCode