@@ -16,8 +16,10 @@ use RESTAPI\Responses\ServerError;
1616class APIModelsFirewallRuleTestCase extends TestCase {
1717 /**
1818 * Reads the active ruleset directly from pfctl.
19+ * @param string|null $needle If provided, ensures this string is found in the pfctl output before returning.
20+ * @return Command The Command object containing the pfctl output.
1921 */
20- public function read_pfctl_rules (): Command {
22+ public function read_pfctl_rules (? string $ needle = null ): Command {
2123 # Keywords that indicate pf is not ready yet
2224 $ not_ready_keywords = ['pfctl: DIOCGETRULE: Device busy ' , 'pfctl: DIOCGETRULENV: Device busy ' ];
2325
@@ -28,9 +30,9 @@ class APIModelsFirewallRuleTestCase extends TestCase {
2830 $ cmd = new Command ('/sbin/pfctl -sr ' );
2931 $ ready = true ;
3032
31- foreach ($ not_ready_keywords as $ keyword ) {
33+ foreach ($ not_ready_keywords as $ kw ) {
3234 # pf is not ready if any of the keywords are found in the output
33- if (str_contains ($ cmd ->output , $ keyword )) {
35+ if (str_contains ($ cmd ->output , $ kw ) or ( $ needle and ! str_contains ( $ cmd -> output , $ needle ) )) {
3436 $ ready = false ;
3537 $ attempt ++;
3638 sleep (1 );
@@ -833,7 +835,7 @@ class APIModelsFirewallRuleTestCase extends TestCase {
833835 $ rule ->create (apply: true );
834836
835837 # Ensure the dnpipe is correctly represented
836- $ pfctl = $ this ->read_pfctl_rules ();
838+ $ pfctl = $ this ->read_pfctl_rules (needle: $ rule -> tracker -> value );
837839 $ this ->assert_str_contains (
838840 $ pfctl ->output ,
839841 "ridentifier {$ rule ->tracker ->value } dnpipe {$ limiter ->number ->value }" ,
0 commit comments