Skip to content

Commit

Permalink
Redis: verify deletion count
Browse files Browse the repository at this point in the history
Signed-off-by: Johan Haals <[email protected]>
  • Loading branch information
jhaals committed May 8, 2024
1 parent b5c64f7 commit ceae5c5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/server/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"encoding/json"
"fmt"
"time"

"github.com/go-redis/redis/v7"
Expand Down Expand Up @@ -36,11 +37,14 @@ func (r *Redis) Get(key string) (yopass.Secret, error) {
}

if s.OneTime {
if err := r.client.Del(key).Err(); err != nil {
res, err := r.client.Del(key).Result()
if err != nil {
return s, err
}
if res != 1 {
return s, fmt.Errorf("expected to delete 1 key, but deleted %d keys", res)
}

Check warning on line 46 in pkg/server/redis.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/redis.go#L45-L46

Added lines #L45 - L46 were not covered by tests
}

return s, nil
}

Expand All @@ -59,8 +63,10 @@ func (r *Redis) Put(key string, secret yopass.Secret) error {

// Delete key from Redis
func (r *Redis) Delete(key string) (bool, error) {
err := r.client.Del(key).Err()

res, err := r.client.Del(key).Result()
if res != 1 {
return false, fmt.Errorf("expected to delete 1 key, but deleted %d keys", res)
}

Check warning on line 69 in pkg/server/redis.go

View check run for this annotation

Codecov / codecov/patch

pkg/server/redis.go#L66-L69

Added lines #L66 - L69 were not covered by tests
if err == redis.Nil {
return false, nil
}
Expand Down

0 comments on commit ceae5c5

Please sign in to comment.