2023-07-18 12:27:26 -05:00
|
|
|
package boltdb_test
|
2023-01-09 15:37:44 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-07-07 11:27:10 -05:00
|
|
|
"crypto/rand"
|
|
|
|
"encoding/base64"
|
|
|
|
"math"
|
2023-01-09 15:37:44 -05:00
|
|
|
"testing"
|
2023-09-08 02:03:58 -05:00
|
|
|
"time"
|
2023-01-09 15:37:44 -05:00
|
|
|
|
|
|
|
"github.com/opencontainers/go-digest"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
"go.etcd.io/bbolt"
|
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
zerr "zotregistry.io/zot/errors"
|
2023-03-28 12:20:09 -05:00
|
|
|
"zotregistry.io/zot/pkg/log"
|
2023-07-18 12:27:26 -05:00
|
|
|
"zotregistry.io/zot/pkg/meta/boltdb"
|
|
|
|
mTypes "zotregistry.io/zot/pkg/meta/types"
|
2023-09-01 13:13:53 -05:00
|
|
|
reqCtx "zotregistry.io/zot/pkg/requestcontext"
|
2023-01-09 15:37:44 -05:00
|
|
|
)
|
|
|
|
|
2023-09-08 02:03:58 -05:00
|
|
|
type imgTrustStore struct{}
|
|
|
|
|
|
|
|
func (its imgTrustStore) VerifySignature(
|
2023-10-30 15:06:04 -05:00
|
|
|
signatureType string, rawSignature []byte, sigKey string, manifestDigest digest.Digest, imageMeta mTypes.ImageMeta,
|
2023-09-08 02:03:58 -05:00
|
|
|
repo string,
|
|
|
|
) (string, time.Time, bool, error) {
|
|
|
|
return "", time.Time{}, false, nil
|
|
|
|
}
|
|
|
|
|
2023-01-09 15:37:44 -05:00
|
|
|
func TestWrapperErrors(t *testing.T) {
|
|
|
|
Convey("Errors", t, func() {
|
|
|
|
tmpDir := t.TempDir()
|
2023-07-18 12:27:26 -05:00
|
|
|
boltDBParams := boltdb.DBParameters{RootDir: tmpDir}
|
|
|
|
boltDriver, err := boltdb.GetBoltDriver(boltDBParams)
|
2023-03-28 12:20:09 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
log := log.NewLogger("debug", "")
|
|
|
|
|
2023-07-18 12:27:26 -05:00
|
|
|
boltdbWrapper, err := boltdb.New(boltDriver, log)
|
2023-01-09 15:37:44 -05:00
|
|
|
So(boltdbWrapper, ShouldNotBeNil)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2023-09-08 02:03:58 -05:00
|
|
|
boltdbWrapper.SetImageTrustStore(imgTrustStore{})
|
|
|
|
|
2023-09-01 13:13:53 -05:00
|
|
|
userAc := reqCtx.NewUserAccessControl()
|
|
|
|
userAc.SetUsername("test")
|
2023-07-07 11:27:10 -05:00
|
|
|
|
2023-09-01 13:13:53 -05:00
|
|
|
ctx := userAc.DeriveContext(context.Background())
|
2023-07-07 11:27:10 -05:00
|
|
|
|
|
|
|
Convey("AddUserAPIKey", func() {
|
|
|
|
Convey("no userid found", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
userAc := reqCtx.NewUserAccessControl()
|
|
|
|
ctx := userAc.DeriveContext(context.Background())
|
2023-07-07 11:27:10 -05:00
|
|
|
|
2023-07-18 12:27:26 -05:00
|
|
|
err = boltdbWrapper.AddUserAPIKey(ctx, "", &mTypes.APIKeyDetails{})
|
2023-07-07 11:27:10 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2023-07-18 12:27:26 -05:00
|
|
|
err = boltdbWrapper.AddUserAPIKey(ctx, "", &mTypes.APIKeyDetails{})
|
2023-07-07 11:27:10 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
err = boltdbWrapper.DB.Update(func(tx *bbolt.Tx) error {
|
2023-07-18 12:27:26 -05:00
|
|
|
return tx.DeleteBucket([]byte(boltdb.UserDataBucket))
|
2023-07-07 11:27:10 -05:00
|
|
|
})
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2023-07-18 12:27:26 -05:00
|
|
|
err = boltdbWrapper.AddUserAPIKey(ctx, "test", &mTypes.APIKeyDetails{})
|
2023-07-07 11:27:10 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
err = boltdbWrapper.DB.Update(func(tx *bbolt.Tx) error {
|
2023-07-18 12:27:26 -05:00
|
|
|
return tx.DeleteBucket([]byte(boltdb.UserAPIKeysBucket))
|
2023-07-07 11:27:10 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2023-07-18 12:27:26 -05:00
|
|
|
err = boltdbWrapper.AddUserAPIKey(ctx, "", &mTypes.APIKeyDetails{})
|
2023-07-07 11:27:10 -05:00
|
|
|
So(err, ShouldEqual, zerr.ErrBucketDoesNotExist)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("UpdateUserAPIKey", func() {
|
|
|
|
err = boltdbWrapper.UpdateUserAPIKeyLastUsed(ctx, "")
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2023-09-01 13:13:53 -05:00
|
|
|
userAc := reqCtx.NewUserAccessControl()
|
|
|
|
ctx := userAc.DeriveContext(context.Background())
|
2023-07-07 11:27:10 -05:00
|
|
|
|
|
|
|
err = boltdbWrapper.UpdateUserAPIKeyLastUsed(ctx, "") //nolint: contextcheck
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("DeleteUserAPIKey", func() {
|
2023-07-18 12:27:26 -05:00
|
|
|
err = boltdbWrapper.SetUserData(ctx, mTypes.UserData{})
|
2023-07-07 11:27:10 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2023-07-18 12:27:26 -05:00
|
|
|
err = boltdbWrapper.AddUserAPIKey(ctx, "hashedKey", &mTypes.APIKeyDetails{})
|
2023-07-07 11:27:10 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
Convey("no such bucket", func() {
|
|
|
|
err = boltdbWrapper.DB.Update(func(tx *bbolt.Tx) error {
|
2023-07-18 12:27:26 -05:00
|
|
|
return tx.DeleteBucket([]byte(boltdb.UserAPIKeysBucket))
|
2023-07-07 11:27:10 -05:00
|
|
|
})
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2023-09-01 13:13:53 -05:00
|
|
|
userAc := reqCtx.NewUserAccessControl()
|
|
|
|
userAc.SetUsername("test")
|
|
|
|
ctx := userAc.DeriveContext(context.Background())
|
2023-07-07 11:27:10 -05:00
|
|
|
|
|
|
|
err = boltdbWrapper.DeleteUserAPIKey(ctx, "")
|
|
|
|
So(err, ShouldEqual, zerr.ErrBucketDoesNotExist)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("userdata not found", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
userAc := reqCtx.NewUserAccessControl()
|
|
|
|
userAc.SetUsername("test")
|
|
|
|
ctx := userAc.DeriveContext(context.Background())
|
2023-07-07 11:27:10 -05:00
|
|
|
|
|
|
|
err := boltdbWrapper.DeleteUserData(ctx)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
err = boltdbWrapper.DeleteUserAPIKey(ctx, "")
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2023-09-01 13:13:53 -05:00
|
|
|
userAc := reqCtx.NewUserAccessControl()
|
|
|
|
ctx := userAc.DeriveContext(context.Background())
|
2023-07-07 11:27:10 -05:00
|
|
|
|
|
|
|
err = boltdbWrapper.DeleteUserAPIKey(ctx, "test") //nolint: contextcheck
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
err = boltdbWrapper.DB.Update(func(tx *bbolt.Tx) error {
|
2023-07-18 12:27:26 -05:00
|
|
|
return tx.DeleteBucket([]byte(boltdb.UserDataBucket))
|
2023-07-07 11:27:10 -05:00
|
|
|
})
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
err = boltdbWrapper.DeleteUserAPIKey(ctx, "") //nolint: contextcheck
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("GetUserAPIKeyInfo", func() {
|
|
|
|
err = boltdbWrapper.DB.Update(func(tx *bbolt.Tx) error {
|
2023-07-18 12:27:26 -05:00
|
|
|
return tx.DeleteBucket([]byte(boltdb.UserAPIKeysBucket))
|
2023-07-07 11:27:10 -05:00
|
|
|
})
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
_, err = boltdbWrapper.GetUserAPIKeyInfo("")
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("GetUserData", func() {
|
|
|
|
err = boltdbWrapper.DB.Update(func(tx *bbolt.Tx) error {
|
2023-07-18 12:27:26 -05:00
|
|
|
buck := tx.Bucket([]byte(boltdb.UserDataBucket))
|
2023-07-07 11:27:10 -05:00
|
|
|
So(buck, ShouldNotBeNil)
|
|
|
|
|
|
|
|
return buck.Put([]byte("test"), []byte("dsa8"))
|
|
|
|
})
|
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
_, err = boltdbWrapper.GetUserData(ctx)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
err = boltdbWrapper.DB.Update(func(tx *bbolt.Tx) error {
|
2023-07-18 12:27:26 -05:00
|
|
|
return tx.DeleteBucket([]byte(boltdb.UserAPIKeysBucket))
|
2023-07-07 11:27:10 -05:00
|
|
|
})
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
_, err = boltdbWrapper.GetUserData(ctx)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("SetUserData", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
userAc := reqCtx.NewUserAccessControl()
|
|
|
|
ctx := userAc.DeriveContext(context.Background())
|
2023-07-07 11:27:10 -05:00
|
|
|
|
2023-07-18 12:27:26 -05:00
|
|
|
err = boltdbWrapper.SetUserData(ctx, mTypes.UserData{})
|
2023-07-07 11:27:10 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
buff := make([]byte, int(math.Ceil(float64(1000000)/float64(1.33333333333))))
|
|
|
|
_, err := rand.Read(buff)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
longString := base64.RawURLEncoding.EncodeToString(buff)
|
|
|
|
|
2023-09-01 13:13:53 -05:00
|
|
|
userAc = reqCtx.NewUserAccessControl()
|
|
|
|
userAc.SetUsername(longString)
|
|
|
|
ctx = userAc.DeriveContext(context.Background())
|
2023-07-07 11:27:10 -05:00
|
|
|
|
2023-07-18 12:27:26 -05:00
|
|
|
err = boltdbWrapper.SetUserData(ctx, mTypes.UserData{}) //nolint: contextcheck
|
2023-07-07 11:27:10 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
err = boltdbWrapper.DB.Update(func(tx *bbolt.Tx) error {
|
2023-07-18 12:27:26 -05:00
|
|
|
return tx.DeleteBucket([]byte(boltdb.UserDataBucket))
|
2023-07-07 11:27:10 -05:00
|
|
|
})
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2023-09-01 13:13:53 -05:00
|
|
|
userAc = reqCtx.NewUserAccessControl()
|
|
|
|
userAc.SetUsername("test")
|
|
|
|
ctx = userAc.DeriveContext(context.Background())
|
2023-07-07 11:27:10 -05:00
|
|
|
|
2023-07-18 12:27:26 -05:00
|
|
|
err = boltdbWrapper.SetUserData(ctx, mTypes.UserData{}) //nolint: contextcheck
|
2023-07-07 11:27:10 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("DeleteUserData", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
userAc = reqCtx.NewUserAccessControl()
|
|
|
|
ctx = userAc.DeriveContext(context.Background())
|
2023-07-07 11:27:10 -05:00
|
|
|
|
|
|
|
err = boltdbWrapper.DeleteUserData(ctx)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
err = boltdbWrapper.DB.Update(func(tx *bbolt.Tx) error {
|
2023-07-18 12:27:26 -05:00
|
|
|
return tx.DeleteBucket([]byte(boltdb.UserDataBucket))
|
2023-07-07 11:27:10 -05:00
|
|
|
})
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2023-09-01 13:13:53 -05:00
|
|
|
userAc = reqCtx.NewUserAccessControl()
|
|
|
|
userAc.SetUsername("test")
|
|
|
|
ctx = userAc.DeriveContext(context.Background())
|
2023-07-07 11:27:10 -05:00
|
|
|
|
|
|
|
err = boltdbWrapper.DeleteUserData(ctx)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("GetUserGroups and SetUserGroups", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
userAc = reqCtx.NewUserAccessControl()
|
|
|
|
ctx = userAc.DeriveContext(context.Background())
|
2023-07-07 11:27:10 -05:00
|
|
|
|
|
|
|
_, err := boltdbWrapper.GetUserGroups(ctx)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
err = boltdbWrapper.SetUserGroups(ctx, []string{})
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2023-04-24 13:13:15 -05:00
|
|
|
Convey("ToggleStarRepo bad context errors", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
uacKey := reqCtx.GetContextKey()
|
|
|
|
ctx := context.WithValue(context.Background(), uacKey, "bad context")
|
2023-04-24 13:13:15 -05:00
|
|
|
|
|
|
|
_, err := boltdbWrapper.ToggleStarRepo(ctx, "repo")
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
Convey("ToggleStarRepo, no repoMeta found", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
userAc := reqCtx.NewUserAccessControl()
|
|
|
|
userAc.SetUsername("username")
|
|
|
|
userAc.SetGlobPatterns("read", map[string]bool{
|
|
|
|
"repo": true,
|
|
|
|
})
|
|
|
|
ctx := userAc.DeriveContext(context.Background())
|
2023-04-24 13:13:15 -05:00
|
|
|
|
|
|
|
err := boltdbWrapper.DB.Update(func(tx *bbolt.Tx) error {
|
2023-10-30 15:06:04 -05:00
|
|
|
repoBuck := tx.Bucket([]byte(boltdb.RepoMetaBuck))
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
err := repoBuck.Put([]byte("repo"), []byte("bad repo"))
|
2023-04-24 13:13:15 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
_, err = boltdbWrapper.ToggleStarRepo(ctx, "repo")
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
Convey("ToggleStarRepo, bad repoMeta found", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
userAc := reqCtx.NewUserAccessControl()
|
|
|
|
userAc.SetUsername("username")
|
|
|
|
userAc.SetGlobPatterns("read", map[string]bool{
|
|
|
|
"repo": true,
|
|
|
|
})
|
|
|
|
ctx := userAc.DeriveContext(context.Background())
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
_, err = boltdbWrapper.ToggleStarRepo(ctx, "repo")
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
Convey("ToggleBookmarkRepo bad context errors", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
uacKey := reqCtx.GetContextKey()
|
|
|
|
ctx := context.WithValue(context.Background(), uacKey, "bad context")
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
_, err := boltdbWrapper.ToggleBookmarkRepo(ctx, "repo")
|
2023-04-24 13:13:15 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
Convey("GetUserData bad context errors", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
uacKey := reqCtx.GetContextKey()
|
|
|
|
ctx := context.WithValue(context.Background(), uacKey, "bad context")
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
_, err := boltdbWrapper.GetUserData(ctx)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
Convey("SetUserData bad context errors", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
uacKey := reqCtx.GetContextKey()
|
|
|
|
ctx := context.WithValue(context.Background(), uacKey, "bad context")
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-07-18 12:27:26 -05:00
|
|
|
err := boltdbWrapper.SetUserData(ctx, mTypes.UserData{})
|
2023-04-24 13:13:15 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
Convey("GetUserGroups bad context errors", func() {
|
|
|
|
_, err := boltdbWrapper.GetUserGroups(ctx)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2023-09-01 13:13:53 -05:00
|
|
|
uacKey := reqCtx.GetContextKey()
|
|
|
|
ctx := context.WithValue(context.Background(), uacKey, "bad context")
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
_, err = boltdbWrapper.GetUserGroups(ctx) //nolint: contextcheck
|
2023-04-24 13:13:15 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
Convey("SetUserGroups bad context errors", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
uacKey := reqCtx.GetContextKey()
|
|
|
|
ctx := context.WithValue(context.Background(), uacKey, "bad context")
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
err := boltdbWrapper.SetUserGroups(ctx, []string{})
|
2023-04-24 13:13:15 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
Convey("AddUserAPIKey bad context errors", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
uacKey := reqCtx.GetContextKey()
|
|
|
|
ctx := context.WithValue(context.Background(), uacKey, "bad context")
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-07-18 12:27:26 -05:00
|
|
|
err := boltdbWrapper.AddUserAPIKey(ctx, "", &mTypes.APIKeyDetails{})
|
2023-04-24 13:13:15 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
Convey("DeleteUserAPIKey bad context errors", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
uacKey := reqCtx.GetContextKey()
|
|
|
|
ctx := context.WithValue(context.Background(), uacKey, "bad context")
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
err := boltdbWrapper.DeleteUserAPIKey(ctx, "")
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
Convey("UpdateUserAPIKeyLastUsed bad context errors", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
uacKey := reqCtx.GetContextKey()
|
|
|
|
ctx := context.WithValue(context.Background(), uacKey, "bad context")
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
err := boltdbWrapper.UpdateUserAPIKeyLastUsed(ctx, "")
|
2023-04-24 13:13:15 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
Convey("DeleteUserData bad context errors", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
uacKey := reqCtx.GetContextKey()
|
|
|
|
ctx := context.WithValue(context.Background(), uacKey, "bad context")
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
err := boltdbWrapper.DeleteUserData(ctx)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
Convey("GetStarredRepos bad context errors", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
uacKey := reqCtx.GetContextKey()
|
|
|
|
ctx := context.WithValue(context.Background(), uacKey, "bad context")
|
2023-04-24 13:13:15 -05:00
|
|
|
|
2023-07-07 11:27:10 -05:00
|
|
|
_, err := boltdbWrapper.GetStarredRepos(ctx)
|
2023-04-24 13:13:15 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("GetBookmarkedRepos bad context errors", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
uacKey := reqCtx.GetContextKey()
|
|
|
|
ctx := context.WithValue(context.Background(), uacKey, "bad context")
|
2023-04-24 13:13:15 -05:00
|
|
|
|
|
|
|
_, err := boltdbWrapper.GetBookmarkedRepos(ctx)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2023-05-04 11:51:21 -05:00
|
|
|
Convey("GetUserRepoMeta unmarshal error", func() {
|
2023-09-01 13:13:53 -05:00
|
|
|
userAc := reqCtx.NewUserAccessControl()
|
|
|
|
userAc.SetUsername("username")
|
|
|
|
userAc.SetGlobPatterns("read", map[string]bool{
|
|
|
|
"repo": true,
|
|
|
|
})
|
|
|
|
ctx := userAc.DeriveContext(context.Background())
|
2023-05-04 11:51:21 -05:00
|
|
|
|
|
|
|
err = boltdbWrapper.DB.Update(func(tx *bbolt.Tx) error {
|
2023-10-30 15:06:04 -05:00
|
|
|
repoBuck := tx.Bucket([]byte(boltdb.RepoMetaBuck))
|
2023-05-04 11:51:21 -05:00
|
|
|
|
|
|
|
err := repoBuck.Put([]byte("repo"), []byte("bad repo"))
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2023-10-30 15:06:04 -05:00
|
|
|
_, err := boltdbWrapper.GetRepoMeta(ctx, "repo")
|
2023-05-04 11:51:21 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
2023-01-09 15:37:44 -05:00
|
|
|
})
|
|
|
|
}
|