Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/public-api-server/pkg/jws/jwstest/testkeyset.go
2507 views
1
// Copyright (c) 2023 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 jwstest
6
7
import (
8
"crypto/rand"
9
"crypto/rsa"
10
"testing"
11
12
"github.com/gitpod-io/gitpod/public-api-server/pkg/jws"
13
"github.com/stretchr/testify/require"
14
)
15
16
func GenerateKeySet(t *testing.T) jws.KeySet {
17
return jws.KeySet{
18
Signing: GenerateRSAPrivateKey(t, "0001"),
19
Validating: []jws.Key{
20
GenerateRSAPrivateKey(t, "0002"),
21
GenerateRSAPrivateKey(t, "0003"),
22
},
23
}
24
}
25
26
func GenerateRSAPrivateKey(t *testing.T, id string) jws.Key {
27
t.Helper()
28
29
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
30
require.NoError(t, err)
31
return jws.Key{
32
ID: id,
33
Private: privateKey,
34
}
35
}
36
37