2021-12-22 10:01:45 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/constants"
|
2021-12-23 05:01:52 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/db"
|
2021-12-22 10:01:45 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
2022-05-30 03:49:55 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/memorystore"
|
2021-12-22 10:01:45 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/resolvers"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
func signupTests(t *testing.T, s TestSetup) {
|
|
|
|
t.Helper()
|
2021-12-24 00:57:39 +00:00
|
|
|
t.Run(`should complete the signup and check duplicates`, func(t *testing.T) {
|
|
|
|
_, ctx := createContext(s)
|
|
|
|
email := "signup." + s.TestInfo.Email
|
2022-01-17 06:02:13 +00:00
|
|
|
res, err := resolvers.SignupResolver(ctx, model.SignUpInput{
|
2021-12-24 00:57:39 +00:00
|
|
|
Email: email,
|
|
|
|
Password: s.TestInfo.Password,
|
|
|
|
ConfirmPassword: s.TestInfo.Password + "s",
|
|
|
|
})
|
2022-03-17 10:05:07 +00:00
|
|
|
assert.NotNil(t, err, "invalid password")
|
2023-03-29 01:36:33 +00:00
|
|
|
assert.Nil(t, res)
|
2022-03-17 10:05:07 +00:00
|
|
|
res, err = resolvers.SignupResolver(ctx, model.SignUpInput{
|
|
|
|
Email: email,
|
|
|
|
Password: "test",
|
|
|
|
ConfirmPassword: "test",
|
|
|
|
})
|
|
|
|
assert.NotNil(t, err, "invalid password")
|
2023-03-29 01:36:33 +00:00
|
|
|
assert.Nil(t, res)
|
2022-05-30 07:17:50 +00:00
|
|
|
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyDisableSignUp, true)
|
2022-01-17 06:02:13 +00:00
|
|
|
res, err = resolvers.SignupResolver(ctx, model.SignUpInput{
|
2021-12-24 00:57:39 +00:00
|
|
|
Email: email,
|
|
|
|
Password: s.TestInfo.Password,
|
|
|
|
ConfirmPassword: s.TestInfo.Password,
|
|
|
|
})
|
2022-03-17 10:05:07 +00:00
|
|
|
assert.NotNil(t, err, "singup disabled")
|
2023-03-29 01:36:33 +00:00
|
|
|
assert.Nil(t, res)
|
2022-05-30 07:17:50 +00:00
|
|
|
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyDisableSignUp, false)
|
2022-03-17 10:05:07 +00:00
|
|
|
res, err = resolvers.SignupResolver(ctx, model.SignUpInput{
|
|
|
|
Email: email,
|
|
|
|
Password: s.TestInfo.Password,
|
|
|
|
ConfirmPassword: s.TestInfo.Password,
|
2023-10-14 12:36:29 +00:00
|
|
|
AppData: map[string]interface{}{
|
|
|
|
"test": "test",
|
|
|
|
},
|
2022-03-17 10:05:07 +00:00
|
|
|
})
|
|
|
|
assert.Nil(t, err, "signup should be successful")
|
2021-12-24 00:57:39 +00:00
|
|
|
user := *res.User
|
|
|
|
assert.Equal(t, email, user.Email)
|
2023-10-14 12:36:29 +00:00
|
|
|
assert.Equal(t, "test", user.AppData["test"])
|
2021-12-24 00:57:39 +00:00
|
|
|
assert.Nil(t, res.AccessToken, "access token should be nil")
|
2022-01-17 06:02:13 +00:00
|
|
|
res, err = resolvers.SignupResolver(ctx, model.SignUpInput{
|
2021-12-24 00:57:39 +00:00
|
|
|
Email: email,
|
|
|
|
Password: s.TestInfo.Password,
|
|
|
|
ConfirmPassword: s.TestInfo.Password,
|
|
|
|
})
|
|
|
|
assert.NotNil(t, err, "should throw duplicate email error")
|
2023-03-29 01:36:33 +00:00
|
|
|
assert.Nil(t, res)
|
2022-07-10 16:19:33 +00:00
|
|
|
verificationRequest, err := db.Provider.GetVerificationRequestByEmail(ctx, email, constants.VerificationTypeBasicAuthSignup)
|
2021-12-24 00:57:39 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, email, verificationRequest.Email)
|
|
|
|
cleanData(email)
|
2021-12-23 05:01:52 +00:00
|
|
|
})
|
|
|
|
}
|