1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-22 08:35:57 +01:00

Don't return error when matching empty password.

This avoids displaying "internal server error" when a username
is disabled.
This commit is contained in:
Juliusz Chroboczek 2024-05-02 17:41:50 +02:00
parent e68ff86287
commit b883171f62
2 changed files with 9 additions and 4 deletions

View file

@ -28,7 +28,7 @@ type Password RawPassword
func (p Password) Match(pw string) (bool, error) { func (p Password) Match(pw string) (bool, error) {
switch p.Type { switch p.Type {
case "": case "":
return false, errors.New("missing password") return false, nil
case "plain": case "plain":
if p.Key == nil { if p.Key == nil {
return false, errors.New("missing key") return false, errors.New("missing key")

View file

@ -60,10 +60,10 @@ func TestBad(t *testing.T) {
if match, err := pw4.Match("bad"); err != nil || match { if match, err := pw4.Match("bad"); err != nil || match {
t.Errorf("pw4 matches") t.Errorf("pw4 matches")
} }
if match, err := pw5.Match(""); err == nil || match { if match, err := pw5.Match(""); err != nil || match {
t.Errorf("pw5 matches") t.Errorf("pw5 matches")
} }
if match, err := pw5.Match("bad"); err == nil || match { if match, err := pw5.Match("bad"); err != nil || match {
t.Errorf("pw5 matches") t.Errorf("pw5 matches")
} }
if match, err := pw6.Match("bad"); err == nil || match { if match, err := pw6.Match("bad"); err == nil || match {
@ -72,12 +72,17 @@ func TestBad(t *testing.T) {
} }
func TestEmptyKey(t *testing.T) { func TestEmptyKey(t *testing.T) {
for _, tpe := range []string{"", "plain", "pbkdf2", "bcrypt", "bad"} { for _, tpe := range []string{"plain", "pbkdf2", "bcrypt", "bad"} {
pw := Password{Type: tpe} pw := Password{Type: tpe}
if match, err := pw.Match(""); err == nil || match { if match, err := pw.Match(""); err == nil || match {
t.Errorf("empty password of type %v didn't error", tpe) t.Errorf("empty password of type %v didn't error", tpe)
} }
} }
pw := Password{}
if match, err := pw.Match(""); err != nil || match {
t.Errorf("empty password empty type matched")
}
} }
func TestJSON(t *testing.T) { func TestJSON(t *testing.T) {