bug62479.phpt 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. --TEST--
  2. PDO PgSQL Bug #62479 (PDO-psql cannot connect if password contains spaces)
  3. --EXTENSIONS--
  4. pdo
  5. pdo_pgsql
  6. --SKIPIF--
  7. <?php
  8. require __DIR__ . '/config.inc';
  9. require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
  10. PDOTest::skip();
  11. $dsn = getenv('PDOTEST_DSN');
  12. if (empty($dsn)) die('skip no dsn found in env');
  13. $db = PDOTest::test_factory(__DIR__ . '/common.phpt');
  14. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  15. $user = 'pdo_test_'.rand(5, 400);
  16. $pass = 'testpass';
  17. // Assume that if we can't create or drop a user, this test needs to be skipped
  18. try {
  19. $db->exec("DROP USER IF EXISTS $user");
  20. $db->exec("CREATE USER $user WITH PASSWORD '$pass'");
  21. } catch (PDOException $e) {
  22. die("skip You need CREATEUSER permissions to run the test");
  23. }
  24. // Peer authentication might prevent the test from properly running
  25. try {
  26. $testConn = new PDO($dsn, $user, $pass);
  27. } catch (PDOException $e) {
  28. echo "skip ".$e->getMessage();
  29. }
  30. $db->exec("DROP USER $user");
  31. ?>
  32. --FILE--
  33. <?php
  34. require __DIR__ . '/config.inc';
  35. require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
  36. $pdo = PDOTest::test_factory(__DIR__ . '/common.phpt');
  37. $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
  38. $rand = rand(5, 400);
  39. $user = "pdo_test_$rand";
  40. $template = "CREATE USER $user WITH PASSWORD '%s'";
  41. $dropUser = "DROP USER $user";
  42. $testQuery = 'SELECT 1 as verification';
  43. // Create temp user with space in password
  44. $sql = sprintf($template, 'my password');
  45. $pdo->query($sql);
  46. $testConn = new PDO($config['ENV']['PDOTEST_DSN'], $user, "my password");
  47. $result = $testConn->query($testQuery)->fetch();
  48. $check = $result[0];
  49. var_dump($check);
  50. // Remove the user
  51. $pdo->query($dropUser);
  52. // Create a user with a space and single quote
  53. $sql = sprintf($template, "my pass''word");
  54. $pdo->query($sql);
  55. $testConn = new PDO($config['ENV']['PDOTEST_DSN'], $user, "my pass'word");
  56. $result = $testConn->query($testQuery)->fetch();
  57. $check = $result[0];
  58. var_dump($check);
  59. // Remove the user
  60. $pdo->query($dropUser);
  61. ?>
  62. --EXPECT--
  63. int(1)
  64. int(1)