[buddypress-trac] [BuddyPress Trac] #7658: User is de-authenticated when making REST API request

buddypress-trac noreply at wordpress.org
Wed Jun 5 19:02:53 UTC 2024


#7658: User is de-authenticated when making REST API request
--------------------------+---------------------
 Reporter:  dcavins       |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  14.0.0
Component:  Core          |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |
--------------------------+---------------------

Comment (by dcavins):

 Hi @imath Thanks for your feedback! I must be misunderstanding the failing
 tests. I've added some notes to the test code below:
 {{{#!php
 <?php
 public function test_is_member_property() {
         $users = self::factory()->user->create_many( 2 );

         $g = self::factory()->group->create( array(
                 'creator_id' => $users[0],
         ) );

         wp_set_current_user( $users[1] );

         $group_a = new BP_Groups_Group( $g );
         // Current user is not yet a member of the group, membership
 should be false.
         $this->assertFalse( $group_a->is_member );

         // The current user is added to the group.
         $this->add_user_to_group( $users[1], $g );
         $group_b = new BP_Groups_Group( $g );
         // Current user should be a member, why are we checking for false
 here?
         // This is the check that fails.
         $this->assertFalse( $group_b->is_member );
 }

 public function test_is_invited_property() {
         $users = self::factory()->user->create_many( 2 );

         $g = self::factory()->group->create( array(
                 'creator_id' => $users[0],
         ) );

         wp_set_current_user( $users[1] );

         $group_a = new BP_Groups_Group( $g );
         // Current user has not yet been invited to the group, is_invited
 should be false.
         $this->assertFalse( $group_a->is_invited );

         groups_invite_user( array(
                 'user_id'    => $users[1],
                 'group_id'   => $g,
                 'inviter_id' => $users[0],
                 'send_invite' => 1
         ) );

         $group_b = new BP_Groups_Group( $g );
         // Current user has been invited to the group, is_invited should
 be true, but we are looking for false?
         $this->assertFalse( $group_b->is_invited );
 }
 }}}

 When I run this code with the new class, it behaves as expected:
 {{{#!php
 <?php
 var_dump( "logged in?", bp_loggedin_user_id(), ); // Outputs 1
 var_dump( "switch current user?", wp_set_current_user( 2 )->ID ); //
 Outputs 2
 var_dump( "logged in after?", bp_loggedin_user_id() ); // Outputs 2
 }}}

 It does fail with the current master branch:
 {{{#!php
 <?php
 var_dump( "logged in?", bp_loggedin_user_id(), ); // Outputs 1
 var_dump( "switch current user?", wp_set_current_user( 2 )->ID ); //
 Outputs 2
 var_dump( "logged in after?", bp_loggedin_user_id() ); // Outputs 1
 }}}

 Thanks!

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/7658#comment:17>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list