Koha/t/db_dependent/Koha/Encryption.t
Marcel de Rooy f300a7d363 Bug 28998: (follow-up) Check missing encryption key in script and module
Script prints a warning.
Module raises an exception.
Unit test added.

Test plan:
Run t/db_dependent/Koha/Encryption.t
Run t/db_dependent/Koha/Auth/TwoFactorAuth.t
Remove entry and check script.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
2022-05-04 05:18:31 -10:00

18 lines
601 B
Perl
Executable file

use Modern::Perl;
use Test::More tests => 2;
use Test::Exception;
use t::lib::Mocks;
use Koha::Encryption;
t::lib::Mocks::mock_config('encryption_key', 'my secret passphrase');
my $string = 'a string to encrypt';
my $crypt = Koha::Encryption->new;
my $encrypted_string = $crypt->encrypt_hex($string);
is( $crypt->decrypt_hex($encrypted_string), $string, 'Decrypted to original text' );
# Check if exception raised when key is empty or missing
t::lib::Mocks::mock_config('encryption_key', '');
throws_ok { $crypt = Koha::Encryption->new } 'Koha::Exceptions::MissingParameter', 'Exception raised';