mirror of
https://github.com/mailcow/mailcow-dockerized.git
synced 2026-11-10 10:31:01 +00:00
[Web][Restic][Dovecot] Backup: safer restic.sh restores, access check first, own aliases and sync sources kept, runner fixes
This commit is contained in:
12 files changed
+169
-24
No files matched your search
@@ -192,7 +192,7 @@ class JobServiceTest extends TestCase
|
||||
// domain admins create mailboxes in their domains, never domains
|
||||
$da = self::domainAdmin();
|
||||
$this->assertSame(['dora@firma.de'], $this->service($da)->restore(self::restore(['mailboxes' => ['dora@firma.de']]))->params['create_mailboxes']);
|
||||
$this->expectUserError(['domain_not_found', 'alt.de'], fn() => $this->service($da)->restore(self::restore(['scope' => 'domain', 'domain' => 'alt.de'])));
|
||||
$this->expectUserError('access_denied', fn() => $this->service($da)->restore(self::restore(['scope' => 'domain', 'domain' => 'alt.de'])));
|
||||
$this->expectUserError('access_denied', fn() => $this->service($da)->restore(self::restore(['mailboxes' => ['x@alt.de']])));
|
||||
}
|
||||
|
||||
@@ -253,6 +253,10 @@ class JobServiceTest extends TestCase
|
||||
// mailboxes and domains of others
|
||||
$this->expectUserError('access_denied', fn() => $this->service($da)->restore(self::restore(['mailboxes' => ['carl@tochter.de']])));
|
||||
$this->expectUserError('access_denied', fn() => $this->service($da)->restore(self::restore(['scope' => 'domain', 'domain' => 'tochter.de'])));
|
||||
// unknown ones look the same
|
||||
$this->expectUserError('access_denied', fn() => $this->service($da)->restore(self::restore(['mailboxes' => ['nobody@tochter.de']])));
|
||||
$this->expectUserError('access_denied', fn() => $this->service($da)->restore(self::restore(['mailboxes' => ['x@nirgends.de']])));
|
||||
$this->expectUserError('access_denied', fn() => $this->service($da)->restore(self::restore(['scope' => 'domain', 'domain' => 'nirgends.de'])));
|
||||
}
|
||||
|
||||
public function testUsersAndReadOnlyKeysCannotRestore(): void
|
||||
@@ -494,8 +498,14 @@ class JobServiceTest extends TestCase
|
||||
$view['result']['mailboxes']['anna@firma.de']['aliases']['errors']);
|
||||
$this->assertSame('restic: Fatal: unable to open repository at …', $view['error']);
|
||||
$this->assertSame("09:00 restore from … by …\n09:01 anna@firma.de done", $view['log']);
|
||||
// and not the account of the admin who requested it
|
||||
$job->requestedBy = 'superuser';
|
||||
$job->log = "09:00 restore job started (requested by superuser)";
|
||||
$view = $this->service(self::domainAdmin())->view($job, true);
|
||||
$this->assertSame(['', '09:00 restore job started (requested by an administrator)'], [$view['requested_by'], $view['log']]);
|
||||
// admins see everything
|
||||
$this->assertSame($job->error, $this->service()->view($job, true)['error']);
|
||||
$this->assertSame('superuser', $this->service()->view($job, true)['requested_by']);
|
||||
}
|
||||
|
||||
public function testADomainAdminRestoresADomainOnceAtATime(): void
|
||||
|
||||
@@ -588,6 +588,31 @@ class RestoreServiceTest extends TestCase
|
||||
$this->assertSame([], $this->groupUpdates);
|
||||
}
|
||||
|
||||
public function testTheOwnAliasOfAnotherMailboxIsLeftAlone(): void
|
||||
{
|
||||
// bob forwarded to anna when the backup was made; info2@ was an alias then and is a mailbox now
|
||||
$this->job(['aliases']);
|
||||
$this->repo->tables['mailbox'][] = self::mailbox('info2@firma.de');
|
||||
$this->repo->tables['alias'][] = ['id' => 5, 'address' => 'info2@firma.de', 'goto' => 'info2@firma.de', 'domain' => 'firma.de', 'active' => 1];
|
||||
$result = $this->merge(self::backup(['aliases' => [
|
||||
['address' => 'bob@firma.de', 'goto' => 'bob@firma.de,anna@firma.de', 'domain' => 'firma.de'],
|
||||
['address' => 'info2@firma.de', 'goto' => 'anna@firma.de', 'domain' => 'firma.de'],
|
||||
]]))['aliases'];
|
||||
$this->assertSame(['bob@firma.de', 'info2@firma.de'], [$this->alias('bob@firma.de')['goto'], $this->alias('info2@firma.de')['goto']]);
|
||||
$this->assertSame(['added' => 0, 'skipped' => 2], array_slice($result, 0, 2));
|
||||
}
|
||||
|
||||
public function testASyncJobUsesItsSourceOnlyWhileTheMailboxMayUseIt(): void
|
||||
{
|
||||
// source 2 no longer covers firma.de since the backup
|
||||
$this->job(['syncjobs']);
|
||||
$this->repo->tables['imapsync_source_domain'] = [];
|
||||
$result = $this->merge(self::backup(['imapsync' => [['user1' => 'anna@legacy.de', 'source_id' => 2, 'source_host1' => 'imap.legacy.de',
|
||||
'source_port1' => 143, 'mins_interval' => 60]]]))['syncjobs'];
|
||||
$this->assertSame([], $this->repo->rows('imapsync', ['user1' => 'anna@legacy.de']));
|
||||
$this->assertSame(['anna@legacy.de (imap.legacy.de:143): sync source does not exist'], $result['errors']);
|
||||
}
|
||||
|
||||
public function testAliasLimitAndAddressesInUse(): void
|
||||
{
|
||||
$this->job(['aliases']);
|
||||
|
||||
Reference in new issue
Block a user