(t *testing.T)
| 79 | } |
| 80 | |
| 81 | func TestRecordPassword(t *testing.T) { |
| 82 | scenarios := []struct { |
| 83 | name string |
| 84 | password string |
| 85 | expected bool |
| 86 | }{ |
| 87 | { |
| 88 | "empty password", |
| 89 | "", |
| 90 | false, |
| 91 | }, |
| 92 | { |
| 93 | "non-empty password", |
| 94 | "123456", |
| 95 | true, |
| 96 | }, |
| 97 | } |
| 98 | |
| 99 | for _, s := range scenarios { |
| 100 | t.Run(s.name, func(t *testing.T) { |
| 101 | record := core.NewRecord(core.NewAuthCollection("test")) |
| 102 | |
| 103 | if record.ValidatePassword(s.password) { |
| 104 | t.Fatal("[before set] Expected password to be invalid") |
| 105 | } |
| 106 | |
| 107 | record.SetPassword(s.password) |
| 108 | |
| 109 | result := record.ValidatePassword(s.password) |
| 110 | |
| 111 | if result != s.expected { |
| 112 | t.Fatalf("[after set] Expected ValidatePassword %v, got %v", result, s.expected) |
| 113 | } |
| 114 | |
| 115 | // try with a random string to ensure that not any string validates |
| 116 | if record.ValidatePassword(security.PseudorandomString(5)) { |
| 117 | t.Fatal("[random] Expected password to be invalid") |
| 118 | } |
| 119 | }) |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | func TestRecordSetRandomPassword(t *testing.T) { |
| 124 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…