Skip to content

Commit 97ba1ab

Browse files
committed
Add tests for open_basedir with filename and URI
1 parent fc8b8e2 commit 97ba1ab

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

ext/pdo_sqlite/tests/pdo_sqlite_filename_uri.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ pdo_sqlite
55
--FILE--
66
<?php
77

8-
// create with in-memory database
8+
// create with in-memory database using shared cached
99
$db = new PDO('sqlite:file::memory:?cache=shared');
1010

1111
var_dump($db->exec('CREATE TABLE test1 (id INT);'));
1212

13+
// create second connection to in-memory database
14+
$db = new PDO('sqlite:file::memory:?cache=shared');
15+
16+
var_dump($db->exec('SELECT * from test1'));
17+
1318
// create with default read-write|create mode
1419
$filename = "file:" . __DIR__ . DIRECTORY_SEPARATOR . "pdo_sqlite_filename_uri.db";
1520

@@ -35,6 +40,7 @@ if (file_exists($filename)) {
3540
--EXPECTF--
3641
int(0)
3742
int(0)
43+
int(0)
3844

3945
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in %s
4046
Stack trace:
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
PDO_sqlite: Testing filenames with open_basedir
3+
--EXTENSIONS--
4+
pdo_sqlite
5+
--INI--
6+
open_basedir={TMP}
7+
--FILE--
8+
<?php
9+
10+
// create in basedir
11+
$filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'pdo_sqlite_filename.db';
12+
13+
new PDO('sqlite:' . $filename);
14+
15+
// create outside basedir
16+
$filename = __DIR__ . DIRECTORY_SEPARATOR . 'pdo_sqlite_filename.db';
17+
18+
new PDO('sqlite:' . $filename);
19+
?>
20+
21+
--CLEAN--
22+
<?php
23+
$filenames = [
24+
sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'pdo_sqlite_filename.db',
25+
__DIR__ . DIRECTORY_SEPARATOR . 'pdo_sqlite_filename.db',
26+
];
27+
foreach ($filenames as $filename) {
28+
if (file_exists($filename)) {
29+
unlink($filename);
30+
}
31+
}
32+
?>
33+
--EXPECTF--
34+
Fatal error: Uncaught PDOException: PDO::__construct(): open_basedir restriction in effect. File(%s) is not within the allowed path(s): (%s) in %s:%d
35+
Stack trace:
36+
%s
37+
#1 {main}
38+
39+
Next PDOException: open_basedir prohibits opening %s in %s:%d
40+
Stack trace:
41+
%s
42+
#1 {main}
43+
thrown in %s
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
PDO_sqlite: Testing URIs with open_basedir
3+
--EXTENSIONS--
4+
pdo_sqlite
5+
--INI--
6+
open_basedir={TMP}
7+
--FILE--
8+
<?php
9+
10+
// create in basedir
11+
$filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'pdo_sqlite_filename.db';
12+
13+
new PDO('sqlite:file:' . $filename);
14+
?>
15+
16+
--CLEAN--
17+
<?php
18+
$filenames = [
19+
sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'pdo_sqlite_filename.db',
20+
];
21+
foreach ($filenames as $filename) {
22+
if (file_exists($filename)) {
23+
unlink($filename);
24+
}
25+
}
26+
?>
27+
--EXPECTF--
28+
Fatal error: Uncaught PDOException: open_basedir prohibits opening %s in %s:%d
29+
Stack trace:
30+
%s
31+
#1 {main}
32+
thrown in %s

0 commit comments

Comments
 (0)