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