mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2026-11-20 23:43:26 +03:00
thanks @TrapoSAMA
This commit is contained in:
1 parent
a2ee929eda
commit
07b9d500fe
53 files changed
+480
-111
No files matched your search
@@ -165,9 +165,9 @@ class BuildSelectQueryTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
public function testStringConditionIsUsedVerbatim()
|
||||
{
|
||||
$queryparts = $this->newHandler()->callBuildSelectQuery('1=1', []);
|
||||
$queryparts = $this->newHandler()->callBuildSelectQuery('quota > 100', []);
|
||||
|
||||
$this->assertStringContainsString('WHERE ( 1=1 )', $queryparts['from_where_order']);
|
||||
$this->assertStringContainsString('WHERE ( quota > 100 )', $queryparts['from_where_order']);
|
||||
// domain_field scoping still applies on top of the raw string condition
|
||||
$this->assertEquals(['_in_0_0' => 'example.com'], $queryparts['params']);
|
||||
}
|
||||
@@ -235,4 +235,51 @@ class BuildSelectQueryTest extends \PHPUnit\Framework\TestCase
|
||||
$count = db_query_all('SELECT COUNT(*) as c FROM mailbox');
|
||||
$this->assertEquals(3, $count[0]['c'], 'mailbox table must survive the attempted injection intact');
|
||||
}
|
||||
public function testDiscardedSearchPreservesDomainAndUserRestrictions(): void
|
||||
{
|
||||
db_insert('domain', ['domain' => 'outside.example', 'description' => 'outside', 'transport' => 'foo', 'active' => 1, 'backupmx' => 0]);
|
||||
db_insert('mailbox', ['username' => 'outside@outside.example', 'password' => 'x',
|
||||
'name' => 'Outside', 'maildir' => 'outside/', 'local_part' => 'outside',
|
||||
'domain' => 'outside.example', 'active' => 1]);
|
||||
$_SESSION = ['sessid' => ['roles' => ['admin']]];
|
||||
$admin = new MailboxHandler(0, 'admin', true);
|
||||
$this->assertTrue($admin->getList(['unknown' => 'x']));
|
||||
$this->assertCount(3, $admin->result());
|
||||
$this->assertArrayNotHasKey('outside@outside.example', $admin->result());
|
||||
$this->assertSame($admin->getPagebrowser('', []), $admin->getPagebrowser(['unknown' => 'x'], []));
|
||||
|
||||
$_SESSION = ['sessid' => ['roles' => ['user']]];
|
||||
$user = new MailboxnameHandler(0, 'alice@example.com', false);
|
||||
$this->assertTrue($user->getList(['password' => 'x%'], ['password' => 'LIKE']));
|
||||
$this->assertSame(['alice@example.com'], array_keys($user->result()));
|
||||
$this->assertSame($user->getPagebrowser('', []), $user->getPagebrowser(['unknown' => 'x'], []));
|
||||
}
|
||||
|
||||
public function testEmptyStringConditionUsesOnlyDomainRestriction(): void
|
||||
{
|
||||
$parts = $this->newHandler()->callBuildSelectQuery('', []);
|
||||
$this->assertMatchesRegularExpression('/ WHERE\s+domain IN /', $parts['from_where_order']);
|
||||
$this->assertSame(['_in_0_0' => 'example.com'], $parts['params']);
|
||||
$this->assertCount(3, db_query_all($parts['select_cols'] . $parts['from_where_order'], $parts['params']));
|
||||
}
|
||||
|
||||
public function testEmptyStringConditionOmitsWhereForUnscopedHandler(): void
|
||||
{
|
||||
$handler = new class () extends AdminHandler {
|
||||
protected function initStruct()
|
||||
{
|
||||
$this->struct = ['username' => self::pacol(0, 1, 1, 'text', 'admin', '')];
|
||||
}
|
||||
|
||||
public function queryParts(): array
|
||||
{
|
||||
return $this->build_select_query('', []);
|
||||
}
|
||||
};
|
||||
$parts = $handler->queryParts();
|
||||
$this->assertStringNotContainsString(' WHERE ', $parts['from_where_order']);
|
||||
$this->assertSame([], $parts['params']);
|
||||
$this->assertSame([], db_query_all($parts['select_cols'] . $parts['from_where_order'], $parts['params']));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user