Log-Analyse 26.08. (P1-3): user:cleanup scheiterte tagelang an derselben
E-Mail-Kollision, weil "delete-<mail>" beim zweiten Loeschen derselben
Adresse doppelt vorkam. UserUtil::buildDeletedEmail() haengt die User-ID an
(seit b7e8bbd); die Wiederherstellen-Schaltflaeche entfernt jetzt auch das
neue Praefix (stripDeletePrefix) statt nur "delete-". Tests fuer beide
Formate.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
53 lines
1.9 KiB
PHP
53 lines
1.9 KiB
PHP
<?php
|
|
|
|
use App\Services\UserUtil;
|
|
use App\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
function makeDeletableUser(string $email): User
|
|
{
|
|
return User::forceCreate([
|
|
'email' => $email,
|
|
'password' => bcrypt('secret'),
|
|
'lang' => 'de',
|
|
]);
|
|
}
|
|
|
|
it('pseudonymises the email with the user id so a second deletion does not collide', function () {
|
|
$first = makeDeletableUser('lena.oetjen@googlemail.com');
|
|
UserUtil::deleteUser($first);
|
|
|
|
$second = makeDeletableUser('lena.oetjen@googlemail.com');
|
|
UserUtil::deleteUser($second);
|
|
|
|
expect($first->fresh()->email)->toBe('delete-'.$first->id.'-lena.oetjen@googlemail.com')
|
|
->and($second->fresh()->email)->toBe('delete-'.$second->id.'-lena.oetjen@googlemail.com');
|
|
});
|
|
|
|
it('restores the original address from both prefix formats', function () {
|
|
expect(UserUtil::stripDeletePrefix('delete-1212-lena.oetjen@googlemail.com'))
|
|
->toBe('lena.oetjen@googlemail.com')
|
|
->and(UserUtil::stripDeletePrefix('delete-lena.oetjen@googlemail.com'))
|
|
->toBe('lena.oetjen@googlemail.com')
|
|
->and(UserUtil::stripDeletePrefix('lena.oetjen@googlemail.com'))
|
|
->toBe('lena.oetjen@googlemail.com')
|
|
->and(UserUtil::stripDeletePrefix(null))->toBe('');
|
|
});
|
|
|
|
it('does not double the prefix when a deleted user is deleted again', function () {
|
|
$user = makeDeletableUser('doppelt@example.com');
|
|
UserUtil::deleteUser($user);
|
|
UserUtil::deleteUser($user->fresh());
|
|
|
|
expect($user->fresh()->email)->toBe('delete-'.$user->id.'-doppelt@example.com');
|
|
});
|
|
|
|
it('keeps the pseudonymised email within the column limit', function () {
|
|
$user = makeDeletableUser(str_repeat('a', 240).'@example.com');
|
|
UserUtil::deleteUser($user);
|
|
|
|
expect(mb_strlen($user->fresh()->email))->toBeLessThanOrEqual(255);
|
|
});
|