forked from gardener/gardener
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic_auth_test.go
More file actions
54 lines (43 loc) · 1.57 KB
/
basic_auth_test.go
File metadata and controls
54 lines (43 loc) · 1.57 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
// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package secrets_test
import (
"strings"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"golang.org/x/crypto/bcrypt"
. "github.com/gardener/gardener/pkg/utils/secrets"
)
var _ = Describe("Basic Auth Secrets", func() {
Describe("Configuration", func() {
var basicAuthConfiguration *BasicAuthSecretConfig
BeforeEach(func() {
basicAuthConfiguration = &BasicAuthSecretConfig{
Name: "basic-auth",
Format: BasicAuthFormatNormal,
Username: "admin",
PasswordLength: 32,
}
})
Describe("#Generate", func() {
It("should properly generate Basic Auth Object", func() {
obj, err := basicAuthConfiguration.Generate()
Expect(err).NotTo(HaveOccurred())
basicAuth, ok := obj.(*BasicAuth)
Expect(ok).To(BeTrue())
password := strings.TrimPrefix(string(basicAuth.SecretData()[DataKeyAuth]), basicAuthConfiguration.Username+":")
Expect(bcrypt.CompareHashAndPassword([]byte(password), []byte(basicAuth.Password))).To(Succeed())
})
})
Describe("#SecretData", func() {
It("should properly return secret data if format is BasicAuthFormatNormal", func() {
obj, err := basicAuthConfiguration.Generate()
Expect(err).NotTo(HaveOccurred())
data := obj.SecretData()
password := strings.TrimPrefix(string(data[DataKeyAuth]), string(data[DataKeyUserName])+":")
Expect(bcrypt.CompareHashAndPassword([]byte(password), data[DataKeyPassword])).To(Succeed())
})
})
})
})