-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsecret_test.go
61 lines (50 loc) · 1.48 KB
/
secret_test.go
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
package rotate_test
import (
"strings"
"testing"
rotate "github.com/square/password-rotation-lambda/v2"
)
func TestRandomPassword_Default(t *testing.T) {
var rp rotate.RandomPassword
secret := map[string]string{
"username": "test-user",
"password": "original-password",
}
err := rp.Rotate(secret)
if err != nil {
t.Fatal(err)
}
if len(secret["password"]) != rotate.DEFAULT_PASSWORD_LENGTH {
t.Fatalf("expected the default RandomPassword to generate passwords with %d characters, got %d characters", rotate.DEFAULT_PASSWORD_LENGTH, len(secret["password"]))
}
}
func TestRandomPassword_Custom(t *testing.T) {
rp := rotate.RandomPassword{
PasswordLength: 1,
}
secret := map[string]string{
"username": "test-user",
"password": "original-password",
}
err := rp.Rotate(secret)
if err != nil {
t.Fatal(err)
}
if len(secret["password"]) != rp.PasswordLength {
t.Fatalf("expected the custom RandomPassword to generate passwords with %d characters, got %d characters", rp.PasswordLength, len(secret["password"]))
}
rp = rotate.RandomPassword{
ValidCharset: []rune("X"),
}
secret = map[string]string{
"username": "test-user",
"password": "original-password",
}
err = rp.Rotate(secret)
if err != nil {
t.Fatal(err)
}
if secret["password"] != strings.Repeat("X", rotate.DEFAULT_PASSWORD_LENGTH) {
t.Fatalf("expected to generate password '%s' from single character charset, got '%s'", strings.Repeat("X", rotate.DEFAULT_PASSWORD_LENGTH), secret["password"])
}
}