-
Notifications
You must be signed in to change notification settings - Fork 13
Add support for application passwords via env vars and wp-cli.yml config #151
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
Open
Copilot
wants to merge
9
commits into
main
Choose a base branch
from
copilot/add-support-for-application-passwords
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+238
−8
Open
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a32474c
Initial plan
Copilot 1c8ffc2
feat: add support for application passwords via env vars and config
Copilot 45233c1
refactor: extract resolve_auth helper, fix parse_url scheme, add unit…
Copilot c36eef1
Apply suggestions from code review
swissspidy a5c2af7
Data provider attribute
swissspidy 8cce6fe
Add .gitattributes
swissspidy c10237b
Lint fixes
swissspidy a693f3a
Merge branch 'main' into copilot/add-support-for-application-passwords
swissspidy 2530da8
Merge branch 'main' into copilot/add-support-for-application-password…
swissspidy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| <?php | ||
|
|
||
| use WP_CLI\Tests\TestCase; | ||
|
|
||
| class Runner_Resolve_Auth_Test extends TestCase { | ||
|
|
||
| private $saved_env = array(); | ||
|
|
||
| public function set_up() { | ||
| foreach ( array( 'WP_REST_CLI_AUTH_USER', 'WP_REST_CLI_AUTH_PASSWORD' ) as $var ) { | ||
| $val = getenv( $var ); | ||
| $this->saved_env[ $var ] = false === $val ? false : $val; | ||
| putenv( $var ); | ||
| } | ||
| } | ||
|
|
||
| public function tear_down() { | ||
| foreach ( $this->saved_env as $var => $val ) { | ||
| if ( false === $val ) { | ||
| putenv( $var ); | ||
| } else { | ||
| putenv( "{$var}={$val}" ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public function test_no_auth_when_nothing_set() { | ||
| $auth = \WP_REST_CLI\Runner::resolve_auth( 'example.com' ); | ||
| $this->assertSame( array(), $auth ); | ||
| } | ||
|
|
||
| public function test_auth_from_config() { | ||
| $auth = \WP_REST_CLI\Runner::resolve_auth( | ||
| 'example.com', | ||
| array( | ||
| 'http_user' => 'admin', | ||
| 'http_password' => 'secret', | ||
| ) | ||
| ); | ||
| $this->assertSame( | ||
| array( | ||
| 'type' => 'basic', | ||
| 'username' => 'admin', | ||
| 'password' => 'secret', | ||
| ), | ||
| $auth | ||
| ); | ||
| } | ||
|
|
||
| public function test_config_allows_empty_password() { | ||
| $auth = \WP_REST_CLI\Runner::resolve_auth( | ||
| 'example.com', | ||
| array( 'http_user' => 'admin' ) | ||
| ); | ||
| $this->assertSame( | ||
| array( | ||
| 'type' => 'basic', | ||
| 'username' => 'admin', | ||
| 'password' => '', | ||
| ), | ||
| $auth | ||
| ); | ||
| } | ||
|
|
||
| public function test_env_vars_override_config() { | ||
| putenv( 'WP_REST_CLI_AUTH_USER=envuser' ); | ||
| putenv( 'WP_REST_CLI_AUTH_PASSWORD=envpass' ); | ||
| $auth = \WP_REST_CLI\Runner::resolve_auth( | ||
| 'example.com', | ||
| array( | ||
| 'http_user' => 'cfguser', | ||
| 'http_password' => 'cfgpass', | ||
| ) | ||
| ); | ||
| $this->assertSame( | ||
| array( | ||
| 'type' => 'basic', | ||
| 'username' => 'envuser', | ||
| 'password' => 'envpass', | ||
| ), | ||
| $auth | ||
| ); | ||
| } | ||
|
|
||
| public function test_env_user_without_env_password_uses_empty_password() { | ||
| putenv( 'WP_REST_CLI_AUTH_USER=envuser' ); | ||
| $auth = \WP_REST_CLI\Runner::resolve_auth( 'example.com' ); | ||
| $this->assertSame( | ||
| array( | ||
| 'type' => 'basic', | ||
| 'username' => 'envuser', | ||
| 'password' => '', | ||
| ), | ||
| $auth | ||
| ); | ||
| } | ||
|
|
||
| public function test_empty_env_user_skips_env_auth() { | ||
| putenv( 'WP_REST_CLI_AUTH_USER=' ); | ||
| putenv( 'WP_REST_CLI_AUTH_PASSWORD=envpass' ); | ||
| $auth = \WP_REST_CLI\Runner::resolve_auth( 'example.com' ); | ||
| $this->assertSame( array(), $auth ); | ||
| } | ||
|
|
||
| public function test_url_credentials_override_env_vars() { | ||
| putenv( 'WP_REST_CLI_AUTH_USER=envuser' ); | ||
| putenv( 'WP_REST_CLI_AUTH_PASSWORD=envpass' ); | ||
| $auth = \WP_REST_CLI\Runner::resolve_auth( 'http://urluser:urlpass@example.com' ); | ||
| $this->assertSame( | ||
| array( | ||
| 'type' => 'basic', | ||
| 'username' => 'urluser', | ||
| 'password' => 'urlpass', | ||
| ), | ||
| $auth | ||
| ); | ||
| } | ||
|
|
||
| public function test_url_credentials_without_scheme() { | ||
| $auth = \WP_REST_CLI\Runner::resolve_auth( 'urluser:urlpass@example.com' ); | ||
| $this->assertSame( | ||
| array( | ||
| 'type' => 'basic', | ||
| 'username' => 'urluser', | ||
| 'password' => 'urlpass', | ||
| ), | ||
| $auth | ||
| ); | ||
| } | ||
|
|
||
| public function test_url_credentials_with_https_scheme() { | ||
| $auth = \WP_REST_CLI\Runner::resolve_auth( 'https://urluser:urlpass@example.com' ); | ||
| $this->assertSame( | ||
| array( | ||
| 'type' => 'basic', | ||
| 'username' => 'urluser', | ||
| 'password' => 'urlpass', | ||
| ), | ||
| $auth | ||
| ); | ||
| } | ||
|
swissspidy marked this conversation as resolved.
Outdated
|
||
|
|
||
| public function test_url_credentials_override_config() { | ||
| $auth = \WP_REST_CLI\Runner::resolve_auth( | ||
| 'http://urluser:urlpass@example.com', | ||
| array( | ||
| 'http_user' => 'cfguser', | ||
| 'http_password' => 'cfgpass', | ||
| ) | ||
| ); | ||
| $this->assertSame( | ||
| array( | ||
| 'type' => 'basic', | ||
| 'username' => 'urluser', | ||
| 'password' => 'urlpass', | ||
| ), | ||
| $auth | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.