forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix phpGH-12423: Changed to prioritize DSN authentication information…
… over arguments. Added connection test Close phpGH-12424
- Loading branch information
1 parent
5465cea
commit b5c287e
Showing
4 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--TEST-- | ||
GitHub #12424 (Fix GH-12423: [pdo_pgsql] Changed to prioritize DSN authentication information over arguments.) | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded'); | ||
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; | ||
require __DIR__ . '/config.inc'; | ||
PDOTest::skip(); | ||
?> | ||
--FILE-- | ||
<?php | ||
require __DIR__ . '/config.inc'; | ||
|
||
[ | ||
'ENV' => [ | ||
'PDOTEST_DSN' => $dsnWithCredentials, | ||
'PDOTEST_USER' => $user, | ||
'PDOTEST_PASS' => $password, | ||
], | ||
] = __DIR__ . '/common.phpt'; | ||
|
||
$dsn = str_replace(" user={$user} password={$password}", '', $dsnWithCredentials); | ||
|
||
echo "dsn without credentials / correct user / correct password\n"; | ||
try { | ||
$db = new PDO($dsn, $user, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); | ||
echo "Connected.\n\n"; | ||
} catch (PDOException $e) { | ||
echo $e->getMessage(); | ||
} | ||
|
||
echo "dsn with credentials / no user / no password\n"; | ||
try { | ||
$db = new PDO("{$dsn} user={$user} password={$password}", null, null, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); | ||
echo "Connected.\n\n"; | ||
} catch (PDOException $e) { | ||
echo $e->getMessage(); | ||
} | ||
|
||
echo "dsn with correct user / incorrect user / correct password\n"; | ||
try { | ||
$db = new PDO("{$dsn} user={$user}", 'hoge', $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); | ||
echo "Connected.\n\n"; | ||
} catch (PDOException $e) { | ||
echo $e->getMessage(); | ||
} | ||
|
||
echo "dsn with correct password / correct user / incorrect password\n"; | ||
try { | ||
$db = new PDO("{$dsn} password={$password}", $user, 'fuga', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); | ||
echo "Connected.\n\n"; | ||
} catch (PDOException $e) { | ||
echo $e->getMessage(); | ||
} | ||
|
||
echo "dsn with correct credentials / incorrect user / incorrect password\n"; | ||
try { | ||
$db = new PDO("{$dsn} user={$user} password={$password}", 'hoge', 'fuga', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); | ||
echo "Connected.\n"; | ||
} catch (PDOException $e) { | ||
echo $e->getMessage(); | ||
} | ||
?> | ||
--EXPECT-- | ||
dsn without credentials / correct user / correct password | ||
Connected. | ||
|
||
dsn with credentials / no user / no password | ||
Connected. | ||
|
||
dsn with correct user / incorrect user / correct password | ||
Connected. | ||
|
||
dsn with correct password / correct user / incorrect password | ||
Connected. | ||
|
||
dsn with correct credentials / incorrect user / incorrect password | ||
Connected. |