Skip to content

Commit f5f01dc

Browse files
committed
61837: Add failing unit tests for checking item permissions while updating password
1 parent ca64c85 commit f5f01dc

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/phpunit/tests/rest-api/rest-posts-controller.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,49 @@ public function test_get_post_with_password_without_permission() {
21732173
$this->assertTrue( $data['excerpt']['protected'] );
21742174
}
21752175

2176+
/**
2177+
* @ticket 61837
2178+
*/
2179+
public function test_get_item_permissions_check_while_updating_password() {
2180+
$endpoint = new WP_REST_Posts_Controller( 'post' );
2181+
2182+
$request_with_post_password = new WP_REST_Request( 'POST', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
2183+
$request_with_post_password->set_body_params(
2184+
$this->set_post_data(
2185+
array(
2186+
'id' => self::$post_id,
2187+
'password' => '123',
2188+
)
2189+
)
2190+
);
2191+
$permission = $endpoint->get_item_permissions_check( $request_with_post_password );
2192+
2193+
// Password provided in POST data, password check should not kick in.
2194+
$this->assertNotInstanceOf( 'WP_Error', $permission, 'Password should be ignored by permissions check if provided in post body.' );
2195+
$this->assertTrue( $permission );
2196+
}
2197+
2198+
/**
2199+
* @ticket 61837
2200+
*/
2201+
public function test_get_item_permissions_check_while_updating_password_with_invalid_type() {
2202+
$endpoint = new WP_REST_Posts_Controller( 'post' );
2203+
2204+
$request_with_post_password = new WP_REST_Request( 'POST', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
2205+
$request_with_post_password->set_body_params(
2206+
$this->set_post_data(
2207+
array(
2208+
'id' => self::$post_id,
2209+
'password' => 123,
2210+
)
2211+
)
2212+
);
2213+
$permission = $endpoint->get_item_permissions_check( $request_with_post_password );
2214+
2215+
$this->assertNotInstanceOf( 'WP_Error', $permission, 'Password should be ignored by permissions chedk even if invalid type' );
2216+
$this->assertTrue( $permission );
2217+
}
2218+
21762219
/**
21772220
* The post response should not have `block_version` when in view context.
21782221
*

0 commit comments

Comments
 (0)