Skip to content

Commit

Permalink
Validate user email before asking for a password. (#12767)
Browse files Browse the repository at this point in the history
* Validate user email before asking for a password.

* Adding changeset

Signed-off-by: pavel-raykov <pavel.raykov@smartcontract.com>

---------

Signed-off-by: pavel-raykov <pavel.raykov@smartcontract.com>
  • Loading branch information
pavel-raykov committed Apr 10, 2024
1 parent 0144587 commit 8db5ccf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-otters-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

Validate user email before asking for a password in the chainlink CLI.
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 8db5ccf

Please sign in to comment.