mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Added execution order of checks.
This commit is contained in:
parent
9a061cb18a
commit
33154d7d58
2 changed files with 28 additions and 16 deletions
|
|
@ -26,6 +26,7 @@ type processor struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type check interface {
|
type check interface {
|
||||||
|
executeOrder() int
|
||||||
run(*processor, string) error
|
run(*processor, string) error
|
||||||
report(*processor, *Domain)
|
report(*processor, *Domain)
|
||||||
}
|
}
|
||||||
|
|
@ -47,8 +48,14 @@ func (p *processor) run(checks []check, domains []string) (*Report, error) {
|
||||||
|
|
||||||
var report Report
|
var report Report
|
||||||
|
|
||||||
|
execs := make([]check, len(checks))
|
||||||
|
copy(execs, checks)
|
||||||
|
sort.SliceStable(execs, func(i, j int) bool {
|
||||||
|
return execs[i].executeOrder() < execs[j].executeOrder()
|
||||||
|
})
|
||||||
|
|
||||||
for _, d := range domains {
|
for _, d := range domains {
|
||||||
for _, ch := range checks {
|
for _, ch := range execs {
|
||||||
if err := ch.run(p, d); err != nil {
|
if err := ch.run(p, d); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -98,6 +105,7 @@ func (p *processor) httpClient() *http.Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
type baseCheck struct {
|
type baseCheck struct {
|
||||||
|
exec int
|
||||||
num int
|
num int
|
||||||
description string
|
description string
|
||||||
messages []string
|
messages []string
|
||||||
|
|
@ -155,6 +163,10 @@ type publicPGPKeyCheck struct {
|
||||||
baseCheck
|
baseCheck
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bc *baseCheck) executeOrder() int {
|
||||||
|
return bc.exec
|
||||||
|
}
|
||||||
|
|
||||||
func (bc *baseCheck) run(*processor, string) error {
|
func (bc *baseCheck) run(*processor, string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -200,7 +212,7 @@ func (tc *tlsCheck) run(p *processor, domain string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *redirectsCheck) report(p *processor, domain *Domain) {
|
func (rc *redirectsCheck) run(p *processor, domain string) error {
|
||||||
if len(p.redirects) == 0 {
|
if len(p.redirects) == 0 {
|
||||||
rc.add("No redirections found.")
|
rc.add("No redirections found.")
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -216,7 +228,7 @@ func (rc *redirectsCheck) report(p *processor, domain *Domain) {
|
||||||
}
|
}
|
||||||
rc.baseCheck.messages = keys
|
rc.baseCheck.messages = keys
|
||||||
}
|
}
|
||||||
rc.baseCheck.report(p, domain)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pmdc *providerMetadataCheck) run(p *processor, domain string) error {
|
func (pmdc *providerMetadataCheck) run(p *processor, domain string) error {
|
||||||
|
|
|
||||||
|
|
@ -100,19 +100,19 @@ func writeReport(report *Report, opts *options) error {
|
||||||
|
|
||||||
func buildChecks() []check {
|
func buildChecks() []check {
|
||||||
return []check{
|
return []check{
|
||||||
&tlsCheck{baseCheck{num: 3, description: "TLS"}},
|
&tlsCheck{baseCheck{exec: 0, num: 3, description: "TLS"}},
|
||||||
&redirectsCheck{baseCheck{num: 6, description: "Redirects"}},
|
&redirectsCheck{baseCheck{exec: 12, num: 6, description: "Redirects"}},
|
||||||
&providerMetadataCheck{baseCheck{num: 7, description: "provider-metadata.json"}},
|
&providerMetadataCheck{baseCheck{exec: 1, num: 7, description: "provider-metadata.json"}},
|
||||||
&securityCheck{baseCheck{num: 8, description: "security.txt"}},
|
&securityCheck{baseCheck{exec: 2, num: 8, description: "security.txt"}},
|
||||||
&wellknownMetadataCheck{baseCheck{num: 9, description: "/.well-known/csaf/provider-metadata.json"}},
|
&wellknownMetadataCheck{baseCheck{exec: 3, num: 9, description: "/.well-known/csaf/provider-metadata.json"}},
|
||||||
&dnsPathCheck{baseCheck{num: 10, description: "DNS path"}},
|
&dnsPathCheck{baseCheck{exec: 4, num: 10, description: "DNS path"}},
|
||||||
&oneFolderPerYearCheck{baseCheck{num: 11, description: "One folder per year"}},
|
&oneFolderPerYearCheck{baseCheck{exec: 5, num: 11, description: "One folder per year"}},
|
||||||
&indexCheck{baseCheck{num: 12, description: "index.txt"}},
|
&indexCheck{baseCheck{exec: 6, num: 12, description: "index.txt"}},
|
||||||
&changesCheck{baseCheck{num: 13, description: "changes.csv"}},
|
&changesCheck{baseCheck{exec: 7, num: 13, description: "changes.csv"}},
|
||||||
&directoryListingsCheck{baseCheck{num: 14, description: "Directory listings"}},
|
&directoryListingsCheck{baseCheck{exec: 8, num: 14, description: "Directory listings"}},
|
||||||
&integrityCheck{baseCheck{num: 18, description: "Integrity"}},
|
&integrityCheck{baseCheck{exec: 9, num: 18, description: "Integrity"}},
|
||||||
&signaturesCheck{baseCheck{num: 19, description: "Signatures"}},
|
&signaturesCheck{baseCheck{exec: 11, num: 19, description: "Signatures"}},
|
||||||
&publicPGPKeyCheck{baseCheck{num: 20, description: "Public PGP Key"}},
|
&publicPGPKeyCheck{baseCheck{exec: 10, num: 20, description: "Public PGP Key"}},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue