Skip to content

Commit e392732

Browse files
test(VirtualIP): ensure nested vips are correctly registered
1 parent b61ddf4 commit e392732

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,47 @@ class APIModelsVirtualIPTestCase extends TestCase {
283283
# Clean up the VIP we created
284284
$vip->delete();
285285
}
286+
287+
/**
288+
* Ensures we can create an IP alias virtual IP nested under a parent CARP virtual IP.
289+
*/
290+
public function test_nested_vip_under_carp_vip(): void {
291+
# Create a CARP virtual IP to test with
292+
$carp_vip = new VirtualIP(
293+
interface: "lan",
294+
mode: "carp",
295+
subnet: "127.0.0.105",
296+
subnet_bits: 32,
297+
vhid: 105,
298+
password: "test",
299+
async: false
300+
);
301+
$carp_vip->create();
302+
303+
# Create a new IP alias virtual IP that uses the CARP virtual IP as its interface
304+
$child_vip = new VirtualIP(
305+
interface: "_vip{$carp_vip->uniqid->value}",
306+
mode: "ipalias",
307+
subnet: "127.0.0.106",
308+
subnet_bits: 32,
309+
async: false
310+
);
311+
$child_vip->create(apply: true);
312+
313+
# Ensure the parent interface shows both virtual IPs sharing the same vhid in ifconfig
314+
$iface = $carp_vip->interface->get_related_model()->if->value;
315+
$ifconfig = new Command("/sbin/ifconfig $iface");
316+
$this->assert_str_contains(
317+
$ifconfig->output,
318+
"inet 127.0.0.105 netmask 0xffffffff broadcast 127.0.0.105 vhid 105"
319+
);
320+
$this->assert_str_contains(
321+
$ifconfig->output,
322+
"inet 127.0.0.106 netmask 0xffffffff broadcast 127.0.0.106 vhid 105"
323+
);
324+
325+
# Clean up the VIPs we created
326+
$child_vip->delete();
327+
$carp_vip->delete(apply: true);
328+
}
286329
}

0 commit comments

Comments
 (0)