Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
gandalftest: fix bug in the createUser handler
Browse files Browse the repository at this point in the history
Adding the user to the list before checking for duplicity is no good.
  • Loading branch information
Francisco Souza committed Feb 19, 2015
1 parent a272881 commit d03ccdf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gandalftest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ func (s *GandalfServer) createUser(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
s.users = append(s.users, usr.Name)
if _, ok := s.keys[usr.Name]; ok {
http.Error(w, "user already exists", http.StatusConflict)
return
}
s.users = append(s.users, usr.Name)
keys := make([]key, 0, len(usr.Keys))
for name, body := range usr.Keys {
keys = append(keys, key{Name: name, Body: body})
Expand Down
1 change: 1 addition & 0 deletions gandalftest/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func (s *S) TestCreateDuplicateUser(c *check.C) {
server.ServeHTTP(recorder, request)
c.Assert(recorder.Code, check.Equals, http.StatusConflict)
c.Assert(recorder.Body.String(), check.Equals, "user already exists\n")
c.Assert(server.Users(), check.DeepEquals, []string{"someuser"})
}

func (s *S) TestRemoveUser(c *check.C) {
Expand Down

0 comments on commit d03ccdf

Please sign in to comment.