From a79376175e2fb983f3e367b53b068bc93a53c5ec Mon Sep 17 00:00:00 2001 From: rot1024 Date: Wed, 20 Apr 2022 19:04:27 +0900 Subject: [PATCH] fix: signup api requires password field --- internal/adapter/http/user.go | 4 +- internal/usecase/interactor/user_signup.go | 5 +- .../usecase/interactor/user_signup_test.go | 47 +++++++++---------- internal/usecase/interfaces/user.go | 2 +- 4 files changed, 26 insertions(+), 32 deletions(-) diff --git a/internal/adapter/http/user.go b/internal/adapter/http/user.go index 834d26f4..e71cf91f 100644 --- a/internal/adapter/http/user.go +++ b/internal/adapter/http/user.go @@ -85,12 +85,12 @@ func (c *UserController) Signup(ctx context.Context, input SignupInput) (SignupO Theme: input.Theme, }, }) - } else if input.Name != nil && input.Email != nil && input.Password != nil { + } else if input.Name != nil && input.Email != nil { u, _, err = c.usecase.Signup(ctx, interfaces.SignupParam{ Sub: input.Sub, Name: *input.Name, Email: *input.Email, - Password: *input.Password, + Password: input.Password, Secret: input.Secret, User: interfaces.SignupUserParam{ UserID: input.UserID, diff --git a/internal/usecase/interactor/user_signup.go b/internal/usecase/interactor/user_signup.go index 19cff400..8450a145 100644 --- a/internal/usecase/interactor/user_signup.go +++ b/internal/usecase/interactor/user_signup.go @@ -20,9 +20,6 @@ import ( ) func (i *User) Signup(ctx context.Context, inp interfaces.SignupParam) (*user.User, *user.Team, error) { - if inp.Password == "" { - return nil, nil, interfaces.ErrSignupInvalidPassword - } if inp.Name == "" { return nil, nil, interfaces.ErrSignupInvalidName } @@ -66,7 +63,7 @@ func (i *User) Signup(ctx context.Context, inp interfaces.SignupParam) (*user.Us Email: inp.Email, Name: inp.Name, Sub: auth, - Password: &inp.Password, + Password: inp.Password, Lang: inp.User.Lang, Theme: inp.User.Theme, UserID: inp.User.UserID, diff --git a/internal/usecase/interactor/user_signup_test.go b/internal/usecase/interactor/user_signup_test.go index 8fb19be0..23b7cc52 100644 --- a/internal/usecase/interactor/user_signup_test.go +++ b/internal/usecase/interactor/user_signup_test.go @@ -15,6 +15,7 @@ import ( "github.com/reearth/reearth-backend/internal/usecase/interfaces" "github.com/reearth/reearth-backend/pkg/id" "github.com/reearth/reearth-backend/pkg/user" + "github.com/samber/lo" "github.com/stretchr/testify/assert" "golang.org/x/text/language" ) @@ -47,10 +48,10 @@ func TestUser_Signup(t *testing.T) { signupSecret: "", authSrvUIDomain: "https://reearth.io", args: interfaces.SignupParam{ - Sub: sr("SUB"), + Sub: lo.ToPtr("SUB"), Email: "aaa@bbb.com", Name: "NAME", - Password: "PAss00!!", + Password: lo.ToPtr("PAss00!!"), User: interfaces.SignupUserParam{ UserID: &uid, TeamID: &tid, @@ -88,7 +89,7 @@ func TestUser_Signup(t *testing.T) { args: interfaces.SignupParam{ Email: "aaa@bbb.com", Name: "NAME", - Password: "PAss00!!", + Password: lo.ToPtr("PAss00!!"), User: interfaces.SignupUserParam{ UserID: &uid, TeamID: &tid, @@ -117,10 +118,10 @@ func TestUser_Signup(t *testing.T) { Verification(user.VerificationFrom(mockcode, mocktime, true)). MustBuild(), args: interfaces.SignupParam{ - Sub: sr("SUB"), + Sub: lo.ToPtr("SUB"), Email: "aaa@bbb.com", Name: "NAME", - Password: "PAss00!!", + Password: lo.ToPtr("PAss00!!"), User: interfaces.SignupUserParam{ UserID: &uid, TeamID: &tid, @@ -135,11 +136,11 @@ func TestUser_Signup(t *testing.T) { signupSecret: "", authSrvUIDomain: "", args: interfaces.SignupParam{ - Sub: sr("SUB"), + Sub: lo.ToPtr("SUB"), Email: "aaa@bbb.com", Name: "NAME", - Password: "PAss00!!", - Secret: sr("hogehoge"), + Password: lo.ToPtr("PAss00!!"), + Secret: lo.ToPtr("hogehoge"), User: interfaces.SignupUserParam{ UserID: &uid, TeamID: &tid, @@ -170,11 +171,11 @@ func TestUser_Signup(t *testing.T) { signupSecret: "SECRET", authSrvUIDomain: "", args: interfaces.SignupParam{ - Sub: sr("SUB"), + Sub: lo.ToPtr("SUB"), Email: "aaa@bbb.com", Name: "NAME", - Password: "PAss00!!", - Secret: sr("SECRET"), + Password: lo.ToPtr("PAss00!!"), + Secret: lo.ToPtr("SECRET"), User: interfaces.SignupUserParam{ UserID: &uid, TeamID: &tid, @@ -209,11 +210,11 @@ func TestUser_Signup(t *testing.T) { signupSecret: "SECRET", authSrvUIDomain: "", args: interfaces.SignupParam{ - Sub: sr("SUB"), + Sub: lo.ToPtr("SUB"), Email: "aaa@bbb.com", Name: "NAME", - Password: "PAss00!!", - Secret: sr("SECRET!"), + Password: lo.ToPtr("PAss00!!"), + Secret: lo.ToPtr("SECRET!"), }, wantError: interfaces.ErrSignupInvalidSecret, }, @@ -222,10 +223,10 @@ func TestUser_Signup(t *testing.T) { signupSecret: "SECRET", authSrvUIDomain: "", args: interfaces.SignupParam{ - Sub: sr("SUB"), + Sub: lo.ToPtr("SUB"), Email: "aaa@bbb.com", Name: "NAME", - Password: "PAss00!!", + Password: lo.ToPtr("PAss00!!"), }, wantError: interfaces.ErrSignupInvalidSecret, }, @@ -234,7 +235,7 @@ func TestUser_Signup(t *testing.T) { args: interfaces.SignupParam{ Email: "aaa", Name: "NAME", - Password: "PAss00!!", + Password: lo.ToPtr("PAss00!!"), }, wantError: user.ErrInvalidEmail, }, @@ -243,7 +244,7 @@ func TestUser_Signup(t *testing.T) { args: interfaces.SignupParam{ Email: "aaa@bbb.com", Name: "NAME", - Password: "PAss00", + Password: lo.ToPtr("PAss00"), }, wantError: user.ErrPasswordLength, }, @@ -252,7 +253,7 @@ func TestUser_Signup(t *testing.T) { args: interfaces.SignupParam{ Email: "aaa@bbb.com", Name: "", - Password: "PAss00!!", + Password: lo.ToPtr("PAss00!!"), }, wantError: interfaces.ErrSignupInvalidName, }, @@ -400,7 +401,7 @@ func TestUser_SignupOIDC(t *testing.T) { AccessToken: "accesstoken", Issuer: "https://issuer", Sub: "sub", - Secret: sr("SECRET"), + Secret: lo.ToPtr("SECRET"), User: interfaces.SignupUserParam{ UserID: &uid, TeamID: &tid, @@ -468,7 +469,7 @@ func TestUser_SignupOIDC(t *testing.T) { AccessToken: "accesstoken", Issuer: "https://issuer", Sub: "sub", - Secret: sr("SECRET!"), + Secret: lo.ToPtr("SECRET!"), User: interfaces.SignupUserParam{ UserID: &uid, TeamID: &tid, @@ -543,7 +544,3 @@ func TestIssToURL(t *testing.T) { assert.Equal(t, &url.URL{Scheme: "https", Host: "iss.com", Path: "/hoge"}, issToURL("https://iss.com/hoge", "")) assert.Equal(t, &url.URL{Scheme: "https", Host: "iss.com", Path: "/hoge/foobar"}, issToURL("https://iss.com/hoge", "foobar")) } - -func sr(s string) *string { - return &s -} diff --git a/internal/usecase/interfaces/user.go b/internal/usecase/interfaces/user.go index 79456c69..c3a743bc 100644 --- a/internal/usecase/interfaces/user.go +++ b/internal/usecase/interfaces/user.go @@ -27,7 +27,7 @@ type SignupParam struct { Sub *string // required by Auth0 Email string Name string - Password string + Password *string Secret *string User SignupUserParam }