From fc8b8e29a675977af8b74f17057e6563cddc66e9 Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Wed, 17 Nov 2021 06:02:34 -0600 Subject: [PATCH 1/2] Add pdo_sqlite tests for empty filename and in-memory uri --- .../tests/pdo_sqlite_empty_filename.phpt | 20 +++++++++++++++++++ .../tests/pdo_sqlite_filename_uri.phpt | 6 ++++++ 2 files changed, 26 insertions(+) create mode 100644 ext/pdo_sqlite/tests/pdo_sqlite_empty_filename.phpt diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_empty_filename.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_empty_filename.phpt new file mode 100644 index 0000000000000..8e474feabd30d --- /dev/null +++ b/ext/pdo_sqlite/tests/pdo_sqlite_empty_filename.phpt @@ -0,0 +1,20 @@ +--TEST-- +PDO_sqlite: Testing empty filename +--EXTENSIONS-- +pdo_sqlite +--FILE-- +exec('CREATE TABLE test1 (id INT);')); + +// create with empty URI +$db = new PDO('sqlite:file:?cache=shared'); + +var_dump($db->exec('CREATE TABLE test1 (id INT);')); +?> +--EXPECT-- +int(0) +int(0) diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_filename_uri.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_filename_uri.phpt index a5d588c6b8709..2af37ac46f693 100644 --- a/ext/pdo_sqlite/tests/pdo_sqlite_filename_uri.phpt +++ b/ext/pdo_sqlite/tests/pdo_sqlite_filename_uri.phpt @@ -5,6 +5,11 @@ pdo_sqlite --FILE-- exec('CREATE TABLE test1 (id INT);')); + // create with default read-write|create mode $filename = "file:" . __DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite_filename_uri.db"; @@ -29,6 +34,7 @@ if (file_exists($filename)) { ?> --EXPECTF-- int(0) +int(0) Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in %s Stack trace: From 0f2257699f090e199b6209bd13c614644411484e Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Thu, 18 Nov 2021 08:04:10 -0600 Subject: [PATCH 2/2] Add tests for open_basedir with filename and URI --- .../tests/pdo_sqlite_filename_uri.phpt | 8 +++- .../tests/pdo_sqlite_open_basedir.phpt | 47 +++++++++++++++++++ .../tests/pdo_sqlite_open_basedir_uri.phpt | 32 +++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 ext/pdo_sqlite/tests/pdo_sqlite_open_basedir.phpt create mode 100644 ext/pdo_sqlite/tests/pdo_sqlite_open_basedir_uri.phpt diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_filename_uri.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_filename_uri.phpt index 2af37ac46f693..b972be27cfbf2 100644 --- a/ext/pdo_sqlite/tests/pdo_sqlite_filename_uri.phpt +++ b/ext/pdo_sqlite/tests/pdo_sqlite_filename_uri.phpt @@ -5,11 +5,16 @@ pdo_sqlite --FILE-- exec('CREATE TABLE test1 (id INT);')); +// create second connection to in-memory database +$db = new PDO('sqlite:file::memory:?cache=shared'); + +var_dump($db->exec('SELECT * from test1')); + // create with default read-write|create mode $filename = "file:" . __DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite_filename_uri.db"; @@ -35,6 +40,7 @@ if (file_exists($filename)) { --EXPECTF-- int(0) int(0) +int(0) Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in %s Stack trace: diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_open_basedir.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_open_basedir.phpt new file mode 100644 index 0000000000000..425d2190234bd --- /dev/null +++ b/ext/pdo_sqlite/tests/pdo_sqlite_open_basedir.phpt @@ -0,0 +1,47 @@ +--TEST-- +PDO_sqlite: Testing filenames with open_basedir +--EXTENSIONS-- +pdo_sqlite +--INI-- +open_basedir=. +--FILE-- +exec('CREATE TABLE test1 (id INT);')); + +// create outside basedir +$filename = '..' . DIRECTORY_SEPARATOR . 'pdo_sqlite_filename.db'; + +new PDO('sqlite:' . $filename); +?> + +--CLEAN-- + +--EXPECTF-- +int(0) + +Fatal error: Uncaught PDOException: PDO::__construct(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s) in %s:%d +Stack trace: +%s +#1 {main} + +Next PDOException: open_basedir prohibits opening %s in %s:%d +Stack trace: +%s +#1 {main} + thrown in %s diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_open_basedir_uri.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_open_basedir_uri.phpt new file mode 100644 index 0000000000000..7525ae34a8e86 --- /dev/null +++ b/ext/pdo_sqlite/tests/pdo_sqlite_open_basedir_uri.phpt @@ -0,0 +1,32 @@ +--TEST-- +PDO_sqlite: Testing URIs with open_basedir +--EXTENSIONS-- +pdo_sqlite +--INI-- +open_basedir={TMP} +--FILE-- + + +--CLEAN-- + +--EXPECTF-- +Fatal error: Uncaught PDOException: open_basedir prohibits opening %s in %s:%d +Stack trace: +%s +#1 {main} + thrown in %s