MCPcopy
hub / github.com/pocketbase/pocketbase / TestRecordPassword

Function TestRecordPassword

core/record_model_auth_test.go:81–121  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

79}
80
81func 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
123func TestRecordSetRandomPassword(t *testing.T) {
124 t.Parallel()

Callers

nothing calls this directly

Calls 6

ValidatePasswordMethod · 0.95
SetPasswordMethod · 0.95
NewRecordFunction · 0.92
NewAuthCollectionFunction · 0.92
PseudorandomStringFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…