Skip to content

Commit 094eefe

Browse files
style: ran prettier on changed files
1 parent 6d7cc9e commit 094eefe

File tree

4 files changed

+69
-87
lines changed

4 files changed

+69
-87
lines changed

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/WireGuardPeer.inc

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ use RESTAPI\Fields\StringField;
1313
use RESTAPI\Responses\ValidationError;
1414
use RESTAPI\Validators\IPAddressValidator;
1515

16-
class WireGuardPeer extends Model
17-
{
16+
class WireGuardPeer extends Model {
1817
public BooleanField $enabled;
1918
public ForeignModelField $tun;
2019
public StringField $endpoint;
@@ -24,66 +23,61 @@ class WireGuardPeer extends Model
2423
public StringField $publickey;
2524
public StringField $presharedkey;
2625
public NestedModelField $allowedips;
27-
28-
public function __construct(mixed $id = null, mixed $parent_id = null, mixed $data = [], ...$options)
29-
{
26+
27+
public function __construct(mixed $id = null, mixed $parent_id = null, mixed $data = [], ...$options) {
3028
# Set model attributes
3129
$this->many = true;
3230
$this->config_path = 'installedpackages/wireguard/peers/item';
3331
$this->verbose_name = 'WireGuard Peer';
3432
$this->subsystem = 'wireguard';
3533
$this->packages = ['pfSense-pkg-WireGuard'];
3634
$this->package_includes = ['wireguard/includes/wg_service.inc', 'wireguard/includes/wg.inc'];
37-
35+
3836
# Set model fields
3937
$this->enabled = new BooleanField(
4038
default: false,
41-
indicates_true: "yes",
42-
indicates_false: "no",
43-
help_text: "Enables or disables this WireGuard peer."
39+
indicates_true: 'yes',
40+
indicates_false: 'no',
41+
help_text: 'Enables or disables this WireGuard peer.',
4442
);
4543
$this->tun = new ForeignModelField(
46-
model_name: "WireGuardTunnel",
47-
model_field: "name",
48-
allowed_keywords: ["unassigned"],
49-
default: "unassigned",
50-
help_text: "The WireGuard tunnel for this peer."
44+
model_name: 'WireGuardTunnel',
45+
model_field: 'name',
46+
allowed_keywords: ['unassigned'],
47+
default: 'unassigned',
48+
help_text: 'The WireGuard tunnel for this peer.',
5149
);
5250
$this->endpoint = new StringField(
5351
default: null,
5452
allow_null: true,
5553
validators: [new IPAddressValidator(allow_ipv4: true, allow_ipv6: true, allow_fqdn: true)],
56-
help_text: "The IP address or hostname of the remote peer. Set to `null` to make this a dynamic endpoint."
54+
help_text: 'The IP address or hostname of the remote peer. Set to `null` to make this a dynamic endpoint.',
5755
);
5856
$this->port = new PortField(
59-
default: "51820",
60-
conditions: ["!endpoint" => null],
61-
help_text: "The port used by the remote peer."
57+
default: '51820',
58+
conditions: ['!endpoint' => null],
59+
help_text: 'The port used by the remote peer.',
6260
);
6361
$this->persistentkeepalive = new IntegerField(
6462
default: null,
6563
allow_null: true,
6664
maximum: 65535,
67-
help_text: "The interval (in seconds) for Keep Alive packets sent to this peer. Set to `null` to disable."
68-
);
69-
$this->publickey = new StringField(
70-
required: true,
71-
unique: true,
72-
help_text: "The public key for this peer."
65+
help_text: 'The interval (in seconds) for Keep Alive packets sent to this peer. Set to `null` to disable.',
7366
);
67+
$this->publickey = new StringField(required: true, unique: true, help_text: 'The public key for this peer.');
7468
$this->presharedkey = new StringField(
75-
default: "",
69+
default: '',
7670
allow_null: true,
7771
write_only: true,
78-
help_text: "The pre-shared key for this tunnel."
72+
help_text: 'The pre-shared key for this tunnel.',
7973
);
8074
$this->allowedips = new NestedModelField(
81-
model_class: "WireGuardPeerAllowedIP",
75+
model_class: 'WireGuardPeerAllowedIP',
8276
default: [],
8377
allow_empty: true,
84-
help_text: "The allowed IP/subnets for this WireGuard peer."
78+
help_text: 'The allowed IP/subnets for this WireGuard peer.',
8579
);
86-
80+
8781
parent::__construct($id, $parent_id, $data, ...$options);
8882
}
8983

@@ -97,8 +91,8 @@ class WireGuardPeer extends Model
9791
# Throw an error if this value is not a valid WireGuard key
9892
if (!wg_is_valid_key($presharedkey)) {
9993
throw new ValidationError(
100-
message: "Field `presharedkey` must be a valid WireGuard pre-shared key.",
101-
response_id: "WIREGUARD_PEER_PRESHAREDKEY_INVALID"
94+
message: 'Field `presharedkey` must be a valid WireGuard pre-shared key.',
95+
response_id: 'WIREGUARD_PEER_PRESHAREDKEY_INVALID',
10296
);
10397
}
10498

@@ -108,16 +102,14 @@ class WireGuardPeer extends Model
108102
/**
109103
* Serialize changes before applying.
110104
*/
111-
public function pre_apply(): void
112-
{
105+
public function pre_apply(): void {
113106
wg_apply_list_add('tunnels', [$this->tun->value]);
114107
}
115108

116109
/**
117110
* Applies changes to WireGuard tunnels/peers.
118111
*/
119-
public function apply(): void
120-
{
112+
public function apply(): void {
121113
(new WireGuardSettingsDispatcher(async: $this->async))->spawn_process();
122114
}
123115
}

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use RESTAPI\Models\WireGuardPeerAllowedIP;
1010
use RESTAPI\Models\WireGuardSettings;
1111
use RESTAPI\Models\WireGuardTunnel;
1212

13-
class APIModelsWireGuardPeerAllowedIPTestCase extends TestCase
14-
{
13+
class APIModelsWireGuardPeerAllowedIPTestCase extends TestCase {
1514
/**
1615
* Ensure the WireGuard package is installed and enabled before running tests.
1716
*/
@@ -44,32 +43,27 @@ class APIModelsWireGuardPeerAllowedIPTestCase extends TestCase
4443
enabled: true,
4544
tun: $tunnel->name->value,
4645
persistentkeepalive: 200,
47-
publickey: "KG0BA4UyPilHH5qnXCfr6Lw8ynecOPor88tljLy3AHk=",
48-
presharedkey: "zppaKHpHl5tvjbwuYh8uTc8lfyzfLYg3IBrwn9yCFsc=",
49-
async: false
46+
publickey: 'KG0BA4UyPilHH5qnXCfr6Lw8ynecOPor88tljLy3AHk=',
47+
presharedkey: 'zppaKHpHl5tvjbwuYh8uTc8lfyzfLYg3IBrwn9yCFsc=',
48+
async: false,
5049
);
5150
$peer->create(apply: true);
5251

5352
# Create a WireGuardPeerAllowedIP and ensure it is shown in 'wg showconf'
54-
$allowed_ip = new WireGuardPeerAllowedIP(
55-
parent_id: $peer->id,
56-
address: "1.2.3.0",
57-
mask: 24,
58-
async: false
59-
);
53+
$allowed_ip = new WireGuardPeerAllowedIP(parent_id: $peer->id, address: '1.2.3.0', mask: 24, async: false);
6054
$allowed_ip->create(apply: true);
61-
$wg_show = new Command("wg showconf ".$peer->tun->value);
62-
$this->assert_str_contains($wg_show->output, "AllowedIPs = 1.2.3.0/24");
55+
$wg_show = new Command('wg showconf ' . $peer->tun->value);
56+
$this->assert_str_contains($wg_show->output, 'AllowedIPs = 1.2.3.0/24');
6357

6458
# Update the allowed IP and ensure the updated value is shown in 'wg showconf'
65-
$allowed_ip->from_representation(address: "3.2.1.0", mask: 25);
59+
$allowed_ip->from_representation(address: '3.2.1.0', mask: 25);
6660
$allowed_ip->update(apply: true);
67-
$wg_show = new Command("wg showconf ".$peer->tun->value);
68-
$this->assert_str_contains($wg_show->output, "AllowedIPs = 3.2.1.0/25");
61+
$wg_show = new Command('wg showconf ' . $peer->tun->value);
62+
$this->assert_str_contains($wg_show->output, 'AllowedIPs = 3.2.1.0/25');
6963

7064
# Delete the allowed IP and ensure it is no longer present in 'wg showconf'
7165
$allowed_ip->delete(apply: true);
72-
$wg_show = new Command("wg showconf ".$peer->tun->value);
73-
$this->assert_str_does_not_contain($wg_show->output, "AllowedIPs");
66+
$wg_show = new Command('wg showconf ' . $peer->tun->value);
67+
$this->assert_str_does_not_contain($wg_show->output, 'AllowedIPs');
7468
}
75-
}
69+
}

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

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use RESTAPI\Models\WireGuardPeer;
99
use RESTAPI\Models\WireGuardSettings;
1010
use RESTAPI\Models\WireGuardTunnel;
1111

12-
class APIModelsWireGuardPeerTestCase extends TestCase
13-
{
12+
class APIModelsWireGuardPeerTestCase extends TestCase {
1413
/**
1514
* Ensure the WireGuard package is installed and enabled before running tests.
1615
*/
@@ -38,26 +37,26 @@ class APIModelsWireGuardPeerTestCase extends TestCase
3837
public function test_validate_presharedkey(): void {
3938
# Ensure bad PSK throws an error
4039
$this->assert_throws_response(
41-
response_id: "WIREGUARD_PEER_PRESHAREDKEY_INVALID",
40+
response_id: 'WIREGUARD_PEER_PRESHAREDKEY_INVALID',
4241
code: 400,
4342
callable: function () {
4443
$peer = new WireGuardPeer(
45-
publickey: "KG0BA4UyPilHH5qnXCfr6Lw8ynecOPor88tljLy3AHk=",
46-
presharedkey: "not a valid key!"
44+
publickey: 'KG0BA4UyPilHH5qnXCfr6Lw8ynecOPor88tljLy3AHk=',
45+
presharedkey: 'not a valid key!',
4746
);
4847
$peer->validate();
49-
}
48+
},
5049
);
5150

5251
# Ensure good PSK does not throw an error
5352
$this->assert_does_not_throw(
5453
callable: function () {
5554
$peer = new WireGuardPeer(
56-
publickey: "KG0BA4UyPilHH5qnXCfr6Lw8ynecOPor88tljLy3AHk=",
57-
presharedkey: "zppaKHpHl5tvjbwuYh8uTc8lfyzfLYg3IBrwn9yCFsc="
55+
publickey: 'KG0BA4UyPilHH5qnXCfr6Lw8ynecOPor88tljLy3AHk=',
56+
presharedkey: 'zppaKHpHl5tvjbwuYh8uTc8lfyzfLYg3IBrwn9yCFsc=',
5857
);
5958
$peer->validate();
60-
}
59+
},
6160
);
6261
}
6362

@@ -74,37 +73,34 @@ class APIModelsWireGuardPeerTestCase extends TestCase
7473
enabled: true,
7574
tun: $tunnel->name->value,
7675
persistentkeepalive: 200,
77-
publickey: "KG0BA4UyPilHH5qnXCfr6Lw8ynecOPor88tljLy3AHk=",
78-
presharedkey: "zppaKHpHl5tvjbwuYh8uTc8lfyzfLYg3IBrwn9yCFsc=",
79-
async: false
76+
publickey: 'KG0BA4UyPilHH5qnXCfr6Lw8ynecOPor88tljLy3AHk=',
77+
presharedkey: 'zppaKHpHl5tvjbwuYh8uTc8lfyzfLYg3IBrwn9yCFsc=',
78+
async: false,
8079
);
8180
$peer->create(apply: true);
82-
$wg_show = new Command("wg showconf ".$peer->tun->value);
83-
$this->assert_str_contains($wg_show->output, "PublicKey = ". $peer->publickey->value);
84-
$this->assert_str_contains($wg_show->output, "PresharedKey = ". $peer->presharedkey->value);
85-
$this->assert_str_contains($wg_show->output, "PersistentKeepalive = ". $peer->persistentkeepalive->value);
81+
$wg_show = new Command('wg showconf ' . $peer->tun->value);
82+
$this->assert_str_contains($wg_show->output, 'PublicKey = ' . $peer->publickey->value);
83+
$this->assert_str_contains($wg_show->output, 'PresharedKey = ' . $peer->presharedkey->value);
84+
$this->assert_str_contains($wg_show->output, 'PersistentKeepalive = ' . $peer->persistentkeepalive->value);
8685

8786
# Update the peer and ensure the updated values are shown in 'wg showconf'
8887
$peer->from_representation(
8988
persistentkeepalive: 80,
90-
publickey: "KJoyFoK5PB5bua5ipRmzijghBSw37bffuuZ2wUN3/Dw=",
91-
presharedkey: "8O+HvB+YG8uPA9E/NJpuBUpGgHU1lHBses6Wzb37Ziw=",
92-
endpoint: "1.2.3.4",
93-
port: "12345"
89+
publickey: 'KJoyFoK5PB5bua5ipRmzijghBSw37bffuuZ2wUN3/Dw=',
90+
presharedkey: '8O+HvB+YG8uPA9E/NJpuBUpGgHU1lHBses6Wzb37Ziw=',
91+
endpoint: '1.2.3.4',
92+
port: '12345',
9493
);
9594
$peer->update(apply: true);
96-
$wg_show = new Command("wg showconf ".$peer->tun->value);
97-
$this->assert_str_contains($wg_show->output, "PublicKey = ". $peer->publickey->value);
98-
$this->assert_str_contains($wg_show->output, "PresharedKey = ". $peer->presharedkey->value);
99-
$this->assert_str_contains($wg_show->output, "PersistentKeepalive = ". $peer->persistentkeepalive->value);
100-
$this->assert_str_contains(
101-
$wg_show->output,
102-
"Endpoint = ". $peer->endpoint->value.":".$peer->port->value
103-
);
95+
$wg_show = new Command('wg showconf ' . $peer->tun->value);
96+
$this->assert_str_contains($wg_show->output, 'PublicKey = ' . $peer->publickey->value);
97+
$this->assert_str_contains($wg_show->output, 'PresharedKey = ' . $peer->presharedkey->value);
98+
$this->assert_str_contains($wg_show->output, 'PersistentKeepalive = ' . $peer->persistentkeepalive->value);
99+
$this->assert_str_contains($wg_show->output, 'Endpoint = ' . $peer->endpoint->value . ':' . $peer->port->value);
104100

105-
# Delete the peer and ensure it is no longer shown in 'wg showconf'
101+
# Delete the peer and ensure it is no longer shown in 'wg showconf'
106102
$peer->delete(apply: true);
107-
$wg_show = new Command("wg showconf ".$peer->tun->value);
108-
$this->assert_str_does_not_contain($wg_show->output, "[Peer]");
103+
$wg_show = new Command('wg showconf ' . $peer->tun->value);
104+
$this->assert_str_does_not_contain($wg_show->output, '[Peer]');
109105
}
110-
}
106+
}

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/autoloader.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require_once 'includes/functions.inc.php';
2020
# Check if the php-jwt dependency has already been installed. This is necessary to concurrently run v1 and v2 on the
2121
# same system since both packages install this dependency, which creates conflicts.
2222
# TODO: Look into the feasibility of making php-jwt its own pfSense package that both packages can share
23-
$jwt_path_prefix = (!is_dir("/etc/inc/firebase/php-jwt/src")) ? "RESTAPI/.resources/includes/" : "";
23+
$jwt_path_prefix = !is_dir('/etc/inc/firebase/php-jwt/src') ? 'RESTAPI/.resources/includes/' : '';
2424
require_once "{$jwt_path_prefix}firebase/php-jwt/src/JWT.php";
2525
require_once "{$jwt_path_prefix}firebase/php-jwt/src/JWK.php";
2626
require_once "{$jwt_path_prefix}firebase/php-jwt/src/Key.php";

0 commit comments

Comments
 (0)