Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/16/2015 10:48:11 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Messages: Introduce filter to enforce private message thread query boundaries.

This change ensures that all queries for private messages will always return anticipated results, even when certain malformed values are passed in. It specifically hardens the user ID argument to prevent accidental overriding.

Fixes #6504. Props r-a-y. (trunk, for 2.4.0)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/messages/template.php

    r9819 r9948  
    260260
    261261    /**
     262     * @group bp_has_message_threads
     263     */
     264    public function test_has_message_threads_anonymous_user_should_not_see_threads() {
     265        $u1 = $this->factory->user->create();
     266        $u2 = $this->factory->user->create();
     267
     268        // create initial thread
     269        $this->factory->message->create( array(
     270            'sender_id'  => $u1,
     271            'recipients' => array( $u2 ),
     272        ) );
     273
     274        // set user to anonymous
     275        $old_current_user = get_current_user_id();
     276        $this->set_current_user( 0 );
     277
     278        // now, do the message thread query
     279        global $messages_template;
     280        bp_has_message_threads();
     281
     282        // assert!
     283        $this->assertEquals( 0, $messages_template->thread_count );
     284        $this->assertEmpty( $messages_template->threads );
     285
     286        $this->set_current_user( $old_current_user );
     287    }
     288
     289    /**
    262290     * @group pagination
    263291     * @group BP_Messages_Box_Template
Note: See TracChangeset for help on using the changeset viewer.