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

Add --show-password flag to user reset-password #394

Merged
merged 9 commits into from
May 18, 2023

Conversation

dsXLII
Copy link
Contributor

@dsXLII dsXLII commented Mar 25, 2023

First go at a PR to address #342 .

@dsXLII dsXLII marked this pull request as ready for review March 28, 2023 13:48
@dsXLII dsXLII requested a review from a team as a code owner March 28, 2023 13:48
@dsXLII dsXLII changed the title First draft of password reset flag to show new pass Add --show-password flag to user reset-password Mar 28, 2023
Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start!

features/user-reset-password.feature Outdated Show resolved Hide resolved
features/user-reset-password.feature Outdated Show resolved Hide resolved
src/User_Command.php Show resolved Hide resolved
src/User_Command.php Outdated Show resolved Hide resolved
@danielbachhuber
Copy link
Member

@dsXLII Still planning to finish this up?

@dsXLII
Copy link
Contributor Author

dsXLII commented May 1, 2023

I'm still here, just distracted by the day job :/

Question about porcelain. For the new app password example, since you can only create one app password at a time the output is unambiguous. But here, since you can reset multiple users' passwords at the same time, it's less clear. (If I do a wp user reset-password 1 2 3 4 four passwords would be output, but it's not obvious that the passwords go in the same order as the user arguments.) What's the best way to handle that? Output them in that order, and document it? Don't allow --porcelain for multiple user arguments?

@danielbachhuber
Copy link
Member

I'm still here, just distracted by the day job :/

No worries!

Question about porcelain.

Good question! You are correct: we don't yet have prior art within WP-CLI.

Let's follow git status and output each password on a new line:

$ git status --porcelain
?? test1
?? test2

Then save STDOUT as {ORIGINAL_PASSWORD}

When I run `wp user reset-password 1 --skip-email --porcelain`
Then save STDOUT as {NEW_PASSWORD}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Learn enough behat to have this check the output (it should be a password, currently "exactly 12 characters, no whitespace, etc")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check doesn't need to be super accurate. In other cases, we simply confirm that STDOUT is not empty.

Behat probably doesn't support checking "exactly 12 characters, no whitespace, etc". In order to perform such a check, you'd need to write a standalone PHP file to execute the check, pass the password to the PHP file, and then have the PHP file exit with 0 or 1 depending on whether it passed or failed. But, doing so is probably overkill for this particular test.

@dsXLII
Copy link
Contributor Author

dsXLII commented May 2, 2023

Added a --porcelain flag. (If you do something impossible, like wp user reset-password 1 2 3 on a site where user 3 doesn't exist, it still outputs a warning, then the new passwords for users 1 and 2. I didn't compare that to the behavior for other places where there's a porcelain option.)

The test almost certainly doesn't work - I assume we should check the output to make sure it's a password (exactly 12 characters, all members of the charset used for passwords, etc), but maybe I'm overthinking it and really only need to make sure it doesn't contain "Warning:" ?

@dsmith4-godaddy
Copy link
Contributor

I think this is ready for a more thorough review. (Resolved the phpcs issues, and a merge conflict from the "change passwords to be 24 characters" PR.)

@danielbachhuber danielbachhuber added this to the 2.5.0 milestone May 17, 2023
@danielbachhuber danielbachhuber self-requested a review May 17, 2023 22:18
Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this, @dsXLII ! Sorry I missed your comment earlier.

I made some minor formatting tweaks with 6bb7681

@danielbachhuber danielbachhuber merged commit ca979c4 into wp-cli:main May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants