Prevents leaking SQL errors in API response

This commit is contained in:
Vlad
2017-09-19 20:32:26 -04:00
parent 697f9ba5bc
commit c3b643df84
2 changed files with 43 additions and 12 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace MailPoet\Test\API\JSON;
use MailPoet\API\JSON\ErrorResponse;
class ErrorResponseTest extends \MailPoetTest {
function testItSanitizesSqlErrorsWhenReturningResponse() {
$errors = array(
'valid error',
'SQLSTATE[22001]: Some SQL error',
'another valid error'
);
$error_response = new ErrorResponse($errors);
expect($error_response->getData())->equals(
array(
'errors' => array(
array(
'error' => 0,
'message' => 'valid error'
),
array(
'error' => 1,
'message' => 'An unknown error occurred.'
),
array(
'error' => 2,
'message' => 'another valid error'
)
)
)
);
}
}