From 141fbe21cadedfecd02c9c779967892f2aa63192 Mon Sep 17 00:00:00 2001 From: JanHoefelmeyer <107021473+JanHoefelmeyer@users.noreply.github.com> Date: Mon, 1 Aug 2022 13:17:35 +0200 Subject: [PATCH] Find missing (#269) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Solves #160 * Implements check on whether index.txt/changes.csv and directory listings exist. Also fixes minor grammatical mistakes * Adds missing else to prevent defaulting to missing-error handling even if another error was found * Removes comment * test whether changes.csv or index.txt is empty * Fixed type mismatching, undeclared variable * Fixes typo in variable * Fixes another typo in variable * Fixes formatting error * Removed reminder comments * Fixes formatting errors * Added check for missing directories * Moved empty dirlistcheck to the right position * fixes typo * fixes typo * Add info if files are found * Cleans up code * simplified check for empty changes.csv and index.txt Co-authored-by: Jan Höfelmeyer Co-authored-by: Sascha L. Teichmann --- cmd/csaf_checker/processor.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/cmd/csaf_checker/processor.go b/cmd/csaf_checker/processor.go index e7acf35..7840c1b 100644 --- a/cmd/csaf_checker/processor.go +++ b/cmd/csaf_checker/processor.go @@ -586,6 +586,7 @@ func (p *processor) integrity( func (p *processor) processROLIEFeed(feed string) error { client := p.httpClient() res, err := client.Get(feed) + p.badDirListings.use() if err != nil { p.badProviderMetadata.error("Cannot fetch feed %s: %v", feed, err) return errContinue @@ -700,7 +701,6 @@ func (p *processor) processROLIEFeed(feed string) error { files = append(files, file) }) - if err := p.integrity(files, base, rolieMask, p.badProviderMetadata.add); err != nil && err != errContinue { return err @@ -744,9 +744,12 @@ func (p *processor) checkIndex(base string, mask whereType) error { if res.StatusCode != http.StatusNotFound { p.badIndices.error("Fetching %s failed. Status code %d (%s)", index, res.StatusCode, res.Status) + } else { + p.badIndices.warn("Fetching index.txt failed: %v not found.", index) } return errContinue } + p.badIndices.info("Found %v", index) files, err := func() ([]csaf.AdvisoryFile, error) { defer res.Body.Close() @@ -766,6 +769,9 @@ func (p *processor) checkIndex(base string, mask whereType) error { p.badIndices.error("Reading %s failed: %v", index, err) return errContinue } + if len(files) == 0 { + p.badIntegrities.warn("index.txt contains no URLs") + } return p.integrity(files, base, mask, p.badIndices.add) } @@ -798,9 +804,12 @@ func (p *processor) checkChanges(base string, mask whereType) error { // It's optional p.badChanges.error("Fetching %s failed. Status code %d (%s)", changes, res.StatusCode, res.Status) + } else { + p.badChanges.warn("Fetching changes.csv failed: %v not found.", changes) } return errContinue } + p.badChanges.info("Found %v", changes) times, files, err := func() ([]time.Time, []csaf.AdvisoryFile, error) { defer res.Body.Close() @@ -841,6 +850,14 @@ func (p *processor) checkChanges(base string, mask whereType) error { return errContinue } + if len(files) == 0 { + var filtered string + if p.ageAccept != nil { + filtered = " (maybe filtered out by time interval)" + } + p.badChanges.warn("no entries in changes.csv found" + filtered) + } + if !sort.SliceIsSorted(times, func(i, j int) bool { return times[j].Before(times[i]) }) { @@ -953,7 +970,7 @@ func (p *processor) checkMissing(string) error { return nil } -// checkInvalid wents over all found adivisories URLs and checks +// checkInvalid goes over all found adivisories URLs and checks // if file name confirms to standard. func (p *processor) checkInvalid(string) error { @@ -975,7 +992,7 @@ func (p *processor) checkInvalid(string) error { return nil } -// checkListing wents over all found adivisories URLs and checks +// checkListing goes over all found adivisories URLs and checks // if their parent directory is listable. func (p *processor) checkListing(string) error { @@ -987,6 +1004,10 @@ func (p *processor) checkListing(string) error { badDirs := map[string]struct{}{} + if len(p.alreadyChecked) == 0 { + p.badDirListings.info("No directory listings found.") + } + for f := range p.alreadyChecked { found, err := pgs.listed(f, p, badDirs) if err != nil && err != errContinue {