@@ -27,13 +27,16 @@ var _ = Describe("GenerateUserSettings", func() {
27
27
userTags = []topology.UserTag {"administrator" , "monitoring" }
28
28
})
29
29
30
- It ("generates the expected rabbithole.UserSettings" , func () {
30
+ It ("uses the password to generate the expected rabbithole.UserSettings" , func () {
31
31
settings , err := internal .GenerateUserSettings (& credentialSecret , userTags )
32
32
Expect (err ).NotTo (HaveOccurred ())
33
33
Expect (settings .Name ).To (Equal ("my-rabbit-user" ))
34
34
Expect (settings .Tags ).To (ConsistOf ("administrator" , "monitoring" ))
35
35
Expect (settings .HashingAlgorithm .String ()).To (Equal (rabbithole .HashingAlgorithmSHA512 .String ()))
36
36
37
+ // Password should not be sent, even if provided
38
+ Expect (settings .Password ).To (BeEmpty ())
39
+
37
40
// The first 4 bytes of the PasswordHash will be the salt used in the hashing algorithm.
38
41
// See https://www.rabbitmq.com/passwords.html#computing-password-hash.
39
42
// We can take this salt and calculate what the correct hashed salted value would
@@ -45,4 +48,19 @@ var _ = Describe("GenerateUserSettings", func() {
45
48
saltedHash := sha512 .Sum512 ([]byte (string (salt ) + "a-secure-password" ))
46
49
Expect (base64 .StdEncoding .EncodeToString ([]byte (string (salt ) + string (saltedHash [:])))).To (Equal (settings .PasswordHash ))
47
50
})
51
+
52
+ It ("uses the passwordHash to generate the expected rabbithole.UserSettings" , func () {
53
+ hash , _ := rabbithole .SaltedPasswordHashSHA256 ("a-different-password" )
54
+ credentialSecret .Data ["passwordHash" ] = []byte (hash )
55
+
56
+ settings , err := internal .GenerateUserSettings (& credentialSecret , userTags )
57
+ Expect (err ).NotTo (HaveOccurred ())
58
+ Expect (settings .Name ).To (Equal ("my-rabbit-user" ))
59
+ Expect (settings .Tags ).To (ConsistOf ("administrator" , "monitoring" ))
60
+ Expect (settings .HashingAlgorithm .String ()).To (Equal (rabbithole .HashingAlgorithmSHA512 .String ()))
61
+ Expect (settings .PasswordHash ).To (Equal (hash ))
62
+
63
+ // Password should not be sent, even if provided
64
+ Expect (settings .Password ).To (BeEmpty ())
65
+ })
48
66
})
0 commit comments