-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: apply mailer autoconfirm config to update user email (#1646)
## What kind of change does this PR introduce? * `GOTRUE_MAILER_AUTOCONFIRM` setting should be respected in the update email flow via `PUT /user` ## What is the current behavior? * When `GOTRUE_MAILER_AUTOCONFIRM=true`, updating a user's email still sends an email and requires user confirmation * Difficult for anonymous users to upgrade to a permanent user seamlessly without requiring email confirmation * Fixes #1619 ## What is the new behavior? * When `GOTRUE_MAILER_AUTOCONFIRM=true`, updating a user's email will not require email confirmation. ## Additional context Add any other context or screenshots.
- Loading branch information
1 parent
42c1d45
commit a518505
Showing
3 changed files
with
53 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,7 @@ func (ts *UserTestSuite) TestUserUpdateEmail() { | |
desc string | ||
userData map[string]string | ||
isSecureEmailChangeEnabled bool | ||
isMailerAutoconfirmEnabled bool | ||
expectedCode int | ||
}{ | ||
{ | ||
|
@@ -93,6 +94,7 @@ func (ts *UserTestSuite) TestUserUpdateEmail() { | |
"phone": "", | ||
}, | ||
isSecureEmailChangeEnabled: false, | ||
isMailerAutoconfirmEnabled: false, | ||
expectedCode: http.StatusOK, | ||
}, | ||
{ | ||
|
@@ -102,6 +104,7 @@ func (ts *UserTestSuite) TestUserUpdateEmail() { | |
"phone": "234567890", | ||
}, | ||
isSecureEmailChangeEnabled: true, | ||
isMailerAutoconfirmEnabled: false, | ||
expectedCode: http.StatusOK, | ||
}, | ||
{ | ||
|
@@ -111,6 +114,7 @@ func (ts *UserTestSuite) TestUserUpdateEmail() { | |
"phone": "", | ||
}, | ||
isSecureEmailChangeEnabled: false, | ||
isMailerAutoconfirmEnabled: false, | ||
expectedCode: http.StatusOK, | ||
}, | ||
{ | ||
|
@@ -120,6 +124,17 @@ func (ts *UserTestSuite) TestUserUpdateEmail() { | |
"phone": "", | ||
}, | ||
isSecureEmailChangeEnabled: true, | ||
isMailerAutoconfirmEnabled: false, | ||
expectedCode: http.StatusOK, | ||
}, | ||
{ | ||
desc: "Update email with mailer autoconfirm enabled", | ||
userData: map[string]string{ | ||
"email": "[email protected]", | ||
"phone": "", | ||
}, | ||
isSecureEmailChangeEnabled: true, | ||
isMailerAutoconfirmEnabled: true, | ||
expectedCode: http.StatusOK, | ||
}, | ||
} | ||
|
@@ -146,9 +161,22 @@ func (ts *UserTestSuite) TestUserUpdateEmail() { | |
|
||
w := httptest.NewRecorder() | ||
ts.Config.Mailer.SecureEmailChangeEnabled = c.isSecureEmailChangeEnabled | ||
ts.Config.Mailer.Autoconfirm = c.isMailerAutoconfirmEnabled | ||
ts.API.handler.ServeHTTP(w, req) | ||
require.Equal(ts.T(), c.expectedCode, w.Code) | ||
|
||
var data models.User | ||
require.NoError(ts.T(), json.NewDecoder(w.Body).Decode(&data)) | ||
|
||
if c.isMailerAutoconfirmEnabled { | ||
require.Empty(ts.T(), data.EmailChange) | ||
require.Equal(ts.T(), "[email protected]", data.GetEmail()) | ||
require.Len(ts.T(), data.Identities, 1) | ||
} else { | ||
require.Equal(ts.T(), "[email protected]", data.EmailChange) | ||
require.Len(ts.T(), data.Identities, 0) | ||
} | ||
|
||
// remove user after each case | ||
require.NoError(ts.T(), ts.API.db.Destroy(u)) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters