Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -35,23 +35,6 @@
);
} );

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 Expand Up @@ -112,7 +95,7 @@
const newPasswordField = this.page.getByRole( 'textbox', { name: 'New Application Password Name' } );
await expect( newPasswordField ).toBeVisible();
await newPasswordField.fill( applicationName );

Check failure on line 98 in tests/e2e/specs/profile/applications-passwords.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG disabled / Run E2E tests

[chromium] › profile/applications-passwords.test.js:19:6 › Manage applications passwords › should correctly create a new application password

2) [chromium] › profile/applications-passwords.test.js:19:6 › Manage applications passwords › should correctly create a new application password Error: Not logged in 96 | 97 | async create(applicationName = TEST_APPLICATION_NAME) { > 98 | await this.admin.visitAdminPage( '/profile.php' ); | ^ 99 | 100 | const newPasswordField = this.page.getByRole( 'textbox', { name: 'New Application Password Name' } ); 101 | await expect( newPasswordField ).toBeVisible(); at Admin.visitAdminPage (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/visit-admin-page.ts:36:9) at ApplicationPasswords.create (/home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/profile/applications-passwords.test.js:98:3) at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/profile/applications-passwords.test.js:23:3

Check failure on line 98 in tests/e2e/specs/profile/applications-passwords.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG disabled / Run E2E tests

[chromium] › profile/applications-passwords.test.js:19:6 › Manage applications passwords › should correctly create a new application password

2) [chromium] › profile/applications-passwords.test.js:19:6 › Manage applications passwords › should correctly create a new application password Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Not logged in 96 | 97 | async create(applicationName = TEST_APPLICATION_NAME) { > 98 | await this.admin.visitAdminPage( '/profile.php' ); | ^ 99 | 100 | const newPasswordField = this.page.getByRole( 'textbox', { name: 'New Application Password Name' } ); 101 | await expect( newPasswordField ).toBeVisible(); at Admin.visitAdminPage (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/visit-admin-page.ts:36:9) at ApplicationPasswords.create (/home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/profile/applications-passwords.test.js:98:3) at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/profile/applications-passwords.test.js:23:3

Check failure on line 98 in tests/e2e/specs/profile/applications-passwords.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG enabled / Run E2E tests

[chromium] › profile/applications-passwords.test.js:19:6 › Manage applications passwords › should correctly create a new application password

2) [chromium] › profile/applications-passwords.test.js:19:6 › Manage applications passwords › should correctly create a new application password Error: Not logged in 96 | 97 | async create(applicationName = TEST_APPLICATION_NAME) { > 98 | await this.admin.visitAdminPage( '/profile.php' ); | ^ 99 | 100 | const newPasswordField = this.page.getByRole( 'textbox', { name: 'New Application Password Name' } ); 101 | await expect( newPasswordField ).toBeVisible(); at Admin.visitAdminPage (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/visit-admin-page.ts:36:9) at ApplicationPasswords.create (/home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/profile/applications-passwords.test.js:98:3) at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/profile/applications-passwords.test.js:23:3

Check failure on line 98 in tests/e2e/specs/profile/applications-passwords.test.js

View workflow job for this annotation

GitHub Actions / Test with SCRIPT_DEBUG enabled / Run E2E tests

[chromium] › profile/applications-passwords.test.js:19:6 › Manage applications passwords › should correctly create a new application password

2) [chromium] › profile/applications-passwords.test.js:19:6 › Manage applications passwords › should correctly create a new application password Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: Not logged in 96 | 97 | async create(applicationName = TEST_APPLICATION_NAME) { > 98 | await this.admin.visitAdminPage( '/profile.php' ); | ^ 99 | 100 | const newPasswordField = this.page.getByRole( 'textbox', { name: 'New Application Password Name' } ); 101 | await expect( newPasswordField ).toBeVisible(); at Admin.visitAdminPage (/home/runner/work/wordpress-develop/wordpress-develop/node_modules/@wordpress/e2e-test-utils-playwright/src/admin/visit-admin-page.ts:36:9) at ApplicationPasswords.create (/home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/profile/applications-passwords.test.js:98:3) at /home/runner/work/wordpress-develop/wordpress-develop/tests/e2e/specs/profile/applications-passwords.test.js:23:3
await this.page.getByRole( 'button', { name: 'Add New Application Password' } ).click();
await expect( this.page.getByRole( 'alert' ) ).toBeVisible();
}
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 );
TimothyBJacobs marked this conversation as resolved.
Show resolved Hide resolved
$created = WP_Application_Passwords::create_new_application_password( self::$user_id, array( 'name' => 'My App' ) );
$this->assertNotWPError( $created );
TimothyBJacobs marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading