From 31901383f38aab091ee1a1ed6886de08e6b18d88 Mon Sep 17 00:00:00 2001 From: pavel-raykov Date: Wed, 10 Apr 2024 10:33:16 +0200 Subject: [PATCH 1/2] Validate user email before asking for a password. --- core/cmd/admin_commands.go | 6 ++++++ core/cmd/admin_commands_test.go | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/cmd/admin_commands.go b/core/cmd/admin_commands.go index 799709ad205..7bde0ec23fb 100644 --- a/core/cmd/admin_commands.go +++ b/core/cmd/admin_commands.go @@ -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" ) @@ -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) diff --git a/core/cmd/admin_commands_test.go b/core/cmd/admin_commands_test.go index f27574f956e..590a24ce8e2 100644 --- a/core/cmd/admin_commands_test.go +++ b/core/cmd/admin_commands_test.go @@ -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", ""}, From e095d90f77b5be2930363aa49241ca4f0cf9cfa1 Mon Sep 17 00:00:00 2001 From: pavel-raykov Date: Wed, 10 Apr 2024 15:32:03 +0200 Subject: [PATCH 2/2] Adding changeset Signed-off-by: pavel-raykov --- .changeset/silver-otters-play.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/silver-otters-play.md diff --git a/.changeset/silver-otters-play.md b/.changeset/silver-otters-play.md new file mode 100644 index 00000000000..433011b5c76 --- /dev/null +++ b/.changeset/silver-otters-play.md @@ -0,0 +1,5 @@ +--- +"chainlink": minor +--- + +Validate user email before asking for a password in the chainlink CLI.