Path: blob/main/components/gitpod-db/go/dbtest/encryption.go
2500 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package dbtest56import (7"encoding/base64"8db "github.com/gitpod-io/gitpod/components/gitpod-db/go"9"github.com/stretchr/testify/require"10"testing"11)1213func GetTestCipher(t *testing.T) (*db.AES256CBC, db.CipherMetadata) {14t.Helper()1516// This is a test key also used in server tests - see components/gitpod-protocol/src/encryption/encryption-engine.spec.ts17key, err := base64.StdEncoding.DecodeString("ZMaTPrF7s9gkLbY45zP59O0LTpLvDd/cgqPE9Ptghh8=")18require.NoError(t, err)1920metadata := db.CipherMetadata{21Name: "default",22Version: 1,23}24cipher, err := db.NewAES256CBCCipher(string(key), metadata)25require.NoError(t, err)26return cipher, metadata27}2829func CipherSet(t *testing.T) *db.CipherSet {30t.Helper()3132configs := []db.CipherConfig{33{34Name: "default",35Version: 1,36Primary: true,37Material: "ZMaTPrF7s9gkLbY45zP59O0LTpLvDd/cgqPE9Ptghh8=",38},39{40Name: "secondary",41Version: 1,42Primary: false,43Material: "A3iUCT27LVbN67Fa+yfcMmLgNFdUWEl22JcdoER44gA=",44},45}4647set, err := db.NewCipherSet(configs)48require.NoError(t, err)4950return set51}525354