Skip to content

Commit 87f0cdc

Browse files
committed
Add functional tests
1 parent 8015c0b commit 87f0cdc

File tree

2 files changed

+226
-2
lines changed

2 files changed

+226
-2
lines changed
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
Feature: Manage user custom fields
2+
3+
Scenario: User application password CRUD
4+
Given a WP install
5+
6+
When I run `wp user application-password create 1 myapp`
7+
Then STDOUT should not be empty
8+
9+
When I run `wp user application-password list 1`
10+
Then STDOUT should contain:
11+
"""
12+
myapp
13+
"""
14+
15+
When I run `wp user application-password list 1 --name=myapp --field=uuid`
16+
And save STDOUT as {UUID}
17+
And I run `wp user application-password get 1 {UUID}`
18+
Then STDOUT should contain:
19+
"""
20+
myapp
21+
"""
22+
23+
When I try `wp user application-password get 2 {UUID}`
24+
Then STDERR should be:
25+
"""
26+
Error: Invalid user ID, email or login: '2'
27+
"""
28+
And the return code should be 1
29+
30+
When I try `wp user application-password get 1 123`
31+
Then STDERR should be:
32+
"""
33+
Error: No application password found for this user ID and UUID.
34+
"""
35+
And the return code should be 1
36+
37+
When I run `wp user application-password update 1 {UUID} --name=anotherapp`
38+
Then STDOUT should not be empty
39+
40+
When I run `wp user application-password get 1 {UUID}`
41+
Then STDOUT should contain:
42+
"""
43+
anotherapp
44+
"""
45+
Then STDOUT should not contain:
46+
"""
47+
myapp
48+
"""
49+
50+
When I run `wp user application-password delete 1 {UUID}`
51+
Then STDOUT should contain:
52+
"""
53+
Success: Deleted 1 of 1 application password.
54+
"""
55+
56+
When I try `wp user application-password get 1 {UUID}`
57+
Then the return code should be 1
58+
59+
When I run `wp user application-password create 1 myapp1`
60+
And I run `wp user application-password create 1 myapp2`
61+
And I run `wp user application-password create 1 myapp3`
62+
And I run `wp user application-password create 1 myapp4`
63+
And I run `wp user application-password create 1 myapp5`
64+
Then STDOUT should not be empty
65+
66+
When I run `wp user application-password list 1 --format=count`
67+
Then STDOUT should be:
68+
"""
69+
5
70+
"""
71+
72+
When I run `wp user application-password list 1 --name=myapp1 --field=uuid`
73+
And save STDOUT as {UUID1}
74+
And I run `wp user application-password list 1 --name=myapp2 --field=uuid`
75+
And save STDOUT as {UUID2}
76+
When I try `wp user application-password delete 1 {UUID1} {UUID2} nonsense`
77+
Then STDERR should contain:
78+
"""
79+
Warning: Failed to delete UUID nonsense
80+
"""
81+
Then STDOUT should contain:
82+
"""
83+
Success: Deleted 2 of 3 application passwords.
84+
"""
85+
86+
When I run `wp user application-password list 1 --format=count`
87+
Then STDOUT should be:
88+
"""
89+
3
90+
"""
91+
92+
When I run `wp user application-password delete 1 --all`
93+
And I run `wp user application-password list 1 --format=count`
94+
Then STDOUT should be:
95+
"""
96+
0
97+
"""
98+
99+
Scenario: List user application passwords
100+
Given a WP install
101+
102+
When I run `wp user application-password create 1 myapp1`
103+
Then STDOUT should not be empty
104+
105+
When I run `wp user application-password create 1 myapp2`
106+
Then STDOUT should not be empty
107+
108+
When I run `wp user application-password list 1 --name=myapp1 --field=uuid`
109+
Then save STDOUT as {UUID1}
110+
111+
When I run `wp user application-password list 1 --name=myapp2 --field=uuid`
112+
Then save STDOUT as {UUID2}
113+
114+
When I run `wp user application-password list 1 --name=myapp1 --field=password`
115+
Then save STDOUT as {HASH1}
116+
117+
When I run `wp user application-password list 1 --name=myapp1 --field=password | sed 's#/#\\\/#g'`
118+
Then save STDOUT as {JSONHASH1}
119+
120+
When I run `wp user application-password list 1 --name=myapp2 --field=password`
121+
Then save STDOUT as {HASH2}
122+
123+
When I run `wp user application-password list 1 --name=myapp2 --field=password | sed 's#/#\\\/#g'`
124+
Then save STDOUT as {JSONHASH2}
125+
126+
When I run `wp user application-password list 1 --name=myapp1 --field=created`
127+
Then save STDOUT as {CREATED1}
128+
129+
When I run `wp user application-password list 1 --name=myapp2 --field=created`
130+
Then save STDOUT as {CREATED2}
131+
132+
When I run `wp user application-password list 1 --format=json`
133+
Then STDOUT should be JSON containing:
134+
"""
135+
[{"uuid":"{UUID1}","app_id":"","name":"myapp1","password":"{JSONHASH1}","created":{CREATED1},"last_used":null,"last_ip":null},{"uuid":"{UUID2}","app_id":"","name":"myapp2","password":"{JSONHASH2}","created":{CREATED2},"last_used":null,"last_ip":null}]
136+
"""
137+
138+
When I run `wp user application-password list 1 --format=json --fields=uuid,name`
139+
Then STDOUT should be JSON containing:
140+
"""
141+
[{"uuid":"{UUID1}","name":"myapp1"},{"uuid":"{UUID2}","name":"myapp2"}]
142+
"""
143+
144+
When I run `wp user application-password list 1`
145+
Then STDOUT should be a table containing rows:
146+
| uuid | app_id | name | password | created | last_used | last_ip |
147+
| {UUID2} | | myapp2 | {HASH2} | {CREATED2} | | |
148+
| {UUID1} | | myapp1 | {HASH1} | {CREATED1} | | |
149+
150+
When I run `wp user application-password list 1 --fields=uuid,app_id,name`
151+
Then STDOUT should be a table containing rows:
152+
| uuid | app_id | name |
153+
| {UUID2} | | myapp2 |
154+
| {UUID1} | | myapp1 |
155+
156+
When I run `wp user application-password list admin`
157+
Then STDOUT should be a table containing rows:
158+
| uuid | app_id | name | password | created | last_used | last_ip |
159+
| {UUID2} | | myapp2 | {HASH2} | {CREATED2} | | |
160+
| {UUID1} | | myapp1 | {HASH1} | {CREATED1} | | |
161+
162+
When I run `wp user application-password list admin --orderby=created --order=asc`
163+
Then STDOUT should be a table containing rows:
164+
| uuid | app_id | name | password | created | last_used | last_ip |
165+
| {UUID1} | | myapp1 | {HASH1} | {CREATED1} | | |
166+
| {UUID2} | | myapp2 | {HASH2} | {CREATED2} | | |
167+
168+
When I run `wp user application-password list admin --orderby=name --order=asc`
169+
Then STDOUT should be a table containing rows:
170+
| uuid | app_id | name | password | created | last_used | last_ip |
171+
| {UUID1} | | myapp1 | {HASH1} | {CREATED1} | | |
172+
| {UUID2} | | myapp2 | {HASH2} | {CREATED2} | | |
173+
174+
When I run `wp user application-password list admin --orderby=name --order=desc`
175+
Then STDOUT should be a table containing rows:
176+
| uuid | app_id | name | password | created | last_used | last_ip |
177+
| {UUID2} | | myapp2 | {HASH2} | {CREATED2} | | |
178+
| {UUID1} | | myapp1 | {HASH1} | {CREATED1} | | |
179+
180+
When I run `wp user application-password list admin --name=myapp2 --format=json`
181+
Then STDOUT should contain:
182+
"""
183+
myapp2
184+
"""
185+
And STDOUT should not contain:
186+
"""
187+
myapp1
188+
"""
189+
190+
When I run `wp user application-password list admin --field=name`
191+
Then STDOUT should be:
192+
"""
193+
myapp1
194+
myapp2
195+
"""
196+
197+
Scenario: Get particular user application password hash
198+
Given a WP install
199+
200+
When I run `wp user create testuser testuser@example.com --porcelain`
201+
Then STDOUT should be a number
202+
And save STDOUT as {USER_ID}
203+
204+
When I try the previous command again
205+
Then the return code should be 1
206+
207+
Given I run `wp user application-password create {USER_ID} someapp --porcelain`
208+
And save STDOUT as {PASSWORD}
209+
And I run `wp user application-password list {USER_ID} --name=someapp --field=uuid`
210+
And save STDOUT as {UUID}
211+
212+
Given I run `wp user application-password get {USER_ID} {UUID} --field=password | sed 's/\$/\\\$/g'`
213+
And save STDOUT as {HASH}
214+
215+
When I run `wp eval "var_export( wp_check_password( '{PASSWORD}', '{HASH}', {USER_ID} ) );"`
216+
Then STDOUT should contain:
217+
"""
218+
true
219+
"""

src/User_Application_Password_Command.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ public function get( $args, $assoc_args ) {
241241
WP_CLI::error( $application_password );
242242
}
243243

244+
if ( null === $application_password ) {
245+
WP_CLI::error( 'No application password found for this user ID and UUID.' );
246+
}
247+
244248
$fields = self::APPLICATION_PASSWORD_FIELDS;
245249

246250
if ( ! empty( $assoc_args['fields'] ) ) {
@@ -433,9 +437,10 @@ public function delete( $args, $assoc_args ) {
433437

434438
WP_CLI::success(
435439
sprintf(
436-
'Deleted %d of %d application passwords.',
440+
'Deleted %d of %d application %s.',
437441
$count - $errors,
438-
$count
442+
$count,
443+
Utils\pluralize( 'password', $count )
439444
)
440445
);
441446

0 commit comments

Comments
 (0)