New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PDO - support username & password specified in DSN #2684
Changes from all commits
d5748e7
5e1a99e
dd96d1d
cc3f7b1
54e3c49
e6e64e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--TEST-- | ||
PDO Common: Pass credentials in dsn instead of constructor params | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('pdo')) die('skip'); | ||
$dir = getenv('REDIR_TEST_DIR'); | ||
if (false == $dir) die('skip no driver'); | ||
|
||
$driver = substr(getenv('PDOTEST_DSN'), 0, strpos(getenv('PDOTEST_DSN'), ':')); | ||
if (!in_array($driver, array('mssql','sybase','dblib','firebird','mysql','oci'))) | ||
SjonHortensius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
die('skip not supported'); | ||
|
||
require_once $dir . 'pdo_test.inc'; | ||
PDOTest::skip(); | ||
?> | ||
--FILE-- | ||
<?php | ||
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; | ||
|
||
$orgDsn = getenv('PDOTEST_DSN'); | ||
$orgUser = getenv('PDOTEST_USER'); | ||
$orgPass = getenv('PDOTEST_PASS'); | ||
|
||
try | ||
{ | ||
putenv("PDOTEST_DSN=$orgDsn;user=$orgUser;password=$orgPass"); | ||
putenv("PDOTEST_USER"); | ||
putenv("PDOTEST_PASS"); | ||
|
||
$link = PDOTest::factory(); | ||
echo "using credentials in dsn: done\n"; | ||
|
||
|
||
// test b/c - credentials in DSN are ignored when user/pass passed as separate params | ||
putenv("PDOTEST_DSN=$orgDsn;user=incorrect;password=ignored"); | ||
putenv("PDOTEST_USER=$orgUser"); | ||
putenv("PDOTEST_PASS=$orgPass"); | ||
|
||
$link = PDOTest::factory(); | ||
echo "ignoring credentials in dsn: done\n"; | ||
} | ||
finally | ||
{ | ||
putenv("PDOTEST_DSN=$orgDsn"); | ||
putenv("PDOTEST_USER=$orgUser"); | ||
putenv("PDOTEST_PASS=$orgPass"); | ||
} | ||
?> | ||
--EXPECTF-- | ||
using credentials in dsn: done | ||
ignoring credentials in dsn: done |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -458,6 +458,8 @@ static int pdo_dblib_handle_factory(pdo_dbh_t *dbh, zval *driver_options) | |
,{ "dbname", NULL, 0 } | ||
,{ "secure", NULL, 0 } /* DBSETLSECURE */ | ||
,{ "version", NULL, 0 } /* DBSETLVERSION */ | ||
,{ "user", NULL, 0 } | ||
,{ "password", NULL, 0 } | ||
}; | ||
|
||
nvars = sizeof(vars)/sizeof(vars[0]); | ||
|
@@ -519,12 +521,20 @@ static int pdo_dblib_handle_factory(pdo_dbh_t *dbh, zval *driver_options) | |
} | ||
} | ||
|
||
if (!dbh->username && vars[6].optval) { | ||
dbh->username = vars[6].optval; | ||
} | ||
|
||
if (dbh->username) { | ||
if(FAIL == DBSETLUSER(H->login, dbh->username)) { | ||
goto cleanup; | ||
} | ||
} | ||
|
||
if (!dbh->password && vars[7].optval) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be a dumb question (as I'm new here, still trying to make & run tests properly): how will this behave for The same question goes for all other places this test is used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SpyroTEQ Sorry for the long time between replies, as this PR seems inactive. The idea is that if a username and password is set for the constructor to PDO (argument 2 and 3), then it will override the ones sent in the DSN, this is how other PDO drivers did it so I wrote it like that (in this case for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it (sorry from my side too to take so long to answer), but I was actually focusing on how you test that the password has been set in DSN and how you test that password has been set as 3rd argument. What I mean is that In other words, these cases might be worth being tested (or must match the tests used, considering empty/not set values as different):
Maybe this is an absurd question in C code, but in PHP code itself, it's often easy to mistake between empty string, not set string (null), 0-filled string, false literal, etc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SpyroTEQ while that is indeed interesting - it is currently impossible to test like that. We have one valid set of credentials for testing and I don't think it's productive to start issuing |
||
dbh->password = vars[7].optval; | ||
} | ||
|
||
if (dbh->password) { | ||
if(FAIL == DBSETLPWD(H->login, dbh->password)) { | ||
goto cleanup; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be done in a separate PR and then merged to
PHP-7.2
and upwardsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I wouldn't mind; this change isn't necessary for branches that don't parse credentials in the dsn - so it's not really needed, do you disagree? It'll require some git-fu to undo the merge and keep this branch merge-able