Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-db/go/dbtest/encryption.go
2500 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package dbtest
6
7
import (
8
"encoding/base64"
9
db "github.com/gitpod-io/gitpod/components/gitpod-db/go"
10
"github.com/stretchr/testify/require"
11
"testing"
12
)
13
14
func GetTestCipher(t *testing.T) (*db.AES256CBC, db.CipherMetadata) {
15
t.Helper()
16
17
// This is a test key also used in server tests - see components/gitpod-protocol/src/encryption/encryption-engine.spec.ts
18
key, err := base64.StdEncoding.DecodeString("ZMaTPrF7s9gkLbY45zP59O0LTpLvDd/cgqPE9Ptghh8=")
19
require.NoError(t, err)
20
21
metadata := db.CipherMetadata{
22
Name: "default",
23
Version: 1,
24
}
25
cipher, err := db.NewAES256CBCCipher(string(key), metadata)
26
require.NoError(t, err)
27
return cipher, metadata
28
}
29
30
func CipherSet(t *testing.T) *db.CipherSet {
31
t.Helper()
32
33
configs := []db.CipherConfig{
34
{
35
Name: "default",
36
Version: 1,
37
Primary: true,
38
Material: "ZMaTPrF7s9gkLbY45zP59O0LTpLvDd/cgqPE9Ptghh8=",
39
},
40
{
41
Name: "secondary",
42
Version: 1,
43
Primary: false,
44
Material: "A3iUCT27LVbN67Fa+yfcMmLgNFdUWEl22JcdoER44gA=",
45
},
46
}
47
48
set, err := db.NewCipherSet(configs)
49
require.NoError(t, err)
50
51
return set
52
}
53
54