Skip to content

Commit 2152660

Browse files
committed
Make decrypt-failure-uniform.phpt resilient to CI OpenSSL noise.
Silence display errors and allow optional STDERR between assertions so PHPUnit PHPT runs do not fail when OpenSSL writes padding diagnostics.
1 parent d36c9e0 commit 2152660

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

tests/decrypt-failure-uniform.phpt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@
22
Decrypt failures always surface a single Exception / message (no oracle)
33
--FILE--
44
<?php
5+
/*
6+
* PHPUnit runs PHPT jobs with display_errors=1 and redirects STDERR to STDOUT.
7+
* OpenSSL may write padding/decoding diagnostics to STDERR on some platforms
8+
* (notably Linux CI). Silence PHP display noise and use %A in EXPECTF so any
9+
* interleaved STDERR text does not fail the oracle assertions.
10+
*/
11+
error_reporting(0);
12+
ini_set('display_errors', '0');
13+
514
require(dirname(__FILE__) . '/../xmlseclibs.php');
615
use RobRichards\XMLSecLibs\XMLSecurityKey;
716

817
/**
918
* Assert a decrypt failure is exactly Exception("Failure decrypting Data").
1019
* Distinct exception classes/messages would form a ciphertext-validity oracle.
1120
*/
12-
function expectDecryptFailure($label, XMLSecurityKey $key, $data) {
21+
function expectDecryptFailure($label, $key, $data) {
1322
try {
1423
$key->decryptData($data);
1524
echo "$label: unexpected success\n";
1625
} catch (Exception $e) {
17-
$ok = (get_class($e) === 'Exception' && $e->getMessage() === XMLSecurityKey::DECRYPTION_FAILURE);
26+
$ok = (get_class($e) === 'Exception'
27+
&& $e->getMessage() === XMLSecurityKey::DECRYPTION_FAILURE);
1828
echo "$label: ".($ok ? "uniform" : (get_class($e)." | ".$e->getMessage()))."\n";
1929
} catch (Throwable $e) {
2030
echo "$label: ".get_class($e)." | ".$e->getMessage()."\n";
@@ -60,11 +70,11 @@ $pt = $ok->decryptData($ct);
6070
echo "ROUNDTRIP: ".($pt === 'hello' ? 'ok' : 'fail')."\n";
6171
?>
6272
--EXPECTF--
63-
CBC_LEN: uniform
64-
CBC_PAD: uniform
65-
CBC_EMPTY: uniform
66-
GCM_TAG: uniform
67-
RSA_OAEP_BAD: uniform
68-
RSA_OAEP_SHORT: uniform
69-
RSA15_BAD: uniform
73+
CBC_LEN: uniform%A
74+
CBC_PAD: uniform%A
75+
CBC_EMPTY: uniform%A
76+
GCM_TAG: uniform%A
77+
RSA_OAEP_BAD: uniform%A
78+
RSA_OAEP_SHORT: uniform%A
79+
RSA15_BAD: uniform%A
7080
ROUNDTRIP: ok

0 commit comments

Comments
 (0)