Skip to content

Commit a5f6b9c

Browse files
committed
Application Passwords: Correct the schema of the app_id property of the application passwords REST API endpoint.
This property can contain either a UUID or an empty string. Props sukhendu2002, johnbillion. Fixes #53692 git-svn-id: https://develop.svn.wordpress.org/trunk@60404 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 740006d commit a5f6b9c

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed

src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,16 @@ public function get_item_schema() {
802802
'app_id' => array(
803803
'description' => __( 'A UUID provided by the application to uniquely identify it. It is recommended to use an UUID v5 with the URL or DNS namespace.' ),
804804
'type' => 'string',
805-
'format' => 'uuid',
805+
'oneOf' => array(
806+
array(
807+
'type' => 'string',
808+
'format' => 'uuid',
809+
),
810+
array(
811+
'type' => 'string',
812+
'enum' => array( '' ),
813+
),
814+
),
806815
'context' => array( 'view', 'edit', 'embed' ),
807816
),
808817
'name' => array(

tests/phpunit/tests/rest-api/rest-application-passwords-controller.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,49 @@ public function test_prepare_item() {
847847
$this->check_response( $prepared->get_data(), $item );
848848
}
849849

850+
/**
851+
* @ticket 53692
852+
*/
853+
public function test_create_item_with_empty_app_id() {
854+
wp_set_current_user( self::$admin );
855+
856+
$request = new WP_REST_Request( 'POST', '/wp/v2/users/me/application-passwords' );
857+
$request->set_body_params(
858+
array(
859+
'name' => 'Test',
860+
'app_id' => '',
861+
)
862+
);
863+
864+
$response = rest_get_server()->dispatch( $request );
865+
$data = $response->get_data();
866+
867+
$this->assertSame( 201, $response->get_status() );
868+
$this->assertSame( '', $data['app_id'] );
869+
}
870+
871+
/**
872+
* @ticket 53692
873+
*/
874+
public function test_create_item_with_uuid_app_id() {
875+
wp_set_current_user( self::$admin );
876+
877+
$uuid = wp_generate_uuid4();
878+
$request = new WP_REST_Request( 'POST', '/wp/v2/users/me/application-passwords' );
879+
$request->set_body_params(
880+
array(
881+
'name' => 'Test',
882+
'app_id' => $uuid,
883+
)
884+
);
885+
886+
$response = rest_get_server()->dispatch( $request );
887+
$data = $response->get_data();
888+
889+
$this->assertSame( 201, $response->get_status() );
890+
$this->assertSame( $uuid, $data['app_id'] );
891+
}
892+
850893
/**
851894
* Checks the password response matches the expected format.
852895
*

tests/qunit/fixtures/wp-api-generated.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10053,7 +10053,18 @@ mockedApiResponse.Schema = {
1005310053
"app_id": {
1005410054
"description": "A UUID provided by the application to uniquely identify it. It is recommended to use an UUID v5 with the URL or DNS namespace.",
1005510055
"type": "string",
10056-
"format": "uuid",
10056+
"oneOf": [
10057+
{
10058+
"type": "string",
10059+
"format": "uuid"
10060+
},
10061+
{
10062+
"type": "string",
10063+
"enum": [
10064+
""
10065+
]
10066+
}
10067+
],
1005710068
"required": false
1005810069
},
1005910070
"name": {
@@ -10137,7 +10148,18 @@ mockedApiResponse.Schema = {
1013710148
"app_id": {
1013810149
"description": "A UUID provided by the application to uniquely identify it. It is recommended to use an UUID v5 with the URL or DNS namespace.",
1013910150
"type": "string",
10140-
"format": "uuid",
10151+
"oneOf": [
10152+
{
10153+
"type": "string",
10154+
"format": "uuid"
10155+
},
10156+
{
10157+
"type": "string",
10158+
"enum": [
10159+
""
10160+
]
10161+
}
10162+
],
1014110163
"required": false
1014210164
},
1014310165
"name": {

0 commit comments

Comments
 (0)