Línea 23... |
Línea 23... |
23 |
* @author Andrew Madden <andrewmadden@catalyst-au.net>
|
23 |
* @author Andrew Madden <andrewmadden@catalyst-au.net>
|
24 |
* @copyright 2020 Catalyst IT
|
24 |
* @copyright 2020 Catalyst IT
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
26 |
* @covers \quizaccess_seb\config_key
|
26 |
* @covers \quizaccess_seb\config_key
|
27 |
*/
|
27 |
*/
|
28 |
class config_key_test extends \advanced_testcase {
|
28 |
final class config_key_test extends \advanced_testcase {
|
Línea 29... |
Línea 29... |
29 |
|
29 |
|
30 |
/**
|
30 |
/**
|
31 |
* Test that trying to generate the hash key with bad xml will result in an error.
|
31 |
* Test that trying to generate the hash key with bad xml will result in an error.
|
32 |
*/
|
32 |
*/
|
Línea 51... |
Línea 51... |
51 |
* @param string $hash The correct config key hash for this file.
|
51 |
* @param string $hash The correct config key hash for this file.
|
52 |
*
|
52 |
*
|
53 |
* @dataProvider real_ck_hash_provider
|
53 |
* @dataProvider real_ck_hash_provider
|
54 |
*/
|
54 |
*/
|
55 |
public function test_config_key_hash_is_derived_correctly($config, $hash): void {
|
55 |
public function test_config_key_hash_is_derived_correctly($config, $hash): void {
|
56 |
$xml = file_get_contents(__DIR__ . '/fixtures/' . $config);
|
56 |
$xml = file_get_contents(self::get_fixture_path(__NAMESPACE__, $config));
|
57 |
$derivedhash = config_key::generate($xml)->get_hash();
|
57 |
$derivedhash = config_key::generate($xml)->get_hash();
|
58 |
$this->assertEquals($hash, $derivedhash);
|
58 |
$this->assertEquals($hash, $derivedhash);
|
59 |
}
|
59 |
}
|
Línea 60... |
Línea 60... |
60 |
|
60 |
|
61 |
/**
|
61 |
/**
|
62 |
* Check that the Config Key hash is not altered if the originatorVersion is present in the XML or not.
|
62 |
* Check that the Config Key hash is not altered if the originatorVersion is present in the XML or not.
|
63 |
*/
|
63 |
*/
|
64 |
public function test_presence_of_originator_version_does_not_effect_hash(): void {
|
64 |
public function test_presence_of_originator_version_does_not_effect_hash(): void {
|
65 |
$xmlwithoriginatorversion = file_get_contents(__DIR__ . '/fixtures/simpleunencrypted.seb');
|
65 |
$xmlwithoriginatorversion = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'simpleunencrypted.seb'));
|
66 |
$xmlwithoutoriginatorversion = file_get_contents(__DIR__ . '/fixtures/simpleunencryptedwithoutoriginator.seb');
|
66 |
$xmlwithoutoriginatorversion = file_get_contents(self::get_fixture_path(__NAMESPACE__, 'simpleunencryptedwithoutoriginator.seb'));
|
67 |
$hashwithorigver = config_key::generate($xmlwithoriginatorversion)->get_hash();
|
67 |
$hashwithorigver = config_key::generate($xmlwithoriginatorversion)->get_hash();
|
68 |
$hashwithoutorigver = config_key::generate($xmlwithoutoriginatorversion)->get_hash();
|
68 |
$hashwithoutorigver = config_key::generate($xmlwithoutoriginatorversion)->get_hash();
|
69 |
$this->assertEquals($hashwithorigver, $hashwithoutorigver);
|
69 |
$this->assertEquals($hashwithorigver, $hashwithoutorigver);
|
Línea 70... |
Línea 70... |
70 |
}
|
70 |
}
|
71 |
|
71 |
|
72 |
/**
|
72 |
/**
|
73 |
* Provide a seb file, the expected Config Key and a password if encrypted.
|
73 |
* Provide a seb file, the expected Config Key and a password if encrypted.
|
74 |
*
|
74 |
*
|
75 |
* @return array
|
75 |
* @return array
|
76 |
*/
|
76 |
*/
|
77 |
public function real_ck_hash_provider(): array {
|
77 |
public static function real_ck_hash_provider(): array {
|
78 |
return [
|
78 |
return [
|
79 |
'unencrypted_mac2.1.4' => ['unencrypted_mac_001.seb',
|
79 |
'unencrypted_mac2.1.4' => ['unencrypted_mac_001.seb',
|
80 |
'4fa9af8ec8759eb7c680752ef4ee5eaf1a860628608fccae2715d519849f9292', ''],
|
80 |
'4fa9af8ec8759eb7c680752ef4ee5eaf1a860628608fccae2715d519849f9292', ''],
|