Skip to content

Commit de0b8af

Browse files
authored
Filter empty strings from NodeInfo staffAccounts (#2639)
1 parent f3ca90b commit de0b8af

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Ensure NodeInfo accurately represents site administrators to the Fediverse.

integration/class-nodeinfo.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,11 @@ private static function get_staff() {
135135
'orderby' => 'ID',
136136
'order' => 'ASC',
137137
'cap' => 'activitypub',
138-
'fields' => array( 'ID' ),
138+
'fields' => 'ID',
139139
)
140140
);
141+
$admins = array_map( array( Webfinger::class, 'get_user_resource' ), $admins );
141142

142-
return array_map(
143-
static function ( $user ) {
144-
return Webfinger::get_user_resource( $user->ID );
145-
},
146-
$admins
147-
);
143+
return array_values( array_filter( $admins ) );
148144
}
149145
}

tests/phpunit/tests/integration/class-test-nodeinfo.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,31 @@ public function test_methods_are_static() {
363363
}
364364
}
365365

366+
/**
367+
* Test staff accounts do not contain empty strings when user type is disabled.
368+
*
369+
* @covers ::add_nodeinfo_data
370+
* @covers ::get_staff
371+
*/
372+
public function test_nodeinfo_staff_accounts_filters_empty_strings() {
373+
$original_nodeinfo = array(
374+
'protocols' => array(),
375+
'usage' => array(),
376+
'metadata' => array(),
377+
);
378+
379+
// Set blog-only mode, which disables user accounts.
380+
\update_option( 'activitypub_actor_mode', ACTIVITYPUB_BLOG_MODE );
381+
382+
$result = Nodeinfo::add_nodeinfo_data( $original_nodeinfo, '2.0' );
383+
384+
// Check that staffAccounts is an array with no empty strings.
385+
$this->assertIsArray( $result['metadata']['staffAccounts'] );
386+
$this->assertEmpty( $result['metadata']['staffAccounts'], 'Staff accounts should be empty in blog-only mode' );
387+
388+
\delete_option( 'activitypub_actor_mode' );
389+
}
390+
366391
/**
367392
* Test integration with actual WordPress hooks.
368393
*

0 commit comments

Comments
 (0)