0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00
zot/pkg/test/mocks/cache_mock.go
Ramkumar Chinchani aaee0220e4
Merge pull request from GHSA-55r9-5mx9-qq7r
when a client pushes an image zot's inline dedupe
will try to find the blob path corresponding with the blob digest
that it's currently pushed and if it's found in the cache
then zot will make a symbolic link to that cache entry and report
to the client that the blob already exists on the location.

Before this patch authorization was not applied on this process meaning
that a user could copy blobs without having permissions on the source repo.

Added a rule which says that the client should have read permissions on the source repo
before deduping, otherwise just Stat() the blob and return the corresponding status code.

Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
Co-authored-by: Petu Eusebiu <peusebiu@cisco.com>
2024-07-08 11:35:44 -07:00

80 lines
1.8 KiB
Go

package mocks
import godigest "github.com/opencontainers/go-digest"
type CacheMock struct {
// Returns the human-readable "name" of the driver.
NameFn func() string
GetAllBlobsFn func(digest godigest.Digest) ([]string, error)
// Retrieves the blob matching provided digest.
GetBlobFn func(digest godigest.Digest) (string, error)
// Uploads blob to cachedb.
PutBlobFn func(digest godigest.Digest, path string) error
// Check if blob exists in cachedb.
HasBlobFn func(digest godigest.Digest, path string) bool
// Delete a blob from the cachedb.
DeleteBlobFn func(digest godigest.Digest, path string) error
UsesRelativePathsFn func() bool
}
func (cacheMock CacheMock) UsesRelativePaths() bool {
if cacheMock.UsesRelativePathsFn != nil {
return cacheMock.UsesRelativePaths()
}
return false
}
func (cacheMock CacheMock) Name() string {
if cacheMock.NameFn != nil {
return cacheMock.NameFn()
}
return "mock"
}
func (cacheMock CacheMock) GetBlob(digest godigest.Digest) (string, error) {
if cacheMock.GetBlobFn != nil {
return cacheMock.GetBlobFn(digest)
}
return "", nil
}
func (cacheMock CacheMock) PutBlob(digest godigest.Digest, path string) error {
if cacheMock.PutBlobFn != nil {
return cacheMock.PutBlobFn(digest, path)
}
return nil
}
func (cacheMock CacheMock) HasBlob(digest godigest.Digest, path string) bool {
if cacheMock.HasBlobFn != nil {
return cacheMock.HasBlobFn(digest, path)
}
return true
}
func (cacheMock CacheMock) DeleteBlob(digest godigest.Digest, path string) error {
if cacheMock.DeleteBlobFn != nil {
return cacheMock.DeleteBlobFn(digest, path)
}
return nil
}
func (cacheMock CacheMock) GetAllBlobs(digest godigest.Digest) ([]string, error) {
if cacheMock.GetAllBlobsFn != nil {
return cacheMock.GetAllBlobsFn(digest)
}
return []string{}, nil
}