1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 18:15:42 +01:00

Stop checker run of a domain after an error occurrs making a continuation pointless.

Fixes issue #24.

TODO: Improve handling of checks that are not run due to the stop.
They currently report success which is not correct.
This commit is contained in:
Sascha L. Teichmann 2022-01-12 12:32:07 +01:00
parent 2a69c13398
commit 09de416a4a

View file

@ -64,7 +64,12 @@ type reporter interface {
report(*processor, *Domain) report(*processor, *Domain)
} }
var errContinue = errors.New("continue") var (
// errContinue indicates that the current check should continue.
errContinue = errors.New("continue")
// errStop indicates that the current check should stop.
errStop = errors.New("stop")
)
type whereType byte type whereType byte
@ -140,7 +145,7 @@ func (p *processor) run(reporters []reporter, domains []string) (*Report, error)
domainsLoop: domainsLoop:
for _, d := range domains { for _, d := range domains {
if err := p.checkDomain(d); err != nil { if err := p.checkDomain(d); err != nil {
if err == errContinue { if err == errContinue || err == errStop {
continue domainsLoop continue domainsLoop
} }
return nil, err return nil, err
@ -167,6 +172,9 @@ func (p *processor) checkDomain(domain string) error {
(*processor).checkMissing, (*processor).checkMissing,
} { } {
if err := check(p, domain); err != nil && err != errContinue { if err := check(p, domain); err != nil && err != errContinue {
if err == errStop {
return nil
}
return err return err
} }
} }
@ -682,13 +690,13 @@ func (p *processor) checkProviderMetadata(domain string) error {
res, err := client.Get(url) res, err := client.Get(url)
if err != nil { if err != nil {
p.badProviderMetadata("Fetching %s: %v.", url, err) p.badProviderMetadata("Fetching %s: %v.", url, err)
return errContinue return errStop
} }
if res.StatusCode != http.StatusOK { if res.StatusCode != http.StatusOK {
p.badProviderMetadata("Fetching %s failed. Status code: %d (%s)", p.badProviderMetadata("Fetching %s failed. Status code: %d (%s)",
url, res.StatusCode, res.Status) url, res.StatusCode, res.Status)
return errContinue return errStop
} }
// Calculate checksum for later comparison. // Calculate checksum for later comparison.
@ -700,7 +708,7 @@ func (p *processor) checkProviderMetadata(domain string) error {
return json.NewDecoder(tee).Decode(&p.pmd) return json.NewDecoder(tee).Decode(&p.pmd)
}(); err != nil { }(); err != nil {
p.badProviderMetadata("Decoding JSON failed: %v", err) p.badProviderMetadata("Decoding JSON failed: %v", err)
return errContinue return errStop
} }
p.pmd256 = hash.Sum(nil) p.pmd256 = hash.Sum(nil)