|
@@ -4,6 +4,56 @@ declare(strict_types=1);
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
|
|
|
|
final class DatabaseDAOTest extends \PHPUnit\Framework\TestCase {
|
|
final class DatabaseDAOTest extends \PHPUnit\Framework\TestCase {
|
|
|
|
|
+ public function test_tablesAreCorrect_withPostgreSQL(): void {
|
|
|
|
|
+ $dsn = getenv('FRESHRSS_TEST_PGSQL_DSN');
|
|
|
|
|
+ if ($dsn === false || $dsn === '') {
|
|
|
|
|
+ self::markTestSkipped('FRESHRSS_TEST_PGSQL_DSN is not configured.');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // A gateway login need not match the PostgreSQL role that owns the tables:
|
|
|
|
|
+ // the DAO relies on grants to the visible tables, not on its own ownership.
|
|
|
|
|
+ $pdo = new Minz_PdoPgsql($dsn, null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
|
|
|
|
|
+ $pdo->setPrefix('test_');
|
|
|
|
|
+ $pdo->beginTransaction();
|
|
|
|
|
+ try {
|
|
|
|
|
+ $pdo->exec(<<<'SQL'
|
|
|
|
|
+ CREATE ROLE freshrss_test_app NOLOGIN;
|
|
|
|
|
+ CREATE SCHEMA freshrss_test_visible;
|
|
|
|
|
+ CREATE SCHEMA freshrss_test_hidden;
|
|
|
|
|
+ SET LOCAL search_path TO freshrss_test_visible;
|
|
|
|
|
+ GRANT USAGE ON SCHEMA freshrss_test_visible, freshrss_test_hidden TO freshrss_test_app;
|
|
|
|
|
+ SQL);
|
|
|
|
|
+ $pdo->exec(<<<'SQL'
|
|
|
|
|
+ CREATE TABLE test_category (id integer);
|
|
|
|
|
+ CREATE TABLE test_feed (id integer);
|
|
|
|
|
+ CREATE TABLE test_entry (id integer);
|
|
|
|
|
+ CREATE TABLE test_entrytmp (id integer);
|
|
|
|
|
+ CREATE TABLE test_tag (id integer);
|
|
|
|
|
+ CREATE TABLE test_entrytag (id integer);
|
|
|
|
|
+ CREATE TABLE another_users_feed (id integer);
|
|
|
|
|
+ GRANT SELECT ON ALL TABLES IN SCHEMA freshrss_test_visible TO freshrss_test_app;
|
|
|
|
|
+ SET LOCAL ROLE freshrss_test_app;
|
|
|
|
|
+ SQL);
|
|
|
|
|
+ $dao = new FreshRSS_DatabaseDAOPGSQL('test', $pdo);
|
|
|
|
|
+ self::assertTrue($dao->tablesAreCorrect(), 'Visible tables may belong to another role.');
|
|
|
|
|
+
|
|
|
|
|
+ $pdo->exec(<<<'SQL'
|
|
|
|
|
+ RESET ROLE;
|
|
|
|
|
+ ALTER TABLE test_feed SET SCHEMA freshrss_test_hidden;
|
|
|
|
|
+ SET LOCAL ROLE freshrss_test_app;
|
|
|
|
|
+ SQL);
|
|
|
|
|
+ self::assertFalse($dao->tablesAreCorrect(), 'A table outside search_path must not hide a missing table.');
|
|
|
|
|
+
|
|
|
|
|
+ $pdo->exec(<<<'SQL'
|
|
|
|
|
+ RESET ROLE;
|
|
|
|
|
+ CREATE VIEW test_feed AS SELECT * FROM freshrss_test_hidden.test_feed;
|
|
|
|
|
+ SET LOCAL ROLE freshrss_test_app;
|
|
|
|
|
+ SQL);
|
|
|
|
|
+ self::assertFalse($dao->tablesAreCorrect(), 'A view must not count as a table.');
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ $pdo->rollBack();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/** @return list<array{string,string,bool,bool}> */
|
|
/** @return list<array{string,string,bool,bool}> */
|
|
|
public static function provideStrilikeCommon(): array {
|
|
public static function provideStrilikeCommon(): array {
|