add signature regex test

This commit is contained in:
Matthias Pfefferle 2023-06-01 08:05:19 +02:00
parent 285925ea08
commit 727aaf1c45
2 changed files with 4 additions and 2 deletions

View file

@ -22,7 +22,7 @@ class Test_Activitypub_Activity extends WP_UnitTestCase {
$activitypub_activity = new \Activitypub\Model\Activity( 'Create' );
$activitypub_activity->from_post( $activitypub_post );
$this->assertContains( \Activitypub\get_rest_url_by_path( 'users/1/followers' ), $activitypub_activity->get_to() );
$this->assertContains( \Activitypub\get_rest_url_by_path( 'users/1/followers' ), $activitypub_activity->get_to() );
$this->assertContains( 'https://example.com/alex', $activitypub_activity->get_cc() );
remove_all_filters( 'activitypub_extract_mentions' );

View file

@ -26,6 +26,8 @@ class Test_Activitypub_Rest_Post_Signature_Verification extends WP_UnitTestCase
$date = gmdate( 'D, d M Y H:i:s T' );
$signature = Activitypub\Signature::generate_signature( 1, 'POST', $remote_actor, $date, $digest );
$this->assertRegExp( '/keyId="http:\/\/example\.org\/\?author=1#main-key",algorithm="rsa-sha256",headers="\(request-target\) host date digest",signature="[^"]*"/', $signature );
// Signed headers
$url_parts = wp_parse_url( $remote_actor );
$route = $url_parts['path'] . '?' . $url_parts['query'];
@ -48,7 +50,7 @@ class Test_Activitypub_Rest_Post_Signature_Verification extends WP_UnitTestCase
// signature_verification
$verified = \openssl_verify( $signed_data, $signature_block['signature'], $public_key, 'rsa-sha256' ) > 0;
$this->assertTRUE( $verified );
$this->assertTrue( $verified );
remove_filter( 'pre_http_request', array( $pre_http_request, 'filter' ), 10 );
}