|
1 | | -@skip-sqlite |
2 | 1 | Feature: Manage database users |
3 | 2 |
|
4 | | - Scenario: Create database user without privileges |
5 | | - Given an empty directory |
6 | | - And WP files |
7 | | - And wp-config.php |
| 3 | + @require-mysql-or-mariadb |
| 4 | + Scenario: Create a database user without privileges |
| 5 | + Given a WP install |
| 6 | + And I run `wp db query "DROP USER IF EXISTS 'wpcli_dbusers_1'@'%'" --dbuser={DB_ROOT_USER} --dbpass={DB_ROOT_PASSWORD}` |
8 | 7 |
|
9 | | - When I try `wp db create` |
10 | | - And I run `wp db users create testuser localhost --password=testpass123` |
11 | | - Then STDOUT should contain: |
| 8 | + When I run `wp db users create wpcli_dbusers_1 '%' --password=first-Pa55 --dbuser={DB_ROOT_USER} --dbpass={DB_ROOT_PASSWORD}` |
| 9 | + Then STDOUT should be: |
12 | 10 | """ |
13 | | - Success: Database user 'testuser'@'localhost' created. |
| 11 | + Success: Created database user 'wpcli_dbusers_1'@'%'. |
14 | 12 | """ |
15 | 13 |
|
16 | | - When I run `wp db query "SELECT User, Host FROM mysql.user WHERE User='testuser'"` |
17 | | - Then STDOUT should contain: |
| 14 | + When I run `wp db query "SELECT User FROM mysql.user WHERE User = 'wpcli_dbusers_1'" --skip-column-names --dbuser={DB_ROOT_USER} --dbpass={DB_ROOT_PASSWORD}` |
| 15 | + Then STDOUT should be: |
18 | 16 | """ |
19 | | - testuser |
| 17 | + wpcli_dbusers_1 |
20 | 18 | """ |
21 | 19 |
|
22 | | - Scenario: Create database user with privileges |
23 | | - Given an empty directory |
24 | | - And WP files |
25 | | - And wp-config.php |
| 20 | + When I try `wp db query "SELECT 1" --dbuser=wpcli_dbusers_1 --dbpass=first-Pa55` |
| 21 | + Then the return code should be 1 |
| 22 | + And STDERR should contain: |
| 23 | + """ |
| 24 | + denied |
| 25 | + """ |
26 | 26 |
|
27 | | - When I try `wp db create` |
28 | | - And I run `wp db users create appuser localhost --password=secret123 --grant-privileges` |
29 | | - Then STDOUT should contain: |
| 27 | + When I try `wp db users create wpcli_dbusers_1 '%' --password=first-Pa55 --dbuser={DB_ROOT_USER} --dbpass={DB_ROOT_PASSWORD}` |
| 28 | + Then the return code should be 1 |
| 29 | + And STDERR should contain: |
| 30 | + """ |
| 31 | + Error: |
| 32 | + """ |
| 33 | + |
| 34 | + When I run `wp db query "DROP USER 'wpcli_dbusers_1'@'%'" --dbuser={DB_ROOT_USER} --dbpass={DB_ROOT_PASSWORD}` |
| 35 | + |
| 36 | + @require-mysql-or-mariadb |
| 37 | + Scenario: Create a database user with privileges on the WordPress database |
| 38 | + Given a WP install |
| 39 | + And I run `wp db query "DROP USER IF EXISTS 'wpcli_dbusers_2'@'%'" --dbuser={DB_ROOT_USER} --dbpass={DB_ROOT_PASSWORD}` |
| 40 | + |
| 41 | + When I run `echo "it's a \"tricky\" pass\\word;" | wp db users create wpcli_dbusers_2 '%' --grant-privileges --dbuser={DB_ROOT_USER} --dbpass={DB_ROOT_PASSWORD}` |
| 42 | + Then STDOUT should be: |
30 | 43 | """ |
31 | | - created with privileges on database |
| 44 | + Success: Created database user 'wpcli_dbusers_2'@'%' with all privileges on '{DB_NAME}'. |
32 | 45 | """ |
33 | | - And STDOUT should contain: |
| 46 | + |
| 47 | + When I run `wp db query "SELECT option_value FROM wp_options WHERE option_name = 'siteurl'" --skip-column-names --dbuser=wpcli_dbusers_2 --dbpass="it's a \"tricky\" pass\\word;"` |
| 48 | + Then STDOUT should be: |
34 | 49 | """ |
35 | | - appuser |
| 50 | + https://example.com |
36 | 51 | """ |
37 | 52 |
|
38 | | - Scenario: Create database user with custom host |
39 | | - Given an empty directory |
40 | | - And WP files |
41 | | - And wp-config.php |
| 53 | + When I run `wp db query "DROP USER 'wpcli_dbusers_2'@'%'" --dbuser={DB_ROOT_USER} --dbpass={DB_ROOT_PASSWORD}` |
42 | 54 |
|
43 | | - When I try `wp db create` |
44 | | - And I run `wp db users create remoteuser '%' --password=remote123` |
45 | | - Then STDOUT should contain: |
| 55 | + @require-mysql-or-mariadb |
| 56 | + Scenario: The new user's password is not leaked into the debug output |
| 57 | + Given a WP install |
| 58 | + And I run `wp db query "DROP USER IF EXISTS 'wpcli_dbusers_3'@'%'" --dbuser={DB_ROOT_USER} --dbpass={DB_ROOT_PASSWORD}` |
| 59 | + |
| 60 | + When I try `wp db users create wpcli_dbusers_3 '%' --password=leak-Ch3ck-Value --dbuser={DB_ROOT_USER} --dbpass={DB_ROOT_PASSWORD} --debug=db` |
| 61 | + Then the return code should be 0 |
| 62 | + And STDERR should contain: |
| 63 | + """ |
| 64 | + Creating database user 'wpcli_dbusers_3'@'%'. |
46 | 65 | """ |
47 | | - Success: Database user 'remoteuser'@'%' created. |
| 66 | + And STDERR should not contain: |
48 | 67 | """ |
| 68 | + leak-Ch3ck-Value |
| 69 | + """ |
| 70 | + |
| 71 | + When I run `wp db query "DROP USER 'wpcli_dbusers_3'@'%'" --dbuser={DB_ROOT_USER} --dbpass={DB_ROOT_PASSWORD}` |
49 | 72 |
|
50 | | - Scenario: Create database user with no password |
51 | | - Given an empty directory |
52 | | - And WP files |
53 | | - And wp-config.php |
| 73 | + @require-mysql-or-mariadb |
| 74 | + Scenario: A password is required |
| 75 | + Given a WP install |
54 | 76 |
|
55 | | - When I try `wp db create` |
56 | | - And I run `wp db users create nopassuser localhost` |
| 77 | + When I try `wp db users create wpcli_dbusers_4 '%' --dbuser={DB_ROOT_USER} --dbpass={DB_ROOT_PASSWORD} < /dev/null` |
| 78 | + Then the return code should be 1 |
| 79 | + And STDERR should contain: |
| 80 | + """ |
| 81 | + Error: A password is required. |
| 82 | + """ |
| 83 | +
|
| 84 | + @require-mysql-or-mariadb |
| 85 | + Scenario: Only the create subcommand is available |
| 86 | + Given a WP install |
| 87 | +
|
| 88 | + When I try `wp db users drop --yes` |
| 89 | + Then the return code should be 1 |
| 90 | + And STDERR should contain: |
| 91 | + """ |
| 92 | + is not a registered subcommand of 'db users' |
| 93 | + """ |
| 94 | +
|
| 95 | + When I run `wp db check` |
57 | 96 | Then STDOUT should contain: |
58 | 97 | """ |
59 | | - Success: Database user 'nopassuser'@'localhost' created. |
| 98 | + Success: Database checked. |
| 99 | + """ |
| 100 | +
|
| 101 | + @require-sqlite |
| 102 | + Scenario: Database users are not supported with SQLite |
| 103 | + Given a WP install |
| 104 | +
|
| 105 | + When I try `wp db users create someone --password=some-Pa55` |
| 106 | + Then the return code should be 1 |
| 107 | + And STDERR should be: |
| 108 | + """ |
| 109 | + Error: Database users are not supported with SQLite. |
60 | 110 | """ |
0 commit comments