2022-09-28 13:39:54 -05:00
|
|
|
package mocks
|
|
|
|
|
|
|
|
import (
|
|
|
|
cveinfo "zotregistry.io/zot/pkg/extensions/search/cve"
|
|
|
|
cvemodel "zotregistry.io/zot/pkg/extensions/search/cve/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CveInfoMock struct {
|
2023-04-18 13:07:47 -05:00
|
|
|
GetImageListForCVEFn func(repo, cveID string) ([]cvemodel.TagInfo, error)
|
|
|
|
GetImageListWithCVEFixedFn func(repo, cveID string) ([]cvemodel.TagInfo, error)
|
2023-03-16 14:13:07 -05:00
|
|
|
GetCVEListForImageFn func(repo string, reference string, searchedCVE string, pageInput cveinfo.PageInput,
|
2023-02-27 14:23:18 -05:00
|
|
|
) ([]cvemodel.CVE, cveinfo.PageInfo, error)
|
|
|
|
GetCVESummaryForImageFn func(repo string, reference string,
|
|
|
|
) (cveinfo.ImageCVESummary, error)
|
|
|
|
CompareSeveritiesFn func(severity1, severity2 string) int
|
|
|
|
UpdateDBFn func() error
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
2023-04-18 13:07:47 -05:00
|
|
|
func (cveInfo CveInfoMock) GetImageListForCVE(repo, cveID string) ([]cvemodel.TagInfo, error) {
|
2022-09-28 13:39:54 -05:00
|
|
|
if cveInfo.GetImageListForCVEFn != nil {
|
|
|
|
return cveInfo.GetImageListForCVEFn(repo, cveID)
|
|
|
|
}
|
|
|
|
|
2023-04-18 13:07:47 -05:00
|
|
|
return []cvemodel.TagInfo{}, nil
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
2023-04-18 13:07:47 -05:00
|
|
|
func (cveInfo CveInfoMock) GetImageListWithCVEFixed(repo, cveID string) ([]cvemodel.TagInfo, error) {
|
2022-09-28 13:39:54 -05:00
|
|
|
if cveInfo.GetImageListWithCVEFixedFn != nil {
|
|
|
|
return cveInfo.GetImageListWithCVEFixedFn(repo, cveID)
|
|
|
|
}
|
|
|
|
|
2023-04-18 13:07:47 -05:00
|
|
|
return []cvemodel.TagInfo{}, nil
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
2023-03-16 14:13:07 -05:00
|
|
|
func (cveInfo CveInfoMock) GetCVEListForImage(repo string, reference string,
|
|
|
|
searchedCVE string, pageInput cveinfo.PageInput,
|
|
|
|
) (
|
2023-01-24 18:03:10 -05:00
|
|
|
[]cvemodel.CVE,
|
|
|
|
cveinfo.PageInfo,
|
|
|
|
error,
|
|
|
|
) {
|
2022-09-28 13:39:54 -05:00
|
|
|
if cveInfo.GetCVEListForImageFn != nil {
|
2023-03-16 14:13:07 -05:00
|
|
|
return cveInfo.GetCVEListForImageFn(repo, reference, searchedCVE, pageInput)
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
2023-01-24 18:03:10 -05:00
|
|
|
return []cvemodel.CVE{}, cveinfo.PageInfo{}, nil
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
2023-02-27 14:23:18 -05:00
|
|
|
func (cveInfo CveInfoMock) GetCVESummaryForImage(repo string, reference string,
|
|
|
|
) (cveinfo.ImageCVESummary, error) {
|
2022-09-28 13:39:54 -05:00
|
|
|
if cveInfo.GetCVESummaryForImageFn != nil {
|
2023-02-27 14:23:18 -05:00
|
|
|
return cveInfo.GetCVESummaryForImageFn(repo, reference)
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return cveinfo.ImageCVESummary{}, nil
|
|
|
|
}
|
|
|
|
|
2023-01-24 18:03:10 -05:00
|
|
|
func (cveInfo CveInfoMock) CompareSeverities(severity1, severity2 string) int {
|
|
|
|
if cveInfo.CompareSeveritiesFn != nil {
|
|
|
|
return cveInfo.CompareSeveritiesFn(severity1, severity2)
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2022-09-28 13:39:54 -05:00
|
|
|
func (cveInfo CveInfoMock) UpdateDB() error {
|
|
|
|
if cveInfo.UpdateDBFn != nil {
|
|
|
|
return cveInfo.UpdateDBFn()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type CveScannerMock struct {
|
2023-02-27 14:23:18 -05:00
|
|
|
IsImageFormatScannableFn func(repo string, reference string) (bool, error)
|
2022-09-28 13:39:54 -05:00
|
|
|
ScanImageFn func(image string) (map[string]cvemodel.CVE, error)
|
|
|
|
CompareSeveritiesFn func(severity1, severity2 string) int
|
|
|
|
UpdateDBFn func() error
|
|
|
|
}
|
|
|
|
|
2023-02-27 14:23:18 -05:00
|
|
|
func (scanner CveScannerMock) IsImageFormatScannable(repo string, reference string) (bool, error) {
|
2022-09-28 13:39:54 -05:00
|
|
|
if scanner.IsImageFormatScannableFn != nil {
|
2023-02-27 14:23:18 -05:00
|
|
|
return scanner.IsImageFormatScannableFn(repo, reference)
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (scanner CveScannerMock) ScanImage(image string) (map[string]cvemodel.CVE, error) {
|
|
|
|
if scanner.ScanImageFn != nil {
|
|
|
|
return scanner.ScanImageFn(image)
|
|
|
|
}
|
|
|
|
|
|
|
|
return map[string]cvemodel.CVE{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (scanner CveScannerMock) CompareSeverities(severity1, severity2 string) int {
|
|
|
|
if scanner.CompareSeveritiesFn != nil {
|
|
|
|
return scanner.CompareSeveritiesFn(severity1, severity2)
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (scanner CveScannerMock) UpdateDB() error {
|
|
|
|
if scanner.UpdateDBFn != nil {
|
|
|
|
return scanner.UpdateDBFn()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|