Skip to content

Commit

Permalink
Fix unit tests when offline
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Dec 29, 2022
1 parent 0992514 commit 9ffdb87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 4 additions & 4 deletions feed-parsers/class-feed-parser-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,20 @@ public function handle_received_activity( $object, $user_id, $type ) {
}
$actor_url = $object['actor'];
$user_feed = false;
if ( \wp_http_validate_url( $actor_url ) ) {
if ( Friends::check_url( $actor_url ) ) {
// Let's check if we follow this actor. If not it might be a different URL representation.
$user_feed = $this->friends_feed->get_user_feed_by_url( $actor_url );
}

if ( is_wp_error( $user_feed ) || ! \wp_http_validate_url( $actor_url ) ) {
if ( is_wp_error( $user_feed ) || ! Friends::check_url( $actor_url ) ) {
$meta = \Activitypub\get_remote_metadata_by_actor( $actor_url );
if ( ! $meta || ! isset( $meta['url'] ) ) {
$this->log( 'Received invalid meta for ' . $actor_url );
return false;
}

$actor_url = $meta['url'];
if ( ! \wp_http_validate_url( $actor_url ) ) {
if ( ! Friends::check_url( $actor_url ) ) {
$this->log( 'Received invalid meta url for ' . $actor_url );
return false;
}
Expand Down Expand Up @@ -321,7 +321,7 @@ private function handle_incoming_post( $object, User_Feed $user_feed ) {
* @param int $user_id The user id.
*/
private function handle_incoming_announce( $url, User_Feed $user_feed, $user_id ) {
if ( ! \wp_http_validate_url( $url ) ) {
if ( ! Friends::check_url( $url ) ) {
$this->log( 'Received invalid announce', compact( 'url' ) );
return false;
}
Expand Down
10 changes: 9 additions & 1 deletion tests/class-friends-testcase-cache-http.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ public function tear_down() {
}

public static function friends_host_is_valid( $return, $host ) {
if ( 'me.local' === $host || 'friend.local' === $host || 'example.org' === $host ) {
if ( in_array(
$host,
array(
'me.local',
'friend.local',
'example.org',
'notiz.blog',
)
) ) {
// Hosts used for test cases.
return $host;
}
Expand Down

0 comments on commit 9ffdb87

Please sign in to comment.