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

Find missing (#269)

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 <Jan Höfelmeyer jhoefelmeyer@intevation.de>
Co-authored-by: Sascha L. Teichmann <sascha.teichmann@intevation.de>
This commit is contained in:
JanHoefelmeyer 2022-08-01 13:17:35 +02:00 committed by GitHub
parent 4c0785c060
commit 141fbe21ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -586,6 +586,7 @@ func (p *processor) integrity(
func (p *processor) processROLIEFeed(feed string) error { func (p *processor) processROLIEFeed(feed string) error {
client := p.httpClient() client := p.httpClient()
res, err := client.Get(feed) res, err := client.Get(feed)
p.badDirListings.use()
if err != nil { if err != nil {
p.badProviderMetadata.error("Cannot fetch feed %s: %v", feed, err) p.badProviderMetadata.error("Cannot fetch feed %s: %v", feed, err)
return errContinue return errContinue
@ -700,7 +701,6 @@ func (p *processor) processROLIEFeed(feed string) error {
files = append(files, file) files = append(files, file)
}) })
if err := p.integrity(files, base, rolieMask, p.badProviderMetadata.add); err != nil && if err := p.integrity(files, base, rolieMask, p.badProviderMetadata.add); err != nil &&
err != errContinue { err != errContinue {
return err return err
@ -744,9 +744,12 @@ func (p *processor) checkIndex(base string, mask whereType) error {
if res.StatusCode != http.StatusNotFound { if res.StatusCode != http.StatusNotFound {
p.badIndices.error("Fetching %s failed. Status code %d (%s)", p.badIndices.error("Fetching %s failed. Status code %d (%s)",
index, res.StatusCode, res.Status) index, res.StatusCode, res.Status)
} else {
p.badIndices.warn("Fetching index.txt failed: %v not found.", index)
} }
return errContinue return errContinue
} }
p.badIndices.info("Found %v", index)
files, err := func() ([]csaf.AdvisoryFile, error) { files, err := func() ([]csaf.AdvisoryFile, error) {
defer res.Body.Close() 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) p.badIndices.error("Reading %s failed: %v", index, err)
return errContinue return errContinue
} }
if len(files) == 0 {
p.badIntegrities.warn("index.txt contains no URLs")
}
return p.integrity(files, base, mask, p.badIndices.add) 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 // It's optional
p.badChanges.error("Fetching %s failed. Status code %d (%s)", p.badChanges.error("Fetching %s failed. Status code %d (%s)",
changes, res.StatusCode, res.Status) changes, res.StatusCode, res.Status)
} else {
p.badChanges.warn("Fetching changes.csv failed: %v not found.", changes)
} }
return errContinue return errContinue
} }
p.badChanges.info("Found %v", changes)
times, files, err := func() ([]time.Time, []csaf.AdvisoryFile, error) { times, files, err := func() ([]time.Time, []csaf.AdvisoryFile, error) {
defer res.Body.Close() defer res.Body.Close()
@ -841,6 +850,14 @@ func (p *processor) checkChanges(base string, mask whereType) error {
return errContinue 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 { if !sort.SliceIsSorted(times, func(i, j int) bool {
return times[j].Before(times[i]) return times[j].Before(times[i])
}) { }) {
@ -953,7 +970,7 @@ func (p *processor) checkMissing(string) error {
return nil 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. // if file name confirms to standard.
func (p *processor) checkInvalid(string) error { func (p *processor) checkInvalid(string) error {
@ -975,7 +992,7 @@ func (p *processor) checkInvalid(string) error {
return nil 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. // if their parent directory is listable.
func (p *processor) checkListing(string) error { func (p *processor) checkListing(string) error {
@ -987,6 +1004,10 @@ func (p *processor) checkListing(string) error {
badDirs := map[string]struct{}{} badDirs := map[string]struct{}{}
if len(p.alreadyChecked) == 0 {
p.badDirListings.info("No directory listings found.")
}
for f := range p.alreadyChecked { for f := range p.alreadyChecked {
found, err := pgs.listed(f, p, badDirs) found, err := pgs.listed(f, p, badDirs)
if err != nil && err != errContinue { if err != nil && err != errContinue {