Skip to content

Commit

Permalink
App Passwords: Don't prevent non-unique App Password names.
Browse files Browse the repository at this point in the history
In [50030] we enforced that Application Passwords have unique names. This was done with the assumption that applications would not connect to a user multiple times. However, in practice we've seen applications run into issues with the unique name constraint. Depending on the app, they may not know if they've been authorized before, or they may intentionally allow connecting multiple times. To prevent friction, App developers need to make their App Name unique, and in doing so often include things like the current date & time, which is already included in the App Passwords list table.

This commit removes this requirement to simplify usage of the Authorize Application flow.

Props mark-k, Boniu91, timothyblynjacobs, peterwilsoncc.
Fixes #54213.


git-svn-id: https://develop.svn.wordpress.org/trunk@59084 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
TimothyBJacobs committed Sep 24, 2024
1 parent 0b8b804 commit ec80646
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
4 changes: 0 additions & 4 deletions src/wp-includes/class-wp-application-passwords.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ public static function create_new_application_password( $user_id, $args = array(
return new WP_Error( 'application_password_empty_name', __( 'An application name is required to create an application password.' ), array( 'status' => 400 ) );
}

if ( self::application_name_exists_for_user( $user_id, $args['name'] ) ) {
return new WP_Error( 'application_password_duplicate_name', __( 'Each application name should be unique.' ), array( 'status' => 409 ) );
}

$new_password = wp_generate_password( static::PW_LENGTH, false );
$hashed_password = wp_hash_password( $new_password );

Expand Down
17 changes: 0 additions & 17 deletions tests/e2e/specs/profile/applications-passwords.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,6 @@ test.describe( 'Manage applications passwords', () => {
);
} );

test('should not allow to create two applications passwords with the same name', async ( {
page,
applicationPasswords
} ) => {
await applicationPasswords.create();
await applicationPasswords.create();

const errorMessage = page.getByRole( 'alert' );

await expect( errorMessage ).toHaveClass( /notice-error/ );
await expect(
errorMessage
).toContainText(
'Each application name should be unique.'
);
});

test( 'should correctly revoke a single application password', async ( {
page,
applicationPasswords
Expand Down
18 changes: 10 additions & 8 deletions tests/phpunit/tests/rest-api/application-passwords.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ public function data_create_new_application_password_validation() {
),
'args' => array( 'name' => '<script>console.log("Hello")</script>' ),
),
'application_password_duplicate_name when name exists' => array(
'expected' => array(
'error_code' => 'application_password_duplicate_name',
'error_message' => 'Each application name should be unique.',
),
'args' => array( 'name' => 'test2' ),
'names' => array( 'test1', 'test2' ),
),
);
}

Expand Down Expand Up @@ -196,4 +188,14 @@ public function data_update_application_password() {
),
);
}

/**
* @ticket 51941
*/
public function test_can_create_duplicate_app_password_names() {
$created = WP_Application_Passwords::create_new_application_password( self::$user_id, array( 'name' => 'My App' ) );
$this->assertNotWPError( $created, 'First attempt to create an application password should not return an error' );
$created = WP_Application_Passwords::create_new_application_password( self::$user_id, array( 'name' => 'My App' ) );
$this->assertNotWPError( $created, 'Second attempt to create an application password should not return an error' );
}
}

0 comments on commit ec80646

Please sign in to comment.