Skip to content

Commit

Permalink
Validate user email before asking for a password.
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-raykov committed Apr 10, 2024
1 parent 6508a4e commit 3190138
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions core/cmd/admin_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

cutils "github.com/smartcontractkit/chainlink-common/pkg/utils"

"github.com/smartcontractkit/chainlink/v2/core/sessions"
"github.com/smartcontractkit/chainlink/v2/core/utils"
"github.com/smartcontractkit/chainlink/v2/core/web/presenters"
)
Expand Down Expand Up @@ -195,6 +196,11 @@ func (s *Shell) ListUsers(_ *cli.Context) (err error) {

// CreateUser creates a new user by prompting for email, password, and role
func (s *Shell) CreateUser(c *cli.Context) (err error) {
// Check user's email validity. Note that it will also be later checked on the server side in the NewUser function.
if err = sessions.ValidateEmail(c.String("email")); err != nil {
return err
}

resp, err := s.HTTP.Get(s.ctx(), "/v2/users/", nil)
if err != nil {
return s.errorOut(err)
Expand Down
4 changes: 2 additions & 2 deletions core/cmd/admin_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func TestShell_CreateUser(t *testing.T) {
role string
err string
}{
{"Invalid request", "//", "", "parseResponse error"},
{"No params", "", "", "Invalid role"},
{"Invalid email", "//", "", "mail: missing '@' or angle-addr"},
{"No params", "", "", "Must enter an email"},
{"No email", "", "view", "Must enter an email"},
{"User exists", cltest.APIEmailAdmin, "admin", fmt.Sprintf(`user with email %s already exists`, cltest.APIEmailAdmin)},
{"Valid params", cltest.MustRandomUser(t).Email, "view", ""},
Expand Down

0 comments on commit 3190138

Please sign in to comment.