2022-09-28 13:39:54 -05:00
|
|
|
package mocks
|
|
|
|
|
|
|
|
import (
|
2023-11-24 03:40:10 -05:00
|
|
|
"context"
|
|
|
|
|
2023-05-25 13:27:49 -05:00
|
|
|
"zotregistry.io/zot/pkg/common"
|
2022-09-28 13:39:54 -05:00
|
|
|
cvemodel "zotregistry.io/zot/pkg/extensions/search/cve/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CveInfoMock struct {
|
2023-11-24 03:40:10 -05:00
|
|
|
GetImageListForCVEFn func(ctx context.Context, repo, cveID string) ([]cvemodel.TagInfo, error)
|
|
|
|
GetImageListWithCVEFixedFn func(ctx context.Context, repo, cveID string) ([]cvemodel.TagInfo, error)
|
2024-01-19 15:59:42 -05:00
|
|
|
GetCVEListForImageFn func(ctx context.Context, repo, reference, searchedCVE, excludedCVE string,
|
2023-12-13 12:16:31 -05:00
|
|
|
pageInput cvemodel.PageInput) ([]cvemodel.CVE, cvemodel.ImageCVESummary, common.PageInfo, error)
|
2023-11-24 03:40:10 -05:00
|
|
|
GetCVESummaryForImageMediaFn func(ctx context.Context, repo string, digest, mediaType string,
|
2023-07-06 03:36:26 -05:00
|
|
|
) (cvemodel.ImageCVESummary, error)
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
2023-11-24 03:40:10 -05:00
|
|
|
func (cveInfo CveInfoMock) GetImageListForCVE(ctx context.Context, repo, cveID string) ([]cvemodel.TagInfo, error) {
|
2022-09-28 13:39:54 -05:00
|
|
|
if cveInfo.GetImageListForCVEFn != nil {
|
2023-11-24 03:40:10 -05:00
|
|
|
return cveInfo.GetImageListForCVEFn(ctx, repo, cveID)
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
2023-04-18 13:07:47 -05:00
|
|
|
return []cvemodel.TagInfo{}, nil
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
2023-11-24 03:40:10 -05:00
|
|
|
func (cveInfo CveInfoMock) GetImageListWithCVEFixed(ctx context.Context, repo, cveID string,
|
|
|
|
) ([]cvemodel.TagInfo, error) {
|
2022-09-28 13:39:54 -05:00
|
|
|
if cveInfo.GetImageListWithCVEFixedFn != nil {
|
2023-11-24 03:40:10 -05:00
|
|
|
return cveInfo.GetImageListWithCVEFixedFn(ctx, repo, cveID)
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
2023-04-18 13:07:47 -05:00
|
|
|
return []cvemodel.TagInfo{}, nil
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
2023-11-24 03:40:10 -05:00
|
|
|
func (cveInfo CveInfoMock) GetCVEListForImage(ctx context.Context, repo string, reference string,
|
2024-01-19 15:59:42 -05:00
|
|
|
searchedCVE string, excludedCVE string, pageInput cvemodel.PageInput,
|
2023-03-16 14:13:07 -05:00
|
|
|
) (
|
2023-01-24 18:03:10 -05:00
|
|
|
[]cvemodel.CVE,
|
2023-12-13 12:16:31 -05:00
|
|
|
cvemodel.ImageCVESummary,
|
2023-05-25 13:27:49 -05:00
|
|
|
common.PageInfo,
|
2023-01-24 18:03:10 -05:00
|
|
|
error,
|
|
|
|
) {
|
2022-09-28 13:39:54 -05:00
|
|
|
if cveInfo.GetCVEListForImageFn != nil {
|
2024-01-19 15:59:42 -05:00
|
|
|
return cveInfo.GetCVEListForImageFn(ctx, repo, reference, searchedCVE, excludedCVE, pageInput)
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
2023-12-13 12:16:31 -05:00
|
|
|
return []cvemodel.CVE{}, cvemodel.ImageCVESummary{}, common.PageInfo{}, nil
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
2023-11-24 03:40:10 -05:00
|
|
|
func (cveInfo CveInfoMock) GetCVESummaryForImageMedia(ctx context.Context, repo, digest, mediaType string,
|
2023-07-06 03:36:26 -05:00
|
|
|
) (cvemodel.ImageCVESummary, error) {
|
|
|
|
if cveInfo.GetCVESummaryForImageMediaFn != nil {
|
2023-11-24 03:40:10 -05:00
|
|
|
return cveInfo.GetCVESummaryForImageMediaFn(ctx, repo, digest, mediaType)
|
2023-07-06 03:36:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return cvemodel.ImageCVESummary{}, nil
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type CveScannerMock struct {
|
2023-02-27 14:23:18 -05:00
|
|
|
IsImageFormatScannableFn func(repo string, reference string) (bool, error)
|
2023-07-06 03:36:26 -05:00
|
|
|
IsImageMediaScannableFn func(repo string, digest, mediaType string) (bool, error)
|
2023-09-22 13:49:17 -05:00
|
|
|
IsResultCachedFn func(digest string) bool
|
|
|
|
GetCachedResultFn func(digest string) map[string]cvemodel.CVE
|
2023-11-24 03:40:10 -05:00
|
|
|
ScanImageFn func(ctx context.Context, image string) (map[string]cvemodel.CVE, error)
|
|
|
|
UpdateDBFn func(ctx context.Context) error
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-07-06 03:36:26 -05:00
|
|
|
func (scanner CveScannerMock) IsImageMediaScannable(repo string, digest, mediaType string) (bool, error) {
|
|
|
|
if scanner.IsImageMediaScannableFn != nil {
|
|
|
|
return scanner.IsImageMediaScannableFn(repo, digest, mediaType)
|
|
|
|
}
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2023-09-22 13:49:17 -05:00
|
|
|
func (scanner CveScannerMock) IsResultCached(digest string) bool {
|
|
|
|
if scanner.IsResultCachedFn != nil {
|
|
|
|
return scanner.IsResultCachedFn(digest)
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (scanner CveScannerMock) GetCachedResult(digest string) map[string]cvemodel.CVE {
|
|
|
|
if scanner.GetCachedResultFn != nil {
|
|
|
|
return scanner.GetCachedResultFn(digest)
|
|
|
|
}
|
|
|
|
|
|
|
|
return map[string]cvemodel.CVE{}
|
|
|
|
}
|
|
|
|
|
2023-11-24 03:40:10 -05:00
|
|
|
func (scanner CveScannerMock) ScanImage(ctx context.Context, image string) (map[string]cvemodel.CVE, error) {
|
2022-09-28 13:39:54 -05:00
|
|
|
if scanner.ScanImageFn != nil {
|
2023-11-24 03:40:10 -05:00
|
|
|
return scanner.ScanImageFn(ctx, image)
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return map[string]cvemodel.CVE{}, nil
|
|
|
|
}
|
|
|
|
|
2023-11-24 03:40:10 -05:00
|
|
|
func (scanner CveScannerMock) UpdateDB(ctx context.Context) error {
|
2022-09-28 13:39:54 -05:00
|
|
|
if scanner.UpdateDBFn != nil {
|
2023-11-24 03:40:10 -05:00
|
|
|
return scanner.UpdateDBFn(ctx)
|
2022-09-28 13:39:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|