-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve: send expiry mail when user has only valid addresses or to an… (
#344) * Improve: send expiry mail when user has only valid addresses or to any valid when revalidation disabled * Improve: test partly invalid user with revalidation * chore: update test comments * fix: keep behavior without revalidation the same * chore: update changelog to reflect changes
- Loading branch information
1 parent
d939498
commit 4f1491a
Showing
3 changed files
with
26 additions
and
17 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
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 |
---|---|---|
|
@@ -278,25 +278,32 @@ func TestEmailRevalidation(t *testing.T) { | |
|
||
createUser(t, db, 1, "TemporaryInvalid", time.Now().AddDate(-1, -1, -1).Unix(), []string{"[email protected]"}) | ||
createUser(t, db, 2, "PermanentInvalid", time.Now().AddDate(-1, -1, -1).Unix(), []string{"[email protected]"}) | ||
createUser(t, db, 3, "PartlyInvalid", time.Now().AddDate(-1, -1, -1).Unix(), []string{"[email protected]", "[email protected]"}) | ||
|
||
require.NoError(t, runWithTimeout(th.expireAccounts)) | ||
require.NoError(t, runWithTimeout(th.revalidateMails)) | ||
|
||
// Is revalidate_on set for both email addresses? | ||
assert.Equal(t, 2, countRows(t, db, "emails", "revalidate_on IS NOT NULL")) | ||
// Is revalidate_on set for all email addresses? | ||
assert.Equal(t, 3, countRows(t, db, "emails", "revalidate_on IS NOT NULL")) | ||
assert.Equal(t, 0, countRows(t, db, "users", "delete_on IS NOT NULL")) | ||
|
||
// Correct the temporary invalid e-mail address to a valid one, simulating it becoming valid, and 'forward time' | ||
_, err = db.Exec("UPDATE irma.emails SET email = $1, revalidate_on = $2 WHERE id = $3", "[email protected]", time.Now().AddDate(0, 0, -1).Unix(), 1) | ||
require.NoError(t, err) | ||
|
||
// Forward time for the invalid address | ||
_, err = db.Exec("UPDATE irma.emails SET revalidate_on = $1 WHERE id = $2", time.Now().AddDate(0, 0, -1).Unix(), 2) | ||
// Forward time for the invalid addresses | ||
_, err = db.Exec("UPDATE irma.emails SET revalidate_on = $1 WHERE email LIKE $2", time.Now().AddDate(0, 0, -1).Unix(), "%@permenantlyinvalidaddress.com") | ||
require.NoError(t, err) | ||
|
||
// Next revalidation run: the invalid email address should be deleted now | ||
require.NoError(t, runWithTimeout(th.revalidateMails)) | ||
|
||
assert.Equal(t, 1, countRows(t, db, "emails", "")) | ||
assert.Equal(t, 2, countRows(t, db, "emails", "")) | ||
|
||
// Next expireAccounts run: the PartlyInvalid user should be expired since the permanently invalid address is deleted now. | ||
require.NoError(t, runWithTimeout(th.expireAccounts)) | ||
assert.Equal(t, 3, countRows(t, db, "users", "")) | ||
assert.Equal(t, 2, countRows(t, db, "users", "delete_on IS NOT NULL")) | ||
} | ||
|
||
func SetupDatabase(t *testing.T) { | ||
|