Make WordPress Core

Changeset 60404


Ignore:
Timestamp:
07/02/2025 11:58:22 AM (7 months ago)
Author:
johnbillion
Message:

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

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php

    r53882 r60404  
    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                ),
  • trunk/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php

    r57987 r60404  
    846846        $this->assertNotWPError( $prepared );
    847847        $this->check_response( $prepared->get_data(), $item );
     848    }
     849
     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'] );
    848891    }
    849892
  • trunk/tests/qunit/fixtures/wp-api-generated.js

    r60359 r60404  
    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                        },
     
    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                        },
Note: See TracChangeset for help on using the changeset viewer.