Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate user email before asking for a password. #12767

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading