App Passwords: Don't prevent non-unique App Password names.

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 .


git-svn-id: https://develop.svn.wordpress.org/trunk@59084 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Timothy Jacobs 2024-09-24 16:38:36 +00:00
parent 0b8b80449f
commit ec80646878
3 changed files with 10 additions and 29 deletions

@ -94,10 +94,6 @@ class WP_Application_Passwords {
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 );

@ -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

@ -77,14 +77,6 @@ class Test_WP_Application_Passwords extends WP_UnitTestCase {
),
'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' ),
),
);
}
@ -196,4 +188,14 @@ class Test_WP_Application_Passwords extends WP_UnitTestCase {
),
);
}
/**
* @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' );
}
}