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