@@ -27,13 +27,16 @@ var _ = Describe("GenerateUserSettings", func() {
2727 userTags = []topology.UserTag {"administrator" , "monitoring" }
2828 })
2929
30- It ("generates the expected rabbithole.UserSettings" , func () {
30+ It ("uses the password to generate the expected rabbithole.UserSettings" , func () {
3131 settings , err := internal .GenerateUserSettings (& credentialSecret , userTags )
3232 Expect (err ).NotTo (HaveOccurred ())
3333 Expect (settings .Name ).To (Equal ("my-rabbit-user" ))
3434 Expect (settings .Tags ).To (ConsistOf ("administrator" , "monitoring" ))
3535 Expect (settings .HashingAlgorithm .String ()).To (Equal (rabbithole .HashingAlgorithmSHA512 .String ()))
3636
37+ // Password should not be sent, even if provided
38+ Expect (settings .Password ).To (BeEmpty ())
39+
3740 // The first 4 bytes of the PasswordHash will be the salt used in the hashing algorithm.
3841 // See https://www.rabbitmq.com/passwords.html#computing-password-hash.
3942 // We can take this salt and calculate what the correct hashed salted value would
@@ -45,4 +48,19 @@ var _ = Describe("GenerateUserSettings", func() {
4548 saltedHash := sha512 .Sum512 ([]byte (string (salt ) + "a-secure-password" ))
4649 Expect (base64 .StdEncoding .EncodeToString ([]byte (string (salt ) + string (saltedHash [:])))).To (Equal (settings .PasswordHash ))
4750 })
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+ })
4866})
0 commit comments