forked from gardener/gardener
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrsa_private_key_test.go
More file actions
79 lines (65 loc) · 1.92 KB
/
rsa_private_key_test.go
File metadata and controls
79 lines (65 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package secrets_test
import (
"crypto/rand"
"crypto/rsa"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/gardener/gardener/pkg/utils"
. "github.com/gardener/gardener/pkg/utils/secrets"
)
var _ = Describe("RSA Private Key Secrets", func() {
Describe("RSA Secret Configuration", func() {
var rsaPrivateKeyConfig *RSASecretConfig
BeforeEach(func() {
rsaPrivateKeyConfig = &RSASecretConfig{
Bits: 3072,
Name: "rsa-secret",
}
})
Describe("#Generate", func() {
It("should properly generate RSAKeys object", func() {
obj, err := rsaPrivateKeyConfig.Generate()
Expect(err).NotTo(HaveOccurred())
rsaSecret, ok := obj.(*RSAKeys)
Expect(ok).To(BeTrue())
Expect(rsaSecret.PrivateKey).NotTo(BeNil())
Expect(*rsaSecret.PublicKey).To(Equal(rsaSecret.PrivateKey.PublicKey))
})
It("should generate ssh public key if specified in the config", func() {
rsaPrivateKeyConfig.UsedForSSH = true
obj, err := rsaPrivateKeyConfig.Generate()
Expect(err).NotTo(HaveOccurred())
rsaSecret, ok := obj.(*RSAKeys)
Expect(ok).To(BeTrue())
Expect(rsaSecret.OpenSSHAuthorizedKey).NotTo(BeNil())
})
})
})
Describe("RSAKeys Object", func() {
var (
rsaKeys *RSAKeys
key *rsa.PrivateKey
)
BeforeEach(func() {
var err error
key, err = rsa.GenerateKey(rand.Reader, 3072)
Expect(err).NotTo(HaveOccurred())
rsaKeys = &RSAKeys{
PrivateKey: key,
OpenSSHAuthorizedKey: []byte("bar"),
}
})
Describe("#SecretData", func() {
It("should properly return secret data", func() {
secretData := map[string][]byte{
DataKeyRSAPrivateKey: utils.EncodePrivateKey(key),
DataKeySSHAuthorizedKeys: []byte("bar"),
}
Expect(rsaKeys.SecretData()).To(Equal(secretData))
})
})
})
})