diff --git a/test/functional/pdo_sqlsrv/pdo_test_passwords_with_braces.phpt b/test/functional/pdo_sqlsrv/pdo_test_passwords_with_braces.phpt new file mode 100644 index 00000000..88e54852 --- /dev/null +++ b/test/functional/pdo_sqlsrv/pdo_test_passwords_with_braces.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test passwords with non alphanumeric characters and braces +--DESCRIPTION-- +The first two cases should fail with a message about login failures. Only the last case fails because the right curly brace was not escaped with another right brace. +--ENV-- +PHPT_EXEC=true +--SKIPIF-- + +--FILE-- +getMessage())) { + echo "Expected $error but got:\n"; + var_dump($e->getMessage()); + } +} + +try { + $randomPwd = generateRandomPassword(); + trace($randomPwd . PHP_EOL); + $conn = new PDO("sqlsrv:Server=$server;", $uid, $randomPwd); + + echo "Incorrect password '$randomPwd' with right braces should have failed!" . PHP_EOL; +} catch (PDOException $e) { + $error = '*Login failed for user*'; + if (!fnmatch($error, $e->getMessage())) { + echo "Expected $error but got:\n"; + var_dump($e->getMessage()); + } +} + +try { + $randomPwd = generateRandomPassword(true, false); + trace($randomPwd . PHP_EOL); + $conn = new PDO("sqlsrv:Server=$server;", $uid, $randomPwd); + + echo ("Shouldn't have connected without escaping braces!" . PHP_EOL); +} catch (PDOException $e) { + echo $e->getMessage() . PHP_EOL; +} + +echo "Done" . PHP_EOL; +?> +--EXPECT-- +SQLSTATE[IMSSP]: An unescaped right brace (}) was found in either the user name or password. All right braces must be escaped with another right brace (}}). +Done \ No newline at end of file diff --git a/test/functional/sqlsrv/sqlsrv_test_passwords_with_braces.phpt b/test/functional/sqlsrv/sqlsrv_test_passwords_with_braces.phpt new file mode 100644 index 00000000..50a85c9e --- /dev/null +++ b/test/functional/sqlsrv/sqlsrv_test_passwords_with_braces.phpt @@ -0,0 +1,75 @@ +--TEST-- +Test passwords with non alphanumeric characters and braces +--DESCRIPTION-- +The first two cases should fail with a message about login failures. Only the last case fails because the right curly brace was not escaped with another right brace. +--ENV-- +PHPT_EXEC=true +--SKIPIF-- + +--FILE-- + $userName, "pwd" => $randomPwd)); +checkErrorMessages($conn, 'Password without right braces', $randomPwd); + +$randomPwd = generateRandomPassword(); +trace($randomPwd . PHP_EOL); +$conn = sqlsrv_connect($server, array("UID" => $userName, "pwd" => $randomPwd)); +checkErrorMessages($conn, 'Password with right braces', $randomPwd); + +$randomPwd = generateRandomPassword(true, false); +trace($randomPwd . PHP_EOL); +$conn = sqlsrv_connect($server, array("UID" => $userName, "pwd" => $randomPwd)); +if ($conn) { + echo ("Shouldn't have connected without escaping braces!" . PHP_EOL); +} +$errors = sqlsrv_errors(); +echo $errors[0]["message"] . PHP_EOL; + +echo "Done" . PHP_EOL; +?> +--EXPECT-- +An unescaped right brace (}) was found in either the user name or password. All right braces must be escaped with another right brace (}}). +Done \ No newline at end of file