Files
vikunja/pkg/mail/testing.go
T
kolaente 52bcd3e093 fix(user): keep old email active until new one is confirmed
Changing the email no longer overwrites the address and flips the account
to StatusEmailConfirmationRequired. The new address is stored as
pending_email and only applied when the confirm token is used (valid 24h),
so a lost or misaddressed confirmation mail can no longer lock the user
out. The change can be repeated to fix typos, cancelled, or the mail
resent; confirmation mails are throttled to one per minute per user, and
stale change tokens are swept by the cleanup cron.

Fixes #3481
2026-08-18 22:03:38 +02:00

68 lines
1.8 KiB
Go

// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-present Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package mail
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
var (
isUnderTest bool
sentMails []*Opts
)
// Fake stops any mails from being sent and instead allows for recording and querying them.
func Fake() {
isUnderTest = true
sentMails = nil
}
// AssertSent asserts if a mail has been sent
func AssertSent(t *testing.T, opts *Opts) {
var found bool
for _, testMail := range sentMails {
if reflect.DeepEqual(testMail, opts) {
found = true
break
}
}
assert.True(t, found, "Failed to assert mail '%v' has been sent.", opts)
}
// LastSent returns the most recently captured mail when running under Fake(),
// or nil if no mail has been sent. Intended for tests.
func LastSent() *Opts {
if len(sentMails) == 0 {
return nil
}
return sentMails[len(sentMails)-1]
}
// SentMails returns all mails captured since the last reset, in the order they were sent. Intended for tests.
func SentMails() []*Opts {
return sentMails
}
// ResetSent clears the captured mail buffer. Intended for tests.
func ResetSent() {
sentMails = nil
}