From 250136756d5ae237153e4e86ec3287b78c6502cb Mon Sep 17 00:00:00 2001 From: Jared Hendrickson Date: Tue, 21 May 2024 16:36:27 -0600 Subject: [PATCH] style: ran prettier on changed files --- .../usr/local/pkg/RESTAPI/Core/Tools.inc | 5 +- .../pkg/RESTAPI/Models/AvailableInterface.inc | 82 ++-- .../RESTAPI/Models/DHCPServerCustomOption.inc | 106 +++-- .../pkg/RESTAPI/Models/DHCPServerLease.inc | 56 +-- .../pkg/RESTAPI/Models/InterfaceStats.inc | 80 ++-- .../APIModelsAvailableInterfaceTestCase.inc | 8 +- ...PIModelsDHCPServerCustomOptionTestCase.inc | 410 ++++++++---------- .../APIModelsDHCPServerLeaseTestCase.inc | 18 +- .../Tests/APIModelsInterfaceStatsTestCase.inc | 10 +- 9 files changed, 356 insertions(+), 419 deletions(-) diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Tools.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Tools.inc index a2ec85149..b4196c852 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Tools.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Tools.inc @@ -186,13 +186,14 @@ function generate_documentation(): bool { 'name' => 'Apache 2.0', 'url' => 'https://raw.githubusercontent.com/jaredhendrickson13/pfsense-api/master/LICENSE', ], - 'description' => '## Getting Started' . + 'description' => + '## Getting Started' . '
' . '- [Authentication and Authorization](https://pfrest.org/AUTHENTICATION_AND_AUTHORIZATION/)
' . '- [Working with Object IDs](https://pfrest.org/WORKING_WITH_OBJECT_IDS/)
' . '- [Queries and Filters](https://pfrest.org/QUERIES_AND_FILTERS/)
' . '- [Common Control Parameters](https://pfrest.org/COMMON_CONTROL_PARAMETERS/)
' . - '- [Working with HATEOAS](https://pfrest.org/WORKING_WITH_HATEOAS/)
' + '- [Working with HATEOAS](https://pfrest.org/WORKING_WITH_HATEOAS/)
', ], 'components' => [ 'responses' => [], diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/AvailableInterface.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/AvailableInterface.inc index 4088ceb2b..41657e8ee 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/AvailableInterface.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/AvailableInterface.inc @@ -5,34 +5,32 @@ namespace RESTAPI\Models; use RESTAPI\Core\Model; use RESTAPI\Fields\StringField; -class AvailableInterface extends Model -{ +class AvailableInterface extends Model { public StringField $if; public StringField $mac; public StringField $dmesg; public StringField $in_use_by; - public function __construct(mixed $id = null, mixed $parent_id = null, mixed $data = [], ...$options) - { + public function __construct(mixed $id = null, mixed $parent_id = null, mixed $data = [], ...$options) { # Set model attributes $this->internal_callable = 'get_all_avail_interfaces'; $this->many = true; # Set model fields $this->if = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The name of the interface.', ); $this->mac = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The MAC address of the interface.', ); $this->dmesg = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The description of the interface.', @@ -56,7 +54,11 @@ class AvailableInterface extends Model $base_ifs = get_interface_list(); # Include wireless clone interfaces - if (config_get_path('wireless/clone') && is_array(config_get_path('wireless/clone')) && count(config_get_path('wireless/clone'))) { + if ( + config_get_path('wireless/clone') && + is_array(config_get_path('wireless/clone')) && + count(config_get_path('wireless/clone')) + ) { foreach (config_get_path('wireless/clone', []) as $clone) { $base_ifs[$clone['cloneif']] = $clone; $base_ifs[$clone['cloneif']]['iswlclone'] = true; @@ -64,7 +66,11 @@ class AvailableInterface extends Model } # Include VLAN interfaces - if (config_get_path('vlans/vlan') && is_array(config_get_path('vlans/vlan')) && count(config_get_path('vlans/vlan'))) { + if ( + config_get_path('vlans/vlan') && + is_array(config_get_path('vlans/vlan')) && + count(config_get_path('vlans/vlan')) + ) { foreach (config_get_path('vlans/vlan', []) as $vlan) { $base_ifs[$vlan['vlanif']] = $vlan; $base_ifs[$vlan['vlanif']]['isvlan'] = true; @@ -72,7 +78,11 @@ class AvailableInterface extends Model } # Include Bridge interfaces - if (config_get_path('bridges/bridged') && is_array(config_get_path('bridges/bridged')) && count(config_get_path('bridges/bridged'))) { + if ( + config_get_path('bridges/bridged') && + is_array(config_get_path('bridges/bridged')) && + count(config_get_path('bridges/bridged')) + ) { foreach (config_get_path('bridges/bridged', []) as $bridge) { $base_ifs[$bridge['bridgeif']] = $bridge; $base_ifs[$bridge['bridgeif']]['isbridge'] = true; @@ -80,7 +90,11 @@ class AvailableInterface extends Model } # Include GIF interfaces - if (config_get_path('gifs/gif') && is_array(config_get_path('gifs/gif')) && count(config_get_path('gifs/gif'))) { + if ( + config_get_path('gifs/gif') && + is_array(config_get_path('gifs/gif')) && + count(config_get_path('gifs/gif')) + ) { foreach (config_get_path('gifs/gif', []) as $gif) { $base_ifs[$gif['gifif']] = $gif; $base_ifs[$gif['gifif']]['isgif'] = true; @@ -88,7 +102,11 @@ class AvailableInterface extends Model } # Include GRE interfaces - if (config_get_path('gres/gre') && is_array(config_get_path('gres/gre')) && count(config_get_path('gres/gre'))) { + if ( + config_get_path('gres/gre') && + is_array(config_get_path('gres/gre')) && + count(config_get_path('gres/gre')) + ) { foreach (config_get_path('gres/gre', []) as $gre) { $base_ifs[$gre['greif']] = $gre; $base_ifs[$gre['greif']]['isgre'] = true; @@ -96,7 +114,11 @@ class AvailableInterface extends Model } # Include LAGG interfaces - if (config_get_path('laggs/lagg') && is_array(config_get_path('laggs/lagg')) && count(config_get_path('laggs/lagg'))) { + if ( + config_get_path('laggs/lagg') && + is_array(config_get_path('laggs/lagg')) && + count(config_get_path('laggs/lagg')) + ) { foreach (config_get_path('laggs/lagg', []) as $lagg) { $base_ifs[$lagg['laggif']] = $lagg; $base_ifs[$lagg['laggif']]['islagg'] = true; @@ -111,38 +133,48 @@ class AvailableInterface extends Model } # Include QinQ interfaces - if (config_get_path('qinqs/qinqentry') && is_array(config_get_path('qinqs/qinqentry')) && count(config_get_path('qinqs/qinqentry'))) { + if ( + config_get_path('qinqs/qinqentry') && + is_array(config_get_path('qinqs/qinqentry')) && + count(config_get_path('qinqs/qinqentry')) + ) { foreach (config_get_path('qinqs/qinqentry', []) as $qinq) { $base_ifs["{$qinq['vlanif']}"]['descr'] = "VLAN {$qinq['tag']} on {$qinq['if']}"; $base_ifs["{$qinq['vlanif']}"]['isqinq'] = true; # QinQ members $qinqifs = explode(' ', $qinq['members']); foreach ($qinqifs as $qinqif) { - $base_ifs["{$qinq['vlanif']}.{$qinqif}"]['descr'] = "QinQ {$qinqif} on VLAN {$qinq['tag']} on {$qinq['if']}"; + $base_ifs["{$qinq['vlanif']}.{$qinqif}"][ + 'descr' + ] = "QinQ {$qinqif} on VLAN {$qinq['tag']} on {$qinq['if']}"; $base_ifs["{$qinq['vlanif']}.{$qinqif}"]['isqinq'] = true; } } } # Include PPP interfaces - if (config_get_path('ppps/ppp') && is_array(config_get_path('ppps/ppp')) && count(config_get_path('ppps/ppp'))) { + if ( + config_get_path('ppps/ppp') && + is_array(config_get_path('ppps/ppp')) && + count(config_get_path('ppps/ppp')) + ) { foreach (config_get_path('ppps/ppp', []) as $pppid => $ppp) { $portname = $ppp['if']; $base_ifs[$portname] = $ppp; $base_ifs[$portname]['isppp'] = true; $ports_base = basename($ppp['ports']); if (isset($ppp['descr'])) { - $base_ifs[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base}) - {$ppp['descr']}"; - } else if (isset($ppp['username'])) { - $base_ifs[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base}) - {$ppp['username']}"; + $base_ifs[$portname]['descr'] = strtoupper($ppp['if']) . "({$ports_base}) - {$ppp['descr']}"; + } elseif (isset($ppp['username'])) { + $base_ifs[$portname]['descr'] = strtoupper($ppp['if']) . "({$ports_base}) - {$ppp['username']}"; } else { - $base_ifs[$portname]['descr'] = strtoupper($ppp['if']). "({$ports_base})"; + $base_ifs[$portname]['descr'] = strtoupper($ppp['if']) . "({$ports_base})"; } } } # Include OpenVPN interfaces - $ovpn_descrs = array(); + $ovpn_descrs = []; if (config_get_path('openvpn') && is_array(config_get_path('openvpn'))) { if (config_get_path('openvpn/openvpn-server') && is_array(config_get_path('openvpn/openvpn-server'))) { foreach (config_get_path('openvpn/openvpn-server', []) as $s) { @@ -163,23 +195,23 @@ class AvailableInterface extends Model # Include IPsec interfaces $ipsec_descrs = interface_ipsec_vti_list_all(); foreach ($ipsec_descrs as $ifname => $ifdescr) { - $base_ifs[$ifname] = array('descr' => $ifdescr); + $base_ifs[$ifname] = ['descr' => $ifdescr]; } # Loop through our array and check if interface is in use foreach ($base_ifs as $pid => $conf) { # Add the physical interface ID to the configuration - $base_ifs[$pid]["if"] = $pid; + $base_ifs[$pid]['if'] = $pid; # Check if there is a configuration for this interface $pf_id = NetworkInterface::query(if: $pid); # Check if the pfSense interface ID was found if ($pf_id->exists()) { - $base_ifs[$pid]["in_use_by"] = $pf_id->first()->id;; + $base_ifs[$pid]['in_use_by'] = $pf_id->first()->id; } } return $base_ifs; } -} \ No newline at end of file +} diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServerCustomOption.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServerCustomOption.inc index 886444bde..ef3d00f4c 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServerCustomOption.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServerCustomOption.inc @@ -12,14 +12,12 @@ use RESTAPI\Responses\ValidationError; /** * Defines a model that configures custom DHCP options. */ -class DHCPServerCustomOption extends Model -{ +class DHCPServerCustomOption extends Model { public IntegerField $number; public StringField $type; public Base64Field $value; - public function __construct(mixed $id = null, mixed $parent_id = null, mixed $data = [], ...$options) - { + public function __construct(mixed $id = null, mixed $parent_id = null, mixed $data = [], ...$options) { # Set model attributes $this->parent_model_class = 'DHCPServer'; $this->config_path = 'numberoptions/item'; @@ -31,28 +29,25 @@ class DHCPServerCustomOption extends Model unique: true, minimum: 1, maximum: 254, - help_text: 'The DHCP option number to configure.' + help_text: 'The DHCP option number to configure.', ); $this->type = new StringField( required: true, choices: [ - "text", - "string", - "boolean", - "unsigned integer 8", - "unsigned integer 16", - "unsigned integer 32", - "signed integer 8", - "signed integer 16", - "signed integer 32", - "ip-address" + 'text', + 'string', + 'boolean', + 'unsigned integer 8', + 'unsigned integer 16', + 'unsigned integer 32', + 'signed integer 8', + 'signed integer 16', + 'signed integer 32', + 'ip-address', ], - help_text: 'The type of value to configure for the option.' - ); - $this->value = new Base64Field( - required: true, - help_text: 'The value to configure for the option.' + help_text: 'The type of value to configure for the option.', ); + $this->value = new Base64Field(required: true, help_text: 'The value to configure for the option.'); parent::__construct($id, $parent_id, $data, ...$options); } @@ -73,79 +68,97 @@ class DHCPServerCustomOption extends Model */ public function validate_value(string $value): string { # Define regular expressions for string validation - $str_rgx_1 = '/^"[^"]*"$/'; // Regex to use when checking if string type value is enclosed in quotes - $str_rgx_2 = '/^[0-9a-f]{2}(?:\:[0-9a-f]{2})*$/i'; // Regex to use when checking if string type value is hex - $bool_opts = ["true", "false", "on", "off"]; // Boolean options + $str_rgx_1 = '/^"[^"]*"$/'; // Regex to use when checking if string type value is enclosed in quotes + $str_rgx_2 = '/^[0-9a-f]{2}(?:\:[0-9a-f]{2})*$/i'; // Regex to use when checking if string type value is hex + $bool_opts = ['true', 'false', 'on', 'off']; // Boolean options # Validate this field when the type is set to 'text' - if ($this->type->value === "text" and strstr($value, '"')) { + if ($this->type->value === 'text' and strstr($value, '"')) { throw new ValidationError( message: "Field `value` must not contain quotes when the type is set to 'text'.", - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_NOT_CONTAIN_QUOTES_WITH_TEXT_TYPE" + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_NOT_CONTAIN_QUOTES_WITH_TEXT_TYPE', ); } # Validate this field when the type is set to 'string' - elseif ($this->type->value === "string" and !preg_match($str_rgx_1, $value) and !preg_match($str_rgx_2, $value)) { + elseif ( + $this->type->value === 'string' and + !preg_match($str_rgx_1, $value) and + !preg_match($str_rgx_2, $value) + ) { throw new ValidationError( message: "Field `value` must be a string enclosed in quotes or a hex string when the type is set to 'string'.", - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_STRING_OR_HEX_STRING_WITH_STRING_TYPE" + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_STRING_OR_HEX_STRING_WITH_STRING_TYPE', ); } # Validate this field when the type is set to 'boolean' - elseif ($this->type->value === "boolean" and !in_array($value, $bool_opts, true)) { + elseif ($this->type->value === 'boolean' and !in_array($value, $bool_opts, true)) { throw new ValidationError( - message: "Field `value` must be one of the following: [" . implode(", ", $bool_opts) . "] ". + message: 'Field `value` must be one of the following: [' . + implode(', ', $bool_opts) . + '] ' . "when the type is set to 'boolean'.", - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_ONE_OF_BOOLEAN_OPTIONS_WITH_BOOLEAN_TYPE" + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_ONE_OF_BOOLEAN_OPTIONS_WITH_BOOLEAN_TYPE', ); } # Validate this field when the type is set to 'unsigned integer 8' - elseif ($this->type->value === "unsigned integer 8" and (!is_numeric($value) or $value < 0 or $value > 255)) { + elseif ($this->type->value === 'unsigned integer 8' and (!is_numeric($value) or $value < 0 or $value > 255)) { throw new ValidationError( message: "Field `value` must be a number between 0 and 255 when the type is set to 'unsigned integer 8'.", - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_8_TYPE" + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_8_TYPE', ); } # Validate this field when the type is set to 'unsigned integer 16' - elseif ($this->type->value === "unsigned integer 16" and (!is_numeric($value) or $value < 0 or $value > 65535)) { + elseif ( + $this->type->value === 'unsigned integer 16' and + (!is_numeric($value) or $value < 0 or $value > 65535) + ) { throw new ValidationError( message: "Field `value` must be a number between 0 and 65535 when the type is set to 'unsigned integer 16'.", - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_16_TYPE" + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_16_TYPE', ); } # Validate this field when the type is set to 'unsigned integer 32' - elseif ($this->type->value === "unsigned integer 32" and (!is_numeric($value) or $value < 0 or $value > 4294967295)) { + elseif ( + $this->type->value === 'unsigned integer 32' and + (!is_numeric($value) or $value < 0 or $value > 4294967295) + ) { throw new ValidationError( message: "Field `value` must be a number between 0 and 4294967295 when the type is set to 'unsigned integer 32'.", - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_32_TYPE" + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_32_TYPE', ); } # Validate this field when the type is set to 'signed integer 8' - elseif ($this->type->value === "signed integer 8" and (!is_numeric($value) or $value < -128 or $value > 127)) { + elseif ($this->type->value === 'signed integer 8' and (!is_numeric($value) or $value < -128 or $value > 127)) { throw new ValidationError( message: "Field `value` must be a number between -128 and 127 when the type is set to 'signed integer 8'.", - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_SIGNED_INTEGER_8_TYPE" + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_SIGNED_INTEGER_8_TYPE', ); } # Validate this field when the type is set to 'signed integer 16' - elseif ($this->type->value === "signed integer 16" and (!is_numeric($value) or $value < -32768 or $value > 32767)) { + elseif ( + $this->type->value === 'signed integer 16' and + (!is_numeric($value) or $value < -32768 or $value > 32767) + ) { throw new ValidationError( message: "Field `value` must be a number between -32768 and 32767 when the type is set to 'signed integer 16'.", - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_SIGNED_INTEGER_16_TYPE" + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_SIGNED_INTEGER_16_TYPE', ); } # Validate this field when the type is set to 'signed integer 32' - elseif ($this->type->value === "signed integer 32" and (!is_numeric($value) or $value < -2147483648 or $value > 2147483647)) { + elseif ( + $this->type->value === 'signed integer 32' and + (!is_numeric($value) or $value < -2147483648 or $value > 2147483647) + ) { throw new ValidationError( message: "Field `value` must be a number between -2147483648 and 2147483647 when the type is set to 'signed integer 32'.", - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_SIGNED_INTEGER_32_TYPE" + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_SIGNED_INTEGER_32_TYPE', ); } # Validate this field when the type is set to 'ip-address' - elseif ($this->type->value === "ip-address" and !is_ipaddrv4($value) and !is_fqdn($value)) { + elseif ($this->type->value === 'ip-address' and !is_ipaddrv4($value) and !is_fqdn($value)) { throw new ValidationError( message: "Field `value` must be a valid IPv4 address or hostname when the type is set to 'ip-address'.", - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_VALID_IPV4_WITH_IP_ADDRESS_TYPE" + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_VALID_IPV4_WITH_IP_ADDRESS_TYPE', ); } @@ -156,8 +169,7 @@ class DHCPServerCustomOption extends Model /** * Applies changes the DHCP Server. */ - public function apply(): void - { + public function apply(): void { (new DHCPServerApplyDispatcher(async: $this->async))->spawn_process(); } -} \ No newline at end of file +} diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServerLease.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServerLease.inc index 7729fc353..fdc30783b 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServerLease.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/DHCPServerLease.inc @@ -9,8 +9,7 @@ use RESTAPI\Fields\StringField; /** * Defines a model that represents a DHCP lease. */ -class DHCPServerLease extends Model -{ +class DHCPServerLease extends Model { public StringField $ip; public StringField $mac; public StringField $hostname; @@ -21,61 +20,35 @@ class DHCPServerLease extends Model public StringField $online_status; public StringField $descr; - public function __construct(mixed $id = null, mixed $parent_id = null, mixed $data = [], ...$options) - { + public function __construct(mixed $id = null, mixed $parent_id = null, mixed $data = [], ...$options) { # Set model attributes $this->internal_callable = 'get_dhcp_leases'; $this->many = true; # Set model fields - $this->ip = new StringField( - default: null, - allow_null: true, - help_text: 'The IP address of the lease.' - ); - $this->mac = new StringField( - default: null, - allow_null: true, - help_text: 'The MAC address of the lease.' - ); - $this->hostname = new StringField( - default: null, - allow_null: true, - help_text: 'The hostname of the lease.' - ); + $this->ip = new StringField(default: null, allow_null: true, help_text: 'The IP address of the lease.'); + $this->mac = new StringField(default: null, allow_null: true, help_text: 'The MAC address of the lease.'); + $this->hostname = new StringField(default: null, allow_null: true, help_text: 'The hostname of the lease.'); $this->if = new InterfaceField( default: null, allow_null: true, - help_text: 'The interface the lease was registered on.' - ); - $this->starts = new StringField( - default: null, - allow_null: true, - help_text: 'The start time of the lease.' - ); - $this->ends = new StringField( - default: null, - allow_null: true, - help_text: 'The end time of the lease.' + help_text: 'The interface the lease was registered on.', ); + $this->starts = new StringField(default: null, allow_null: true, help_text: 'The start time of the lease.'); + $this->ends = new StringField(default: null, allow_null: true, help_text: 'The end time of the lease.'); $this->active_status = new StringField( default: null, allow_null: true, internal_name: 'act', - help_text: 'The active status of the lease.' + help_text: 'The active status of the lease.', ); $this->online_status = new StringField( default: null, allow_null: true, internal_name: 'online', - help_text: 'The online status of the lease.' + help_text: 'The online status of the lease.', ); - $this->descr = new StringField( - default: null, - allow_null: true, - help_text: 'The description of the lease.' - ); - + $this->descr = new StringField(default: null, allow_null: true, help_text: 'The description of the lease.'); parent::__construct($id, $parent_id, $data, ...$options); } @@ -84,8 +57,7 @@ class DHCPServerLease extends Model * Obtains the DHCP leases from the system internally. This is the internal callable for the Model. * @return array An array of recent/current DHCP leases */ - protected function get_dhcp_leases(): array - { - return system_get_dhcpleases()["lease"]; + protected function get_dhcp_leases(): array { + return system_get_dhcpleases()['lease']; } -} \ No newline at end of file +} diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/InterfaceStats.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/InterfaceStats.inc index 8e6ca4f3a..2cf8adbbc 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/InterfaceStats.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/InterfaceStats.inc @@ -10,8 +10,7 @@ use RESTAPI\Fields\StringField; /** * Defines a model that represents interface statistics and detailed interface information. */ -class InterfaceStats extends Model -{ +class InterfaceStats extends Model { public StringField $name; public StringField $descr; public StringField $hwif; @@ -40,147 +39,122 @@ class InterfaceStats extends Model public StringField $gateway; public StringField $gatewayv6; - public function __construct(mixed $id = null, mixed $parent_id = null, mixed $data = [], ...$options) - { + public function __construct(mixed $id = null, mixed $parent_id = null, mixed $data = [], ...$options) { # Set model attributes $this->internal_callable = 'get_interface_stats'; $this->many = true; # Set model fields $this->name = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The name of the interface.', ); $this->descr = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The description of the interface.', ); $this->hwif = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The hardware interface name of the interface.', ); $this->macaddr = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The MAC address of the interface.', ); $this->mtu = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The MTU of the interface.', ); - $this->enable = new BooleanField( - default: false, - help_text: 'Whether the interface is enabled.', - ); + $this->enable = new BooleanField(default: false, help_text: 'Whether the interface is enabled.'); $this->status = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The status of the interface.', ); $this->ipaddr = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The IPv4 address of the interface.', ); $this->subnet = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The IPv4 subnet of the interface.', ); $this->linklocal = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The IPv6 link-local address of the interface.', ); $this->ipaddrv6 = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The IPv6 address of the interface.', ); $this->subnetv6 = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The IPv6 subnet of the interface.', ); - $this->inerrs = new IntegerField( - default: 0, - help_text: 'The number of inbound errors on the interface.', - ); - $this->outerrs = new IntegerField( - default: 0, - help_text: 'The number of outbound errors on the interface.', - ); - $this->collisions = new IntegerField( - default: 0, - help_text: 'The number of collisions on the interface.', - ); - $this->inbytes = new IntegerField( - default: 0, - help_text: 'The number of inbound bytes on the interface.', - ); + $this->inerrs = new IntegerField(default: 0, help_text: 'The number of inbound errors on the interface.'); + $this->outerrs = new IntegerField(default: 0, help_text: 'The number of outbound errors on the interface.'); + $this->collisions = new IntegerField(default: 0, help_text: 'The number of collisions on the interface.'); + $this->inbytes = new IntegerField(default: 0, help_text: 'The number of inbound bytes on the interface.'); $this->inbytespass = new IntegerField( default: 0, help_text: 'The number of inbound bytes passed on the interface.', ); - $this->outbytes = new IntegerField( - default: 0, - help_text: 'The number of outbound bytes on the interface.', - ); + $this->outbytes = new IntegerField(default: 0, help_text: 'The number of outbound bytes on the interface.'); $this->outbytespass = new IntegerField( default: 0, help_text: 'The number of outbound bytes passed on the interface.', ); - $this->inpkts = new IntegerField( - default: 0, - help_text: 'The number of inbound packets on the interface.', - ); + $this->inpkts = new IntegerField(default: 0, help_text: 'The number of inbound packets on the interface.'); $this->inpktspass = new IntegerField( default: 0, help_text: 'The number of inbound packets passed on the interface.', ); - $this->outpkts = new IntegerField( - default: 0, - help_text: 'The number of outbound packets on the interface.', - ); + $this->outpkts = new IntegerField(default: 0, help_text: 'The number of outbound packets on the interface.'); $this->outpktspass = new IntegerField( default: 0, help_text: 'The number of outbound packets passed on the interface.', ); $this->dhcplink = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The DHCP link status of the interface.', ); $this->media = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The speed/duplex of the interface.', ); $this->gateway = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The IPv4 gateway of the interface.', ); $this->gatewayv6 = new StringField( - default: "", + default: '', allow_empty: true, allow_null: true, help_text: 'The IPv6 gateway of the interface.', @@ -199,10 +173,10 @@ class InterfaceStats extends Model $if_info = []; foreach ($if_descrs as $if_descr => $if_name) { - $if = ["name" => $if_descr, "descr" => $if_name]; + $if = ['name' => $if_descr, 'descr' => $if_name]; $if = $if + get_interface_info($if_descr); $if_info[] = $if; } return $if_info; } -} \ No newline at end of file +} diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsAvailableInterfaceTestCase.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsAvailableInterfaceTestCase.inc index ad5c1773a..94529459c 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsAvailableInterfaceTestCase.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsAvailableInterfaceTestCase.inc @@ -5,13 +5,11 @@ namespace RESTAPI\Tests; use RESTAPI\Core\TestCase; use RESTAPI\Models\AvailableInterface; -class APIModelsAvailableInterfaceTestCase extends TestCase -{ +class APIModelsAvailableInterfaceTestCase extends TestCase { /** * Checks that we can correctly read AvailableInterface objects */ - public function test_read(): void - { + public function test_read(): void { # Create a AvailableInterface to populate an interface $available_interface = AvailableInterface::read_all(); $this->assert_is_true($available_interface->exists()); @@ -19,4 +17,4 @@ class APIModelsAvailableInterfaceTestCase extends TestCase $this->assert_is_not_empty($available_interface->first()->mac->value); $this->assert_is_not_empty($available_interface->first()->in_use_by->value); } -} \ No newline at end of file +} diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsDHCPServerCustomOptionTestCase.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsDHCPServerCustomOptionTestCase.inc index bcfc04891..6f300de31 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsDHCPServerCustomOptionTestCase.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsDHCPServerCustomOptionTestCase.inc @@ -6,520 +6,472 @@ use RESTAPI\Core\TestCase; use RESTAPI\Models\DHCPServerBackend; use RESTAPI\Models\DHCPServerCustomOption; -class APIModelsDHCPServerCustomOptionTestCase extends TestCase -{ +class APIModelsDHCPServerCustomOptionTestCase extends TestCase { /** * Checks that the `value` field is validated correctly when the `type` field is set to `text`. */ - public function test_validate_value_with_bad_text_type_value(): void - { + public function test_validate_value_with_bad_text_type_value(): void { $this->assert_throws_response( - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_NOT_CONTAIN_QUOTES_WITH_TEXT_TYPE", + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_NOT_CONTAIN_QUOTES_WITH_TEXT_TYPE', code: 400, - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "text", - value: '"This is a bad value."' + type: 'text', + value: '"This is a bad value."', ); $option->validate(); - } + }, ); $this->assert_does_not_throw( - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "text", - value: "This is a good value." + type: 'text', + value: 'This is a good value.', ); $option->validate(); - } + }, ); } /** * Checks that the `value` field is validated correctly when the `type` field is set to `string`. */ - public function test_validate_value_with_bad_string_type_value(): void - { + public function test_validate_value_with_bad_string_type_value(): void { $this->assert_throws_response( - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_STRING_OR_HEX_STRING_WITH_STRING_TYPE", + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_STRING_OR_HEX_STRING_WITH_STRING_TYPE', code: 400, - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "string", - value: "This is a bad value." + type: 'string', + value: 'This is a bad value.', ); $option->validate(); - } + }, ); $this->assert_does_not_throw( - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "string", - value: "\"This is a good value.\"" + type: 'string', + value: "\"This is a good value.\"", ); $option->validate(); - } + }, ); $this->assert_does_not_throw( - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "string", - value: "00:11:22:33:44:55" + type: 'string', + value: '00:11:22:33:44:55', ); $option->validate(); - } + }, ); } /** * Checks that the `value` field is validated correctly when the `type` field is set to `boolean`. */ - public function test_validate_value_with_bad_boolean_type_value(): void - { + public function test_validate_value_with_bad_boolean_type_value(): void { $this->assert_throws_response( - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_ONE_OF_BOOLEAN_OPTIONS_WITH_BOOLEAN_TYPE", + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_ONE_OF_BOOLEAN_OPTIONS_WITH_BOOLEAN_TYPE', code: 400, - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "boolean", - value: "This is a bad value." + type: 'boolean', + value: 'This is a bad value.', ); $option->validate(); - } + }, ); $this->assert_does_not_throw( - callable: function() { - $option = new DHCPServerCustomOption( - parent_id: "lan", - number: 5, - type: "boolean", - value: "true" - ); + callable: function () { + $option = new DHCPServerCustomOption(parent_id: 'lan', number: 5, type: 'boolean', value: 'true'); $option->validate(); - } + }, ); $this->assert_does_not_throw( - callable: function() { - $option = new DHCPServerCustomOption( - parent_id: "lan", - number: 5, - type: "boolean", - value: "false" - ); + callable: function () { + $option = new DHCPServerCustomOption(parent_id: 'lan', number: 5, type: 'boolean', value: 'false'); $option->validate(); - } + }, ); $this->assert_does_not_throw( - callable: function() { - $option = new DHCPServerCustomOption( - parent_id: "lan", - number: 5, - type: "boolean", - value: "on" - ); + callable: function () { + $option = new DHCPServerCustomOption(parent_id: 'lan', number: 5, type: 'boolean', value: 'on'); $option->validate(); - } + }, ); $this->assert_does_not_throw( - callable: function() { - $option = new DHCPServerCustomOption( - parent_id: "lan", - number: 5, - type: "boolean", - value: "off" - ); + callable: function () { + $option = new DHCPServerCustomOption(parent_id: 'lan', number: 5, type: 'boolean', value: 'off'); $option->validate(); - } + }, ); } /** * Checks that the `value` field is validated correctly when the `type` field is set to `unsigned integer 8`. */ - public function test_validate_value_with_bad_unsigned_integer_8_type_value(): void - { + public function test_validate_value_with_bad_unsigned_integer_8_type_value(): void { $this->assert_throws_response( - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_8_TYPE", + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_8_TYPE', code: 400, - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "unsigned integer 8", - value: "This is a bad value." + type: 'unsigned integer 8', + value: 'This is a bad value.', ); $option->validate(); - } + }, ); $this->assert_throws_response( - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_8_TYPE", + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_8_TYPE', code: 400, - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "unsigned integer 8", - value: "256" + type: 'unsigned integer 8', + value: '256', ); $option->validate(); - } + }, ); $this->assert_does_not_throw( - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "unsigned integer 8", - value: "255" + type: 'unsigned integer 8', + value: '255', ); $option->validate(); - } + }, ); } /** * Checks that the `value` field is validated correctly when the `type` field is set to `unsigned integer 16`. */ - public function test_validate_value_with_bad_unsigned_integer_16_type_value(): void - { + public function test_validate_value_with_bad_unsigned_integer_16_type_value(): void { $this->assert_throws_response( - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_16_TYPE", + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_16_TYPE', code: 400, - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "unsigned integer 16", - value: "This is a bad value." + type: 'unsigned integer 16', + value: 'This is a bad value.', ); $option->validate(); - } + }, ); $this->assert_throws_response( - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_16_TYPE", + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_16_TYPE', code: 400, - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "unsigned integer 16", - value: "65536" + type: 'unsigned integer 16', + value: '65536', ); $option->validate(); - } + }, ); $this->assert_does_not_throw( - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "unsigned integer 16", - value: "65535" + type: 'unsigned integer 16', + value: '65535', ); $option->validate(); - } + }, ); } /** * Checks that the `value` field is validated correctly when the `type` field is set to `unsigned integer 32`. */ - public function test_validate_value_with_bad_unsigned_integer_32_type_value(): void - { + public function test_validate_value_with_bad_unsigned_integer_32_type_value(): void { $this->assert_throws_response( - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_32_TYPE", + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_32_TYPE', code: 400, - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "unsigned integer 32", - value: "This is a bad value." + type: 'unsigned integer 32', + value: 'This is a bad value.', ); $option->validate(); - } + }, ); $this->assert_throws_response( - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_32_TYPE", + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_UNSIGNED_INTEGER_32_TYPE', code: 400, - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "unsigned integer 32", - value: "4294967296" + type: 'unsigned integer 32', + value: '4294967296', ); $option->validate(); - } + }, ); $this->assert_does_not_throw( - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "unsigned integer 32", - value: "4294967295" + type: 'unsigned integer 32', + value: '4294967295', ); $option->validate(); - } + }, ); } /** * Checks that the `value` field is validated correctly when the `type` field is set to `signed integer 8`. */ - public function test_validate_value_with_bad_signed_integer_8_type_value(): void - { + public function test_validate_value_with_bad_signed_integer_8_type_value(): void { $this->assert_throws_response( - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_SIGNED_INTEGER_8_TYPE", + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_SIGNED_INTEGER_8_TYPE', code: 400, - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "signed integer 8", - value: "This is a bad value." + type: 'signed integer 8', + value: 'This is a bad value.', ); $option->validate(); - } + }, ); $this->assert_throws_response( - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_SIGNED_INTEGER_8_TYPE", + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_SIGNED_INTEGER_8_TYPE', code: 400, - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "signed integer 8", - value: "-129" + type: 'signed integer 8', + value: '-129', ); $option->validate(); - } + }, ); $this->assert_does_not_throw( - callable: function() { + callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "signed integer 8", - value: "-128" + type: 'signed integer 8', + value: '-128', ); $option->validate(); - } + }, ); } /** * Checks that the `value` field is validated correctly when the `type` field is set to `signed integer 16`. */ - public function test_validate_value_with_bad_signed_integer_16_type_value(): void - { + public function test_validate_value_with_bad_signed_integer_16_type_value(): void { $this->assert_throws_response( - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_SIGNED_INTEGER_16_TYPE", + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_SIGNED_INTEGER_16_TYPE', code: 400, callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "signed integer 16", - value: "This is a bad value." + type: 'signed integer 16', + value: 'This is a bad value.', ); $option->validate(); - } + }, ); } /** * Checks that the `value` field is validated correctly when the `type` field is set to `signed integer 32`. */ - public function test_validate_value_with_bad_signed_integer_32_type_value(): void - { + public function test_validate_value_with_bad_signed_integer_32_type_value(): void { $this->assert_throws_response( - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_SIGNED_INTEGER_32_TYPE", + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_SIGNED_INTEGER_32_TYPE', code: 400, callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "signed integer 32", - value: "This is a bad value." + type: 'signed integer 32', + value: 'This is a bad value.', ); $option->validate(); - } + }, ); $this->assert_throws_response( - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_SIGNED_INTEGER_32_TYPE", + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_IN_RANGE_WITH_SIGNED_INTEGER_32_TYPE', code: 400, callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "signed integer 32", - value: "-2147483649" + type: 'signed integer 32', + value: '-2147483649', ); $option->validate(); - } + }, ); $this->assert_does_not_throw( callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "signed integer 32", - value: "-2147483648" + type: 'signed integer 32', + value: '-2147483648', ); $option->validate(); - } + }, ); $this->assert_does_not_throw( callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "signed integer 32", - value: "2147483647" + type: 'signed integer 32', + value: '2147483647', ); $option->validate(); - } + }, ); } /** * Checks that the `value` field is validated correctly when the `type` field is set to `ip-address`. */ - public function test_validate_value_with_bad_ip_address_type_value(): void - { + public function test_validate_value_with_bad_ip_address_type_value(): void { $this->assert_throws_response( - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_VALID_IPV4_WITH_IP_ADDRESS_TYPE", + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_VALID_IPV4_WITH_IP_ADDRESS_TYPE', code: 400, callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "ip-address", - value: "This is a bad value." + type: 'ip-address', + value: 'This is a bad value.', ); $option->validate(); - } + }, ); $this->assert_throws_response( - response_id: "DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_VALID_IPV4_WITH_IP_ADDRESS_TYPE", + response_id: 'DHCP_SERVER_CUSTOM_OPTION_VALUE_MUST_BE_VALID_IPV4_WITH_IP_ADDRESS_TYPE', code: 400, callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "ip-address", - value: "192.168.1.256" + type: 'ip-address', + value: '192.168.1.256', ); $option->validate(); - } + }, ); $this->assert_does_not_throw( callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "ip-address", - value: "192.168.1.1" + type: 'ip-address', + value: '192.168.1.1', ); $option->validate(); - } + }, ); $this->assert_does_not_throw( callable: function () { $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "ip-address", - value: "example.com" + type: 'ip-address', + value: 'example.com', ); $option->validate(); - } + }, ); } /** * Checks that we can create, update and delete DHCP Server Custom Options. */ - public function test_crud():void { + public function test_crud(): void { # Custom options are currently only available for ISC DHCP, ensure the backend is set - $backend = new DHCPServerBackend(backend: "isc", async: false); + $backend = new DHCPServerBackend(backend: 'isc', async: false); $backend->update(apply: true); $option = new DHCPServerCustomOption( - parent_id: "lan", + parent_id: 'lan', number: 5, - type: "text", - value: "This is a good value.", - async: false + type: 'text', + value: 'This is a good value.', + async: false, ); $option->create(apply: true); - $dhcpd_config = file_get_contents("/var/dhcpd/etc/dhcpd.conf"); + $dhcpd_config = file_get_contents('/var/dhcpd/etc/dhcpd.conf'); + $this->assert_str_contains($dhcpd_config, "option custom-$option->parent_id-$option->id code 5 = text"); $this->assert_str_contains( $dhcpd_config, - "option custom-$option->parent_id-$option->id code 5 = text" - ); - $this->assert_str_contains( - $dhcpd_config, - "option custom-$option->parent_id-$option->id \"This is a good value.\"" + "option custom-$option->parent_id-$option->id \"This is a good value.\"", ); - $option->from_representation( - parent_id: "lan", - number: 10, - type: "ip-address", - value: "1.2.3.4" - ); + $option->from_representation(parent_id: 'lan', number: 10, type: 'ip-address', value: '1.2.3.4'); $option->create(apply: true); - $dhcpd_config = file_get_contents("/var/dhcpd/etc/dhcpd.conf"); - $this->assert_str_contains( - $dhcpd_config, - "option custom-$option->parent_id-$option->id code 10 = ip-address" - ); - $this->assert_str_contains( - $dhcpd_config, - "option custom-$option->parent_id-$option->id 1.2.3.4" - ); + $dhcpd_config = file_get_contents('/var/dhcpd/etc/dhcpd.conf'); + $this->assert_str_contains($dhcpd_config, "option custom-$option->parent_id-$option->id code 10 = ip-address"); + $this->assert_str_contains($dhcpd_config, "option custom-$option->parent_id-$option->id 1.2.3.4"); $option->delete(apply: true); - $dhcpd_config = file_get_contents("/var/dhcpd/etc/dhcpd.conf"); - $this->assert_str_does_not_contain( - $dhcpd_config, - "option custom-$option->parent_id-$option->id" - ); + $dhcpd_config = file_get_contents('/var/dhcpd/etc/dhcpd.conf'); + $this->assert_str_does_not_contain($dhcpd_config, "option custom-$option->parent_id-$option->id"); } -} \ No newline at end of file +} diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsDHCPServerLeaseTestCase.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsDHCPServerLeaseTestCase.inc index bb670cabb..f09eebf20 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsDHCPServerLeaseTestCase.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsDHCPServerLeaseTestCase.inc @@ -6,30 +6,28 @@ use RESTAPI\Core\TestCase; use RESTAPI\Models\DHCPServerLease; use RESTAPI\Models\DHCPServerStaticMapping; -class APIModelsDHCPServerLeaseTestCase extends TestCase -{ +class APIModelsDHCPServerLeaseTestCase extends TestCase { /** * Checks that we can correct read DHCP leases */ public function test_read(): void { # Create a DHCP server static mapping to populate a DHCP lease $static_mapping = new DHCPServerStaticMapping( - parent_id: "lan", - mac: "00:00:00:00:00:00", - ipaddr: "192.168.1.2", - hostname: "test-hostname", - descr: "test-description", + parent_id: 'lan', + mac: '00:00:00:00:00:00', + ipaddr: '192.168.1.2', + hostname: 'test-hostname', + descr: 'test-description', async: false, ); $static_mapping->create(apply: true); # Read current DHCP leases and ensure our static mapping is present - $lease_q = DHCPServerLease::query(mac: "00:00:00:00:00:00"); + $lease_q = DHCPServerLease::query(mac: '00:00:00:00:00:00'); $this->assert_is_true($lease_q->exists()); $this->assert_equals($lease_q->first()->ip->value, $static_mapping->ipaddr->value); $this->assert_equals($lease_q->first()->mac->value, $static_mapping->mac->value); $this->assert_equals($lease_q->first()->hostname->value, $static_mapping->hostname->value); $this->assert_equals($lease_q->first()->descr->value, $static_mapping->descr->value); } - -} \ No newline at end of file +} diff --git a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsInterfaceStatsTestCase.inc b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsInterfaceStatsTestCase.inc index f0d757cea..983236c5c 100644 --- a/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsInterfaceStatsTestCase.inc +++ b/pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsInterfaceStatsTestCase.inc @@ -5,15 +5,13 @@ namespace RESTAPI\Tests; use RESTAPI\Core\TestCase; use RESTAPI\Models\InterfaceStats; -class APIModelsInterfaceStatsTestCase extends TestCase -{ +class APIModelsInterfaceStatsTestCase extends TestCase { /** * Checks that we can correct read interface statistics */ - public function test_read(): void - { + public function test_read(): void { # Create a interface statistics to populate a interface - $interface_stats = InterfaceStats::query(name: "wan"); + $interface_stats = InterfaceStats::query(name: 'wan'); $this->assert_is_true($interface_stats->exists()); $this->assert_is_not_empty($interface_stats->first()->name->value); $this->assert_is_not_empty($interface_stats->first()->descr->value); @@ -26,4 +24,4 @@ class APIModelsInterfaceStatsTestCase extends TestCase $this->assert_is_not_empty($interface_stats->first()->media->value); $this->assert_is_not_empty($interface_stats->first()->gateway->value); } -} \ No newline at end of file +}