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