1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 11:55:40 +01:00

Extend processor SHA fetching tests

Allow to forbid individual hashes from downloading. This allows to for
testing the behavior, if one of the hashes could not be downloaded.
This commit is contained in:
koplas 2024-12-16 12:23:10 +01:00
parent 9dd4b7fc8d
commit b1a7620763
No known key found for this signature in database
3 changed files with 68 additions and 65 deletions

View file

@ -18,10 +18,11 @@ import (
// ProviderParams configures the test provider.
type ProviderParams struct {
URL string
EnableSha256 bool
EnableSha512 bool
ForbidHashFetching bool
URL string
EnableSha256 bool
EnableSha512 bool
ForbidSha256 bool
ForbidSha512 bool
}
// ProviderHandler returns a test provider handler with the specified configuration.
@ -50,7 +51,10 @@ func ProviderHandler(params *ProviderParams, directoryProvider bool) http.Handle
w.Header().Add("Content-Type", "text/html")
case strings.HasSuffix(path, ".json"):
w.Header().Add("Content-Type", "application/json")
case (strings.HasSuffix(path, ".sha256") || strings.HasSuffix(path, ".sha512")) && params.ForbidHashFetching:
case (strings.HasSuffix(path, ".sha256")) && params.ForbidSha256:
w.WriteHeader(http.StatusForbidden)
return
case strings.HasSuffix(path, ".sha512") && params.ForbidSha512:
w.WriteHeader(http.StatusForbidden)
return
case strings.HasSuffix(path, ".sha256") && directoryProvider && !params.EnableSha256: