<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[49276] trunk: App Passwords: Support an app_id to uniquely identify instances of an app.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/49276">49276</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/49276","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>TimothyBlynJacobs</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2020-10-22 15:04:23 +0000 (Thu, 22 Oct 2020)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>App Passwords: Support an app_id to uniquely identify instances of an app.
Apps may now optionally include an `app_id` parameter when directing the user to the Authorize Application screen. This allows for instances of an application to be identified and potentially revoked or blocked.
Props TimothyBlynJacobs, georgestephanis.
Fixes <a href="https://core.trac.wordpress.org/ticket/51583">#51583</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcjs_enqueuesadminauthappjs">trunk/src/js/_enqueues/admin/auth-app.js</a></li>
<li><a href="#trunksrcwpadminauthorizeapplicationphp">trunk/src/wp-admin/authorize-application.php</a></li>
<li><a href="#trunksrcwpadminincludesuserphp">trunk/src/wp-admin/includes/user.php</a></li>
<li><a href="#trunksrcwpincludesclasswpapplicationpasswordsphp">trunk/src/wp-includes/class-wp-application-passwords.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestapplicationpasswordscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php</a></li>
<li><a href="#trunktestsphpunittestsrestapirestapplicationpasswordscontrollerphp">trunk/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php</a></li>
<li><a href="#trunktestsqunitfixtureswpapigeneratedjs">trunk/tests/qunit/fixtures/wp-api-generated.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcjs_enqueuesadminauthappjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/js/_enqueues/admin/auth-app.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/js/_enqueues/admin/auth-app.js 2020-10-22 04:03:25 UTC (rev 49275)
+++ trunk/src/js/_enqueues/admin/auth-app.js 2020-10-22 15:04:23 UTC (rev 49276)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -16,7 +16,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $approveBtn.click( function( e ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- var name = $appNameField.val();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ var name = $appNameField.val(),
+ appId = $( 'input[name="app_id"]', $form ).val();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> e.preventDefault();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -32,6 +33,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> name: name
</span><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( appId.length > 0 ) {
+ request.app_id = appId;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters the request data used to Authorize an Application Password request.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span></span></pre></div>
<a id="trunksrcwpadminauthorizeapplicationphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/authorize-application.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/authorize-application.php 2020-10-22 04:03:25 UTC (rev 49275)
+++ trunk/src/wp-admin/authorize-application.php 2020-10-22 15:04:23 UTC (rev 49276)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -18,6 +18,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $success_url = $_POST['success_url'];
</span><span class="cx" style="display: block; padding: 0 10px"> $reject_url = $_POST['reject_url'];
</span><span class="cx" style="display: block; padding: 0 10px"> $app_name = $_POST['app_name'];
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $app_id = $_POST['app_id'];
</ins><span class="cx" style="display: block; padding: 0 10px"> $redirect = '';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $_POST['reject'] ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -27,7 +28,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $redirect = admin_url();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( isset( $_POST['approve'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $created = WP_Application_Passwords::create_new_application_password( get_current_user_id(), array( 'name' => $app_name ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $created = WP_Application_Passwords::create_new_application_password(
+ get_current_user_id(),
+ array(
+ 'name' => $app_name,
+ 'app_id' => $app_id,
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $created ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $error = $created;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -56,6 +63,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $title = __( 'Authorize Application' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $app_name = ! empty( $_REQUEST['app_name'] ) ? $_REQUEST['app_name'] : '';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+$app_id = ! empty( $_REQUEST['app_id'] ) ? $_REQUEST['app_id'] : '';
</ins><span class="cx" style="display: block; padding: 0 10px"> $success_url = ! empty( $_REQUEST['success_url'] ) ? $_REQUEST['success_url'] : null;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $_REQUEST['reject_url'] ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -68,7 +76,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $user = wp_get_current_user();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-$request = compact( 'app_name', 'success_url', 'reject_url' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+$request = compact( 'app_name', 'app_id', 'success_url', 'reject_url' );
</ins><span class="cx" style="display: block; padding: 0 10px"> $is_valid = wp_is_authorize_application_password_request_valid( $request, $user );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $is_valid ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -183,6 +191,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> <form action="<?php echo esc_url( admin_url( 'authorize-application.php' ) ); ?>" method="post">
</span><span class="cx" style="display: block; padding: 0 10px"> <?php wp_nonce_field( 'authorize_application_password' ); ?>
</span><span class="cx" style="display: block; padding: 0 10px"> <input type="hidden" name="action" value="authorize_application_password" />
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <input type="hidden" name="app_id" value="<?php echo esc_attr( $app_id ); ?>" />
</ins><span class="cx" style="display: block; padding: 0 10px"> <input type="hidden" name="success_url" value="<?php echo esc_url( $success_url ); ?>" />
</span><span class="cx" style="display: block; padding: 0 10px"> <input type="hidden" name="reject_url" value="<?php echo esc_url( $reject_url ); ?>" />
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwpadminincludesuserphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/user.php 2020-10-22 04:03:25 UTC (rev 49275)
+++ trunk/src/wp-admin/includes/user.php 2020-10-22 15:04:23 UTC (rev 49276)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -604,6 +604,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * The array of request data. All arguments are optional and may be empty.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $app_name The suggested name of the application.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type string $app_id A uuid provided by the application to uniquely identify it.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @type string $success_url The url the user will be redirected to after approving the application.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $reject_url The url the user will be redirected to after rejecting the application.
</span><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -635,6 +636,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $request['app_id'] ) && ! wp_is_uuid( $request['app_id'] ) ) {
+ $error->add(
+ 'invalid_app_id',
+ __( 'The app id must be a uuid.' )
+ );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Fires before application password errors are returned.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpapplicationpasswordsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-application-passwords.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-application-passwords.php 2020-10-22 04:03:25 UTC (rev 49275)
+++ trunk/src/wp-includes/class-wp-application-passwords.php 2020-10-22 15:04:23 UTC (rev 49276)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -51,6 +51,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $new_item = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'uuid' => wp_generate_uuid4(),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'app_id' => empty( $args['app_id'] ) ? '' : $args['app_id'],
</ins><span class="cx" style="display: block; padding: 0 10px"> 'name' => $args['name'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'password' => $hashed_password,
</span><span class="cx" style="display: block; padding: 0 10px"> 'created' => time(),
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestapplicationpasswordscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php 2020-10-22 04:03:25 UTC (rev 49275)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php 2020-10-22 15:04:23 UTC (rev 49276)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -412,6 +412,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'name' => $request['name'],
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $request['app_id'] && ! $request['uuid'] ) {
+ $prepared->app_id = $request['app_id'];
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters an application password before it is inserted via the REST API.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -441,6 +445,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $prepared = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'uuid' => $item['uuid'],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'app_id' => empty( $item['app_id'] ) ? '' : $item['app_id'],
</ins><span class="cx" style="display: block; padding: 0 10px"> 'name' => $item['name'],
</span><span class="cx" style="display: block; padding: 0 10px"> 'created' => gmdate( 'Y-m-d\TH:i:s', $item['created'] ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'last_used' => $item['last_used'] ? gmdate( 'Y-m-d\TH:i:s', $item['last_used'] ) : null,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -615,6 +620,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'context' => array( 'view', 'edit', 'embed' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'readonly' => true,
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ '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',
+ 'context' => array( 'view', 'edit', 'embed' ),
+ ),
</ins><span class="cx" style="display: block; padding: 0 10px"> 'name' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'description' => __( 'The name of the application password.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'string',
</span></span></pre></div>
<a id="trunktestsphpunittestsrestapirestapplicationpasswordscontrollerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php 2020-10-22 04:03:25 UTC (rev 49275)
+++ trunk/tests/phpunit/tests/rest-api/rest-application-passwords-controller.php 2020-10-22 15:04:23 UTC (rev 49276)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -308,8 +308,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_create_item() {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_set_current_user( self::$admin );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $app_id = wp_generate_uuid4();
</ins><span class="cx" style="display: block; padding: 0 10px"> $request = new WP_REST_Request( 'POST', '/wp/v2/users/me/application-passwords' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $request->set_body_params( array( 'name' => 'App' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $request->set_body_params(
+ array(
+ 'name' => 'App',
+ 'app_id' => $app_id,
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> $response = rest_do_request( $request );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 201, $response->get_status() );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -318,6 +324,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertCount( 1, $passwords );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->check_response( $response->get_data(), $passwords[0], true );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 'App', $response->get_data()['name'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals( $app_id, $response->get_data()['app_id'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertNull( $response->get_data()['last_used'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertNull( $response->get_data()['last_ip'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -514,6 +521,36 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @ticket 51583
+ */
+ public function test_update_item_cannot_overwrite_app_id() {
+ wp_set_current_user( self::$admin );
+ list( , $item ) = WP_Application_Passwords::create_new_application_password( self::$admin, array( 'name' => 'App' ) );
+
+ $uuid = $item['uuid'];
+ $request = new WP_REST_Request( 'PUT', '/wp/v2/users/me/application-passwords/' . $uuid );
+ $request->set_body_params( array( 'app_id' => wp_generate_uuid4() ) );
+ $response = rest_do_request( $request );
+ $this->assertEquals( '', $response->get_data()['app_id'] );
+
+ $app_id = wp_generate_uuid4();
+
+ list( , $item ) = WP_Application_Passwords::create_new_application_password(
+ self::$admin,
+ array(
+ 'name' => 'App',
+ 'app_id' => $app_id,
+ )
+ );
+
+ $uuid = $item['uuid'];
+ $request = new WP_REST_Request( 'PUT', '/wp/v2/users/me/application-passwords/' . $uuid );
+ $request->set_body_params( array( 'app_id' => wp_generate_uuid4() ) );
+ $response = rest_do_request( $request );
+ $this->assertEquals( $app_id, $response->get_data()['app_id'] );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * @ticket 42790
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_delete_item() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -775,6 +812,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> protected function check_response( $response, $item, $password = false ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'uuid', $response );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertArrayHasKey( 'app_id', $response );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'name', $response );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'created', $response );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'last_used', $response );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -781,6 +819,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'last_ip', $response );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $item['uuid'], $response['uuid'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEquals( $item['app_id'], $response['app_id'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( $item['name'], $response['name'] );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( gmdate( 'Y-m-d\TH:i:s', $item['created'] ), $response['created'] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -812,12 +851,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $data = $response->get_data();
</span><span class="cx" style="display: block; padding: 0 10px"> $properties = $data['schema']['properties'];
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertCount( 6, $properties );
</del><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'uuid', $properties );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertArrayHasKey( 'app_id', $properties );
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'name', $properties );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'password', $properties );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'created', $properties );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'last_used', $properties );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertArrayHasKey( 'last_ip', $properties );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertCount( 7, $properties );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsqunitfixtureswpapigeneratedjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/qunit/fixtures/wp-api-generated.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/qunit/fixtures/wp-api-generated.js 2020-10-22 04:03:25 UTC (rev 49275)
+++ trunk/tests/qunit/fixtures/wp-api-generated.js 2020-10-22 15:04:23 UTC (rev 49276)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4917,6 +4917,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> "POST"
</span><span class="cx" style="display: block; padding: 0 10px"> ],
</span><span class="cx" style="display: block; padding: 0 10px"> "args": {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "app_id": {
+ "description": "A machine-readable string provided by the application to uniquely identify it.",
+ "type": "string",
+ "required": false
+ },
</ins><span class="cx" style="display: block; padding: 0 10px"> "name": {
</span><span class="cx" style="display: block; padding: 0 10px"> "description": "The name of the application password.",
</span><span class="cx" style="display: block; padding: 0 10px"> "type": "string",
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4967,6 +4972,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> "PATCH"
</span><span class="cx" style="display: block; padding: 0 10px"> ],
</span><span class="cx" style="display: block; padding: 0 10px"> "args": {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ "app_id": {
+ "description": "A machine-readable string provided by the application to uniquely identify it.",
+ "type": "string",
+ "required": false
+ },
</ins><span class="cx" style="display: block; padding: 0 10px"> "name": {
</span><span class="cx" style="display: block; padding: 0 10px"> "description": "The name of the application password.",
</span><span class="cx" style="display: block; padding: 0 10px"> "type": "string",
</span></span></pre>
</div>
</div>
</body>
</html>