Skip to content

Commit 64a14cb

Browse files
style: run prettier on changed files
1 parent 728521c commit 64a14cb

File tree

1 file changed

+49
-69
lines changed

1 file changed

+49
-69
lines changed

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsOpenVPNClientExportTestCase.inc

Lines changed: 49 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ use RESTAPI\Models\OpenVPNClientExportConfig;
1212
use RESTAPI\Models\OpenVPNServer;
1313
use RESTAPI\Models\User;
1414

15-
class APIModelsOpenVPNClientExportTestCase extends TestCase
16-
{
15+
class APIModelsOpenVPNClientExportTestCase extends TestCase {
1716
private CertificateAuthority $server_ca;
1817
private CertificateGenerate $server_cert;
1918
private CertificateGenerate $user_cert;
@@ -27,8 +26,7 @@ class APIModelsOpenVPNClientExportTestCase extends TestCase
2726
/**
2827
* Setup the test environment before starting tests.
2928
*/
30-
public function setup(): void
31-
{
29+
public function setup(): void {
3230
# Create a CA we can test with
3331
$this->server_ca = new CertificateAuthority(
3432
descr: 'test_ca',
@@ -62,7 +60,7 @@ class APIModelsOpenVPNClientExportTestCase extends TestCase
6260
$this->user_cert->create();
6361

6462
# Create a user we can use for testing
65-
$this->user = new User(name: "ovpntest", password: "ovpntest", cert: [$this->user_cert->refid->value]);
63+
$this->user = new User(name: 'ovpntest', password: 'ovpntest', cert: [$this->user_cert->refid->value]);
6664
$this->user->create();
6765

6866
# Create a remote auth server to use for testing
@@ -108,8 +106,7 @@ class APIModelsOpenVPNClientExportTestCase extends TestCase
108106
/**
109107
* Remove the CA and cert used for testing after tests complete.
110108
*/
111-
public function teardown(): void
112-
{
109+
public function teardown(): void {
113110
$this->user->delete();
114111
$this->authserver->delete();
115112
$this->ovpns->delete(apply: true);
@@ -121,58 +118,55 @@ class APIModelsOpenVPNClientExportTestCase extends TestCase
121118
/**
122119
* Ensure the 'certref' field is required for OpenVPNServers using the 'server_tls' mode
123120
*/
124-
public function test_certref_required_for_server_tls(): void
125-
{
121+
public function test_certref_required_for_server_tls(): void {
126122
# Ensure the server_tls server mode requires a certref for export
127123
$this->assert_throws_response(
128-
response_id: "OPENVPN_CLIENT_EXPORT_CERTREF_REQUIRED",
124+
response_id: 'OPENVPN_CLIENT_EXPORT_CERTREF_REQUIRED',
129125
code: 400,
130126
callable: function () {
131127
# Update the OpenVPNServer mode
132-
$this->ovpns->mode->value = "server_tls";
128+
$this->ovpns->mode->value = 'server_tls';
133129
$this->ovpns->update();
134130

135131
# Ensure the validate_server method throws an error for no certref
136132
$export = new OpenVPNClientExport(id: $this->ovpnce->id);
137133
$export->certref->value = null;
138134
$export->validate_server($this->ovpns->vpnid->value);
139-
}
135+
},
140136
);
141137
}
142138

143139
/**
144140
* Ensure the 'certref' field is required for OpenVPNServers using the 'server_tls_user' mode
145141
*/
146-
public function test_certref_required_for_server_tls_user(): void
147-
{
142+
public function test_certref_required_for_server_tls_user(): void {
148143
# Ensure the server_tls_user server mode requires a certref for export
149144
$this->assert_throws_response(
150-
response_id: "OPENVPN_CLIENT_EXPORT_CERTREF_REQUIRED",
145+
response_id: 'OPENVPN_CLIENT_EXPORT_CERTREF_REQUIRED',
151146
code: 400,
152147
callable: function () {
153148
# Update the OpenVPNServer mode
154-
$this->ovpns->mode->value = "server_tls_user";
149+
$this->ovpns->mode->value = 'server_tls_user';
155150
$this->ovpns->authmode->value = $this->ovpns->authmode->default;
156151
$this->ovpns->update();
157152

158153
# Ensure the validate_server method throws an error for no certref
159154
$export = new OpenVPNClientExport(id: $this->ovpnce->id);
160155
$export->certref->value = null;
161156
$export->validate_server($this->ovpns->vpnid->value);
162-
}
157+
},
163158
);
164159
}
165160

166161
/**
167162
* Ensure the 'certref' field is not required for OpenVPNServers using the 'server_user' mode
168163
*/
169-
public function test_certref_not_required_for_server_user(): void
170-
{
164+
public function test_certref_not_required_for_server_user(): void {
171165
# Ensure the server_user server mode does not require a certref for export
172166
$this->assert_does_not_throw(
173167
callable: function () {
174168
# Update the OpenVPNServer mode
175-
$this->ovpns->mode->value = "server_user";
169+
$this->ovpns->mode->value = 'server_user';
176170
$this->ovpns->authmode->value = $this->ovpns->authmode->default;
177171
$this->ovpns->update();
178172

@@ -181,163 +175,149 @@ class APIModelsOpenVPNClientExportTestCase extends TestCase
181175
$export->certref->value = null;
182176
$export->username->value = $this->user->name->value; # username is required for server_user mode
183177
$export->validate_server($this->ovpns->vpnid->value);
184-
}
178+
},
185179
);
186180
}
187181

188182
/**
189183
* Ensure the username field is required for OpenVPN servers using the 'Local Database' authmode
190184
*/
191-
public function test_username_required_for_local_database_authmode(): void
192-
{
185+
public function test_username_required_for_local_database_authmode(): void {
193186
# Ensure a username is required when using the local database authmode
194187
$this->assert_throws_response(
195-
response_id: "OPENVPN_CLIENT_EXPORT_USERNAME_REQUIRED",
188+
response_id: 'OPENVPN_CLIENT_EXPORT_USERNAME_REQUIRED',
196189
code: 400,
197190
callable: function () {
198191
# Update the OpenVPNServer mode
199-
$this->ovpns->mode->value = "server_tls_user";
192+
$this->ovpns->mode->value = 'server_tls_user';
200193
$this->ovpns->authmode->value = $this->ovpns->authmode->default;
201194
$this->ovpns->update();
202195

203196
# Ensure the validate_server method throws an error for no certref
204197
$export = new OpenVPNClientExport(id: $this->ovpnce->id, certref: $this->user_cert->refid->value);
205198
$export->username->value = null;
206199
$export->validate_server($this->ovpns->vpnid->value);
207-
}
200+
},
208201
);
209202
}
210203

211204
/**
212205
* Ensure the username field is not required for OpenVPN servers using a remote authmode
213206
*/
214-
public function test_username_not_required_for_remote_authmode(): void
215-
{
207+
public function test_username_not_required_for_remote_authmode(): void {
216208
# Ensure a username is not required when using a remote authmode
217209
$this->assert_does_not_throw(
218210
callable: function () {
219211
# Update the OpenVPNServer mode
220-
$this->ovpns->mode->value = "server_tls_user";
212+
$this->ovpns->mode->value = 'server_tls_user';
221213
$this->ovpns->authmode->value = [$this->authserver->name->value];
222214
$this->ovpns->update();
223215

224216
# Ensure the validate_server method does not throw an error for no username
225217
$export = new OpenVPNClientExport(id: $this->ovpnce->id, certref: $this->user_cert->refid->value);
226218
$export->username->value = null;
227219
$export->validate_server($this->ovpns->vpnid->value);
228-
}
220+
},
229221
);
230222
}
231223

232224
/**
233225
* Ensure an error is thrown when 'usetoken' is enabled with a forbidden export 'type'
234226
*/
235-
public function test_usetoken_forbidden_types(): void
236-
{
227+
public function test_usetoken_forbidden_types(): void {
237228
foreach (OpenVPNClientExport::USETOKEN_FORBIDDEN_TYPES as $forbidden_type) {
238229
$this->assert_throws_response(
239-
response_id: "OPENVPN_CLIENT_EXPORT_TYPE_USETOKEN_NOT_ALLOWED",
230+
response_id: 'OPENVPN_CLIENT_EXPORT_TYPE_USETOKEN_NOT_ALLOWED',
240231
code: 409,
241232
callable: function () use ($forbidden_type) {
242233
# Create a new OpenVPNClientExport with 'usetoken' enabled and a forbidden export 'type'
243234
$export = new OpenVPNClientExport(usetoken: true);
244235
$export->validate_type($forbidden_type);
245-
}
236+
},
246237
);
247238
}
248239
}
249240

250241
/**
251242
* Ensure no error is thrown when 'usetoken' is disabled, and a usetoken forbidden type is used.
252243
*/
253-
public function test_usetoken_forbidden_types_disabled(): void
254-
{
244+
public function test_usetoken_forbidden_types_disabled(): void {
255245
foreach (OpenVPNClientExport::USETOKEN_FORBIDDEN_TYPES as $forbidden_type) {
256246
$this->assert_does_not_throw(
257247
callable: function () use ($forbidden_type) {
258248
# Create a new OpenVPNClientExport with 'usetoken' disabled and a forbidden export 'type'
259249
$export = new OpenVPNClientExport(usetoken: false);
260250
$export->validate_type($forbidden_type);
261-
}
251+
},
262252
);
263253
}
264254
}
265255

266256
/**
267257
* Ensure no error is thrown when 'usetoken' is enabled, and a non usetoken forbidden type is used.
268258
*/
269-
public function test_usetoken_non_forbidden_types(): void
270-
{
259+
public function test_usetoken_non_forbidden_types(): void {
271260
$this->assert_does_not_throw(
272261
callable: function () {
273262
# Create a new OpenVPNClientExport with 'usetoken' enabled and a non forbidden export 'type'
274263
$export = new OpenVPNClientExport(usetoken: true);
275-
$export->validate_type("inst-Win10");
276-
}
264+
$export->validate_type('inst-Win10');
265+
},
277266
);
278267
}
279268

280269
/**
281270
* Ensure the certref validation for user certs is skipped if there is no username specified.
282271
*/
283-
public function test_certref_validation_skipped_for_user_certs_without_username(): void
284-
{
272+
public function test_certref_validation_skipped_for_user_certs_without_username(): void {
285273
# Create a new OpenVPNClientExport with a user cert and no username
286274
$export = new OpenVPNClientExport();
287275
$export->username->value = null;
288-
$this->assert_equals($export->validate_certref("anything"), "anything");
289-
$this->assert_equals(
290-
$export->validate_certref($this->user_cert->refid->value),
291-
$this->user_cert->refid->value
292-
);
276+
$this->assert_equals($export->validate_certref('anything'), 'anything');
277+
$this->assert_equals($export->validate_certref($this->user_cert->refid->value), $this->user_cert->refid->value);
293278
}
294279

295280
/**
296281
* Ensure an error is thrown if the provided certref is not assigned to the provided user.
297282
*/
298-
public function test_certref_validation_user_cert_not_assigned_to_user(): void
299-
{
283+
public function test_certref_validation_user_cert_not_assigned_to_user(): void {
300284
# Ensure an error is thrown if the certref is not assigned to the user
301285
$this->assert_throws_response(
302-
response_id: "OPENVPN_CLIENT_EXPORT_USER_CERT_NOT_FOUND",
286+
response_id: 'OPENVPN_CLIENT_EXPORT_USER_CERT_NOT_FOUND',
303287
code: 404,
304288
callable: function () {
305289
# Create a new OpenVPNClientExport with a user cert and a username
306290
$export = new OpenVPNClientExport(username: $this->user->name->value);
307291

308292
# Try to use the server cert (which isn't assigned to the user), this should throw an error
309293
$export->validate_certref($this->server_cert->refid->value);
310-
}
294+
},
311295
);
312296
}
313297

314298
/**
315299
* Ensure an error is thrown if the requested user cert does not have a private key
316300
* and usepkcs11 or usetoken is not used
317301
*/
318-
public function test_certref_validation_user_cert_no_private_key(): void
319-
{
302+
public function test_certref_validation_user_cert_no_private_key(): void {
320303
# Temporarily unset the prv value for the user cert
321-
Certificate::set_config(
322-
"{$this->user_cert->get_config_path()}/prv",
323-
null
324-
);
304+
Certificate::set_config("{$this->user_cert->get_config_path()}/prv", null);
325305

326306
# Ensure an error is thrown if the user cert does not have a private key
327307
$this->assert_throws_response(
328-
response_id: "OPENVPN_CLIENT_EXPORT_CERT_NO_PRIVATE_KEY",
308+
response_id: 'OPENVPN_CLIENT_EXPORT_CERT_NO_PRIVATE_KEY',
329309
code: 400,
330310
callable: function () {
331311
# Create a new OpenVPNClientExport with a user cert and a username
332312
$export = new OpenVPNClientExport(
333313
username: $this->user->name->value,
334314
usepkcs11: false,
335-
usetoken: false
315+
usetoken: false,
336316
);
337317

338318
# Ensure the validate_certref method throws an error for no private key
339319
$export->validate_certref($this->user_cert->refid->value);
340-
}
320+
},
341321
);
342322
}
343323

@@ -347,9 +327,9 @@ class APIModelsOpenVPNClientExportTestCase extends TestCase
347327
public function test_export_config_inline(): void {
348328
$exporter = new OpenVPNClientExport(
349329
id: $this->ovpnce->id,
350-
type: "confinline",
330+
type: 'confinline',
351331
username: $this->user->name->value,
352-
certref: $this->user_cert->refid->value
332+
certref: $this->user_cert->refid->value,
353333
);
354334

355335
$config = $exporter->export_config();
@@ -366,9 +346,9 @@ class APIModelsOpenVPNClientExportTestCase extends TestCase
366346
public function test_export_config_zip(): void {
367347
$exporter = new OpenVPNClientExport(
368348
id: $this->ovpnce->id,
369-
type: "confzip",
349+
type: 'confzip',
370350
username: $this->user->name->value,
371-
certref: $this->user_cert->refid->value
351+
certref: $this->user_cert->refid->value,
372352
);
373353
$filepath = $exporter->export_config();
374354

@@ -384,9 +364,9 @@ class APIModelsOpenVPNClientExportTestCase extends TestCase
384364
public function test_export_installer(): void {
385365
$exporter = new OpenVPNClientExport(
386366
id: $this->ovpnce->id,
387-
type: "inst-Win10",
367+
type: 'inst-Win10',
388368
username: $this->user->name->value,
389-
certref: $this->user_cert->refid->value
369+
certref: $this->user_cert->refid->value,
390370
);
391371
$filepath = $exporter->export_installer();
392372

@@ -402,9 +382,9 @@ class APIModelsOpenVPNClientExportTestCase extends TestCase
402382
public function test_export_viscosity(): void {
403383
$exporter = new OpenVPNClientExport(
404384
id: $this->ovpnce->id,
405-
type: "visc",
385+
type: 'visc',
406386
username: $this->user->name->value,
407-
certref: $this->user_cert->refid->value
387+
certref: $this->user_cert->refid->value,
408388
);
409389
$filepath = $exporter->export_installer();
410390

0 commit comments

Comments
 (0)