mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 18:15:42 +01:00
check whether rolie service document contains all feeds
This commit is contained in:
parent
fd374b30b6
commit
d7fb52b735
1 changed files with 50 additions and 4 deletions
|
|
@ -285,7 +285,7 @@ func (p *processor) serviceCheck(url string, feeds [][]csaf.Feed) error {
|
||||||
return errContinue
|
return errContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
rolieService, err := func() (any, error) {
|
rolieService, err := func() (*csaf.ROLIEServiceDocument, error) {
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
return csaf.LoadROLIEServiceDocument(res.Body)
|
return csaf.LoadROLIEServiceDocument(res.Body)
|
||||||
}()
|
}()
|
||||||
|
|
@ -295,11 +295,57 @@ func (p *processor) serviceCheck(url string, feeds [][]csaf.Feed) error {
|
||||||
return errContinue
|
return errContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use me!
|
// Build lists of all feeds in feeds and in the Service Document
|
||||||
_ = rolieService
|
sfeeds := []string{}
|
||||||
_ = feeds
|
ffeeds := []string{}
|
||||||
|
for _, col := range rolieService.Service.Workspace {
|
||||||
|
for _, fd := range col.Collection {
|
||||||
|
sfeeds = append(sfeeds, fd.HRef)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, r := range feeds {
|
||||||
|
for _, s := range r {
|
||||||
|
ffeeds = append(ffeeds, string(*s.URL))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check if ROLIE Service Document contains exactly all ROLIE feeds
|
||||||
|
m1, m2 := sameContentsSS(sfeeds, ffeeds)
|
||||||
|
if len(m1) != 0 {
|
||||||
|
p.badROLIEservice.error("The ROLIE service document contains nonexistent feed entries: %v", m1)
|
||||||
|
}
|
||||||
|
if len(m2) != 0 {
|
||||||
|
p.badROLIEservice.error("The ROLIE service document is missing feed entries: %v", m2)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
// TODO: Check conformity with RFC8322
|
// TODO: Check conformity with RFC8322
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sameContents checks if two slices slice1 and slice2 of strings contains the same strings
|
||||||
|
// returns two slices of all strings missing in the respective other slice
|
||||||
|
func sameContentsSS(slice1 []string, slice2 []string) ([]string, []string) {
|
||||||
|
m1 := []string{}
|
||||||
|
m2 := []string{}
|
||||||
|
for _, e1 := range slice1 {
|
||||||
|
if !containsAllSS(slice2, e1) {
|
||||||
|
m1 = append(m1, e1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, e2 := range slice2 {
|
||||||
|
if !containsAllSS(slice1, e2) {
|
||||||
|
m2 = append(m2, e2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m1, m2
|
||||||
|
}
|
||||||
|
|
||||||
|
// containsAllSS checks if a slice of strings contains a string
|
||||||
|
func containsAllSS(slice []string, str string) bool {
|
||||||
|
for _, e := range slice {
|
||||||
|
if e == str {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue