assertSame( $digest, HTTPSig::generate_digest_header($text) ); } public static function generate_digestProvider() { return [ 'empty body text' => [ '', 'SHA-256=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=' ], 'sample body text' => [ 'body text', 'SHA-256=2fu8kUkvuzuo5XyhWwORNOcJgDColXgxWkw1T5EXzPI=' ], 'NULL body text' => [ null, 'SHA-256=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=' ], ]; } function testGeneratedDigestsOfDifferentTextShouldNotBeEqual() { $this->assertNotSame( HTTPSig::generate_digest_header('text1'), HTTPSig::generate_digest_header('text2') ); } function testDecrypt_sigheader() { $header = 'Header: iv="value_iv" key="value_key" alg="value_alg" data="value_data"'; $result = [ 'encrypted' => true, 'iv' => 'value_iv', 'key' => 'value_key', 'alg' => 'value_alg', 'data' => 'value_data' ]; $this->assertSame($result, HTTPSig::decrypt_sigheader($header, 'site private key')); } function testDecrypt_sigheaderUseSitePrivateKey() { // Initialize config with a known value for test \Zotlabs\Lib\Config::Set('system', 'prvkey', 'system.prvkey'); $header = 'Header: iv="value_iv" key="value_key" alg="value_alg" data="value_data"'; $result = [ 'encrypted' => true, 'iv' => 'value_iv', 'key' => 'value_key', 'alg' => 'value_alg', 'data' => 'value_data' ]; $this->assertSame($result, HTTPSig::decrypt_sigheader($header)); } function testDecrypt_sigheaderIncompleteHeaderShouldReturnEmptyString() { $header = 'Header: iv="value_iv" key="value_key"'; $this->assertEmpty(HTTPSig::decrypt_sigheader($header, 'site private key')); } }