1
1
--TEST--
2
2
GitHub #12424 (Fix GH-12423: [pdo_pgsql] Changed to prioritize DSN authentication information over arguments.)
3
+ --EXTENSIONS--
4
+ pdo
5
+ pdo_pgsql
3
6
--SKIPIF--
4
7
<?php
5
- if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
6
8
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
7
9
require __DIR__ . '/config.inc';
10
+ if (strpos($config['ENV']['PDOTEST_DSN'], 'password=') === false && !isset($config['ENV']['PDOTEST_PASS'])) {
11
+ die('skip no password');
12
+ }
8
13
PDOTest::skip();
9
14
?>
10
15
--FILE--
@@ -15,53 +20,55 @@ $dsnWithCredentials = $config['ENV']['PDOTEST_DSN'];
15
20
$user = $config['ENV']['PDOTEST_USER'] ?? null;
16
21
$password = $config['ENV']['PDOTEST_PASS'] ?? null;
17
22
if (!$user) {
18
- preg_match('/user=(. *?) /', $dsnWithCredentials, $match);
23
+ preg_match('/user=([^ ] *?)/', $dsnWithCredentials, $match);
19
24
$user = $match[1] ?? '';
20
25
}
21
26
if (!$password) {
22
- preg_match('/password=(. *?)$ /', $dsnWithCredentials, $match);
27
+ preg_match('/password=([^ ] *?)/', $dsnWithCredentials, $match);
23
28
$password = $match[1] ?? '';
24
29
}
25
- $dsn = str_replace(" user={$user} password={$password}", '', $dsnWithCredentials);
30
+ $dsn = str_replace("user={$user}", '', $dsnWithCredentials);
31
+ $dsn = str_replace("password={$password}", '', $dsn);
32
+ $dsn = rtrim($dsn);
26
33
27
34
echo "dsn without credentials / correct user / correct password\n";
28
35
try {
29
36
$db = new PDO($dsn, $user, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
30
37
echo "Connected.\n\n";
31
38
} catch (PDOException $e) {
32
- echo $e->getMessage();
39
+ echo $e->getMessage()."\n" ;
33
40
}
34
41
35
42
echo "dsn with credentials / no user / no password\n";
36
43
try {
37
44
$db = new PDO("{$dsn} user={$user} password={$password}", null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
38
45
echo "Connected.\n\n";
39
46
} catch (PDOException $e) {
40
- echo $e->getMessage();
47
+ echo $e->getMessage()."\n" ;
41
48
}
42
49
43
50
echo "dsn with correct user / incorrect user / correct password\n";
44
51
try {
45
52
$db = new PDO("{$dsn} user={$user}", 'hoge', $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
46
53
echo "Connected.\n\n";
47
54
} catch (PDOException $e) {
48
- echo $e->getMessage();
55
+ echo $e->getMessage()."\n" ;
49
56
}
50
57
51
58
echo "dsn with correct password / correct user / incorrect password\n";
52
59
try {
53
60
$db = new PDO("{$dsn} password={$password}", $user, 'fuga', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
54
61
echo "Connected.\n\n";
55
62
} catch (PDOException $e) {
56
- echo $e->getMessage();
63
+ echo $e->getMessage()."\n" ;
57
64
}
58
65
59
66
echo "dsn with correct credentials / incorrect user / incorrect password\n";
60
67
try {
61
68
$db = new PDO("{$dsn} user={$user} password={$password}", 'hoge', 'fuga', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
62
69
echo "Connected.\n";
63
70
} catch (PDOException $e) {
64
- echo $e->getMessage();
71
+ echo $e->getMessage()."\n" ;
65
72
}
66
73
?>
67
74
--EXPECT--
0 commit comments