mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-05 20:40:16 -08:00
fix(server): fix redis key when trying to delete blob (#8649)
This commit is contained in:
2
pkg/cache/redis.go
vendored
2
pkg/cache/redis.go
vendored
@@ -142,7 +142,7 @@ func (c RedisCache) PutBlob(blobID string, blobInfo types.BlobInfo) error {
|
||||
func (c RedisCache) DeleteBlobs(blobIDs []string) error {
|
||||
var errs error
|
||||
for _, blobID := range blobIDs {
|
||||
key := fmt.Sprintf("%s::%s::%s", redisPrefix, artifactBucket, blobID)
|
||||
key := fmt.Sprintf("%s::%s::%s", redisPrefix, blobBucket, blobID)
|
||||
if err := c.client.Del(context.TODO(), key).Err(); err != nil {
|
||||
errs = multierror.Append(errs, xerrors.Errorf("unable to delete blob %s: %w", blobID, err))
|
||||
}
|
||||
|
||||
8
pkg/cache/redis_test.go
vendored
8
pkg/cache/redis_test.go
vendored
@@ -523,8 +523,6 @@ func TestRedisCache_DeleteBlobs(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
defer s.Close()
|
||||
|
||||
s.Set(correctHash, "any string")
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
addr := s.Addr()
|
||||
@@ -535,12 +533,18 @@ func TestRedisCache_DeleteBlobs(t *testing.T) {
|
||||
c, err := cache.NewRedisCache(fmt.Sprintf("redis://%s", addr), "", "", "", false, 0)
|
||||
require.NoError(t, err)
|
||||
|
||||
s.Set(tt.wantKey, "any string")
|
||||
|
||||
err = c.DeleteBlobs(tt.args.blobIDs)
|
||||
if tt.wantErr != "" {
|
||||
require.ErrorContains(t, err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify that the blobs are deleted
|
||||
got := s.Keys()
|
||||
assert.NotContains(t, got, tt.wantKey)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user