Skip to content

Commit

Permalink
Feat: Compare dates in changes.csv to those within the files if existent
Browse files Browse the repository at this point in the history
  • Loading branch information
JanHoefelmeyer committed Jan 22, 2025
1 parent 5907a39 commit 0fdf2b2
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cmd/csaf_checker/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type processor struct {
pmd any
keys *crypto.KeyRing
labelChecker labelChecker
times map[csaf.AdvisoryFile]time.Time

invalidAdvisories topicMessages
badFilenames topicMessages
Expand Down Expand Up @@ -213,6 +214,7 @@ func (p *processor) reset() {
p.pmd256 = nil
p.pmd = nil
p.keys = nil
clear(p.times)

p.invalidAdvisories.reset()
p.badFilenames.reset()
Expand Down Expand Up @@ -620,6 +622,8 @@ func makeAbsolute(base *url.URL) func(*url.URL) *url.URL {

var yearFromURL = regexp.MustCompile(`.*/(\d{4})/[^/]+$`)

// integrity checks several csaf.AdvisoryFiles for formal
// mistakes, from conforming filenames to invalid advisories.
func (p *processor) integrity(
files []csaf.AdvisoryFile,
base string,
Expand Down Expand Up @@ -750,6 +754,24 @@ func (p *processor) integrity(
p.badFolders.error("%s should be in folder %d", u, d.UTC().Year())
}

if len(p.times) > 0 && p.badChanges.used() {
current, err := p.expr.Eval(`$.document.tracking.current_release_date`, doc)
if err != nil {
p.badChanges.error("Extracting 'current_release_date' from %s failed: %v", u, err)
} else if text, ok := current.(string); !ok {
p.badChanges.error("'current_release_date' is not a string in %s", u)
} else if d, err := time.Parse(time.RFC3339, text); err != nil {
p.badChanges.error(
"Parsing 'initial_release_date' as RFC3339 failed in %s: %v", u, err)
} else {
fmt.Println(p.times[f])
fmt.Println(d)
if p.times[f] != d {
p.badChanges.error("Current release date in changes.csv and %s is not identical", u)
}
}
}

// Check hashes
p.badIntegrities.use()

Expand Down Expand Up @@ -941,6 +963,10 @@ func (p *processor) checkChanges(base string, mask whereType) error {
}
p.badChanges.info("Found %v", changes)

if p.times == nil {
p.times = map[csaf.AdvisoryFile]time.Time{}
}

times, files, err := func() ([]time.Time, []csaf.AdvisoryFile, error) {
defer res.Body.Close()
var times []time.Time
Expand Down Expand Up @@ -973,6 +999,7 @@ func (p *processor) checkChanges(base string, mask whereType) error {
times, files =
append(times, t),
append(files, csaf.PlainAdvisoryFile(path))
p.times[csaf.PlainAdvisoryFile(path)] = t
}
return times, files, nil
}()
Expand Down

0 comments on commit 0fdf2b2

Please sign in to comment.