Skip to content

unit tests Encryption_test::test_initialize_encrypt_decrypt fails with OpenSSL3 #6171

Closed

Description

@tenzap

running the unit tests of CI3 leads to 1 error and 9 deprecation notices:

Deprecation notices:

There were 9 errors:

1) URI_test::test_filter_uri_passing
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property URI_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41
PHP Deprecated:  Creation of dynamic property Mock_Core_URI::$config is deprecated in /path_to_ci/CodeIgniter/tests/mocks/core/uri.php on line 19
PHP Deprecated:  Creation of dynamic property URI_test::$uri is deprecated in /path_to_ci/CodeIgniter/tests/codeigniter/core/URI_test.php on line 7

2) URI_test::test_filter_uri_throws_error
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property URI_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41
PHP Deprecated:  Creation of dynamic property Mock_Core_URI::$config is deprecated in /path_to_ci/CodeIgniter/tests/mocks/core/uri.php on line 19
PHP Deprecated:  Creation of dynamic property URI_test::$uri is deprecated in /path_to_ci/CodeIgniter/tests/codeigniter/core/URI_test.php on line 7

3) Utf8_test::test___constructUTF8_ENABLED
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property Utf8_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41

4) Utf8_test::test__constructUTF8_DISABLED
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property Utf8_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41

5) Utf8_test::test_is_ascii
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property Utf8_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41

6) Utf8_test::test_convert_to_utf8
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property Utf8_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41

7) Text_helper_test::test_highlight_phrase
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property Text_helper_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41

8) Url_helper_test::test_url_title
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property Url_helper_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41

9) Url_helper_test::test_url_title_extra_dashes
PHPUnit\Framework\Exception: PHP Deprecated:  Creation of dynamic property Url_helper_test::$ci_view_root is deprecated in /path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php on line 41

--

Failures

There was 1 failure:

1) Encryption_test::test_initialize_encrypt_decrypt
Failed asserting that false matches expected 'This is a plain-text message.'.

/path_to_ci/CodeIgniter/tests/codeigniter/libraries/Encryption_test.php:212
/path_to_ci/CodeIgniter/tests/mocks/ci_testcase.php:351

ERRORS!
Tests: 337, Assertions: 1076, Errors: 9, Failures: 1, Skipped: 25.

Activity

  1. tenzap commented on Nov 6, 2022

    @tenzap
    ContributorAuthor

    PR #6173 fixes the deprecation warnings.
    However, concerning the failure, it is different, so I will rename the title so that it is related to OpenSSL3.

    With OpenSSL3, some ciphers are not available anymore when the legacy
    provider is not enabled. Especially, 'des' cypher is provided by the legacy
    provider in OpenSSL3, and the legacy provider is not enabled by default.

    This leads to the failure of Encryption_test::test_initialize_encrypt_decrypt test.

    See: https://wiki.openssl.org/index.php/OpenSSL_3.0#Providers

    The legacy provider. This is a collection of legacy algorithms that are either no longer in common use or strongly discouraged from use. However some applications may need to use these algorithms for backwards compatibility reasons. This provider is NOT loaded by default. This may mean that some applications upgrading from earlier versions of OpenSSL may find that some algorithms are no longer available unless they load the legacy provider explicitly. Algorithms in the legacy provider include MD2, MD4, MDC2, RMD160, CAST5, BF (Blowfish), IDEA, SEED, RC2, RC4, RC5 and DES (but not 3DES).

    Since the test uses

    $this->encryption->initialize(array('cipher' => 'des', 'mode' => 'ecb', 'key' => substr($key, 0, 8)));
    

    it fails.

    So a solution would be to use another cipher: "tripledes" instead of "des"

    --- a/tests/codeigniter/libraries/Encryption_test.php
    +++ b/tests/codeigniter/libraries/Encryption_test.php
    @@ -208,7 +208,7 @@ class Encryption_test extends CI_TestCase {
     		$this->assertEquals($message, $this->encryption->decrypt($this->encryption->encrypt($message)));
     
     		// Try DES in ECB mode, just for the sake of changing stuff
    -		$this->encryption->initialize(array('cipher' => 'des', 'mode' => 'ecb', 'key' => substr($key, 0, 8)));
    +		$this->encryption->initialize(array('cipher' => 'tripledes', 'mode' => 'ecb', 'key' => substr($key, 0, 8)));
     		$this->assertEquals($message, $this->encryption->decrypt($this->encryption->encrypt($message)));
     	}
     
  2. changed the title [-]unit tests with php8.2 failures[/-] [+]unit tests Encryption_test::test_initialize_encrypt_decrypt files with OpenSSL3[/+] on Nov 6, 2022
  3. changed the title [-]unit tests Encryption_test::test_initialize_encrypt_decrypt files with OpenSSL3[/-] [+]unit tests Encryption_test::test_initialize_encrypt_decrypt fails with OpenSSL3[/+] on Nov 6, 2022
  4. tenzap commented on Jun 24, 2023

    @tenzap
    ContributorAuthor

    Another solution which would make it work for both openssl 1 & 3

    --- a/tests/codeigniter/libraries/Encryption_test.php
    +++ b/tests/codeigniter/libraries/Encryption_test.php
    @@ -208,7 +208,11 @@
     		$this->assertEquals($message, $this->encryption->decrypt($this->encryption->encrypt($message)));
     
     		// Try DES in ECB mode, just for the sake of changing stuff
    -		$this->encryption->initialize(array('cipher' => 'des', 'mode' => 'ecb', 'key' => substr($key, 0, 8)));
    +		if(OPENSSL_VERSION_NUMBER >= 0x3000000f) {
    +			$this->encryption->initialize(array('cipher' => 'tripledes', 'mode' => 'ecb', 'key' => substr($key, 0, 8)));
    +		} else {
    +			$this->encryption->initialize(array('cipher' => 'des', 'mode' => 'ecb', 'key' => substr($key, 0, 8)));
    +		}
     		$this->assertEquals($message, $this->encryption->decrypt($this->encryption->encrypt($message)));
     	}
     
    
  5. gxgpet commented on Jan 14, 2024

    @gxgpet
    Contributor

    Fixed via #6261.

    We might consider the OpenSSL version/similar solution in the future, but for now, I marked the test as skipped for older PHP versions only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions