Browse Source

Fix rcube::decrypt() (#9264)

* do not skip test_encrypt_and_decrypt test
* Fix rcube::decrypt()
pull/9518/head
Michael Voříšek 2 years ago
committed by Aleksander Machniak
parent
commit
5474761725
  1. 2
      program/lib/Roundcube/rcube.php
  2. 19
      tests/Framework/Rcube.php

2
program/lib/Roundcube/rcube.php

@ -958,7 +958,7 @@ class rcube
$iv_size = openssl_cipher_iv_length($method);
$tag = null;
if (preg_match('/^##(.{16})##/', $cipher, $matches)) {
if (preg_match('/^##(.{16})##/s', $cipher, $matches)) {
$tag = $matches[1];
$cipher = substr($cipher, strlen($matches[0]));
}

19
tests/Framework/Rcube.php

@ -46,21 +46,18 @@ class Framework_Rcube extends PHPUnit\Framework\TestCase
function test_encrypt_and_decrypt()
{
$rcube = rcube::get_instance();
$result = $rcube->decrypt($rcube->encrypt('test'));
$result = $rcube->decrypt($rcube->encrypt('test'));
$this->assertSame('test', $result);
// The following tests fail quite often, therefore we disable them
$this->markTestSkipped();
// Test AEAD cipher method
$defaultCipherMethod = $rcube->config->get('cipher_method');
$rcube->config->set('cipher_method', 'aes-256-gcm');
$result = $rcube->decrypt($rcube->encrypt('test'));
$this->assertSame('test', $result);
// Back to the default
$rcube->config->set('cipher_method', 'DES-EDE3-CBC');
try {
$result = $rcube->decrypt($rcube->encrypt('test'));
$this->assertSame('test', $result);
} finally {
$rcube->config->set('cipher_method', $defaultCipherMethod);
}
}
}
Loading…
Cancel
Save