Skip to content

Commit

Permalink
Fix schema for app_id property in application passwords and also add …
Browse files Browse the repository at this point in the history
…rtelated unit test
  • Loading branch information
Sukhendu2002 committed Feb 10, 2025
1 parent 551e474 commit 97c6eba
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,16 @@ public function get_item_schema() {
'app_id' => array(
'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.' ),
'type' => 'string',
'format' => 'uuid',
'oneOf' => array(
array(
'type' => 'string',
'format' => 'uuid',
),
array(
'type' => 'string',
'enum' => array( '' ),
),
),
'context' => array( 'view', 'edit', 'embed' ),
),
'name' => array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,67 @@ public function test_prepare_item() {
$this->check_response( $prepared->get_data(), $item );
}

/**
* @ticket 53692
*/
public function test_app_id_schema() {
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users/me/application-passwords' );
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
$properties = $data['schema']['properties'];

$this->assertArrayHasKey( 'app_id', $properties );
$this->assertSame( 'string', $properties['app_id']['type'] );
$this->assertCount( 2, $properties['app_id']['oneOf'] );

$this->assertSame( 'string', $properties['app_id']['oneOf'][0]['type'] );
$this->assertSame( 'uuid', $properties['app_id']['oneOf'][0]['format'] );

$this->assertSame( 'string', $properties['app_id']['oneOf'][1]['type'] );
$this->assertSame( array( '' ), $properties['app_id']['oneOf'][1]['enum'] );
}

/**
* @ticket 53692
*/
public function test_create_item_with_empty_app_id() {
wp_set_current_user( self::$admin );

$request = new WP_REST_Request( 'POST', '/wp/v2/users/' . self::$admin . '/application-passwords' );
$request->set_body_params(
array(
'name' => 'Test',
'app_id' => '',
)
);

$response = rest_get_server()->dispatch( $request );
$this->assertSame( 201, $response->get_status() );
$data = $response->get_data();
$this->assertSame( '', $data['app_id'] );
}

/**
* @ticket 53692
*/
public function test_create_item_with_uuid_app_id() {
wp_set_current_user( self::$admin );

$uuid = wp_generate_uuid4();

Check warning on line 896 in tests/phpunit/tests/rest-api/rest-application-passwords-controller.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
$request = new WP_REST_Request( 'POST', '/wp/v2/users/' . self::$admin . '/application-passwords' );
$request->set_body_params(
array(
'name' => 'Test',
'app_id' => $uuid,
)
);

$response = rest_get_server()->dispatch( $request );
$this->assertSame( 201, $response->get_status() );
$data = $response->get_data();
$this->assertSame( $uuid, $data['app_id'] );
}

/**
* Checks the password response matches the expected format.
*
Expand Down
22 changes: 20 additions & 2 deletions tests/qunit/fixtures/wp-api-generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -10028,7 +10028,16 @@ mockedApiResponse.Schema = {
"app_id": {
"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.",
"type": "string",
"format": "uuid",
"oneOf": [
{
"type": "string",
"format": "uuid",
},
{
"type": "string",
"enum": [ "" ],
},
],
"required": false
},
"name": {
Expand Down Expand Up @@ -10112,7 +10121,16 @@ mockedApiResponse.Schema = {
"app_id": {
"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.",
"type": "string",
"format": "uuid",
"oneOf": [
{
"type": "string",
"format": "uuid",
},
{
"type": "string",
"enum": [ "" ],
},
],
"required": false
},
"name": {
Expand Down

0 comments on commit 97c6eba

Please sign in to comment.