Skip to content

Commit

Permalink
Merge pull request #658 from ericchiang/dev-dont-error-on-invalid-use…
Browse files Browse the repository at this point in the history
…rname

*: don't error out if a username doesn't exist in the backing connector
  • Loading branch information
ericchiang authored Nov 1, 2016
2 parents 90e613b + 57a59d4 commit 799b3f3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
9 changes: 7 additions & 2 deletions connector/ldap/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ func (c *ldapConnector) Login(username, password string) (ident connector.Identi

switch n := len(resp.Entries); n {
case 0:
return fmt.Errorf("ldap: no results returned for filter: %q", filter)
log.Printf("ldap: no results returned for filter: %q", filter)
incorrectPass = true
return nil
case 1:
default:
return fmt.Errorf("ldap: filter returned multiple (%d) results: %q", n, filter)
Expand All @@ -335,6 +337,9 @@ func (c *ldapConnector) Login(username, password string) (ident connector.Identi
if err != nil {
return connector.Identity{}, false, err
}
if incorrectPass {
return connector.Identity{}, false, nil
}

// Encode entry for follow up requests such as the groups query and
// refresh attempts.
Expand Down Expand Up @@ -364,7 +369,7 @@ func (c *ldapConnector) Login(username, password string) (ident connector.Identi
return connector.Identity{}, false, err
}

return ident, !incorrectPass, nil
return ident, true, nil
}

func (c *ldapConnector) Groups(ident connector.Identity) ([]string, error) {
Expand Down
3 changes: 2 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,9 @@ func (db passwordDB) Login(email, password string) (connector.Identity, bool, er
if err != nil {
if err != storage.ErrNotFound {
log.Printf("get password: %v", err)
return connector.Identity{}, false, err
}
return connector.Identity{}, false, err
return connector.Identity{}, false, nil
}
if err := bcrypt.CompareHashAndPassword(p.Hash, []byte(password)); err != nil {
return connector.Identity{}, false, nil
Expand Down
8 changes: 4 additions & 4 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,10 @@ func TestPasswordDB(t *testing.T) {
},
},
{
name: "unknown user",
username: "john@example.com",
password: pw,
wantErr: true,
name: "unknown user",
username: "john@example.com",
password: pw,
wantInvalid: true,
},
{
name: "invalid password",
Expand Down

0 comments on commit 799b3f3

Please sign in to comment.