Skip to content

Commit e2f8a55

Browse files
test(VirtualIP): add tests for unique-per-interface vhids #754
1 parent 8d73d08 commit e2f8a55

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,45 @@ class APIModelsVirtualIPTestCase extends TestCase {
242242
$carp_status->update();
243243
$carp_vip->delete(apply: true);
244244
}
245+
246+
public function test_carp_vhid_must_be_unique_per_interface(): void {
247+
# Create a virtual IP to test with
248+
$vip = new VirtualIP(
249+
mode: 'carp',
250+
interface: 'lan',
251+
subnet: '127.1.2.3',
252+
subnet_bits: 32,
253+
password: 'testpasswd',
254+
vhid: 5,
255+
);
256+
$vip->create();
257+
258+
# Ensure we can update the existing VIP with the same VHID without issue
259+
$this->assert_does_not_throw(
260+
callable: function () use ($vip) {
261+
$vip->validate_vhid(vhid: 5);
262+
},
263+
);
264+
265+
# Ensure we cannot create a new VIP with the same VHID on the same interface
266+
$this->assert_throws_response(
267+
response_id: 'VIRTUALIP_VHID_ALREADY_IN_USE',
268+
code: 409,
269+
callable: function () {
270+
$vip = new VirtualIP(mode: 'carp', interface: 'lan');
271+
$vip->validate_vhid(vhid: 5);
272+
},
273+
);
274+
275+
# Ensure we can create a new VIP with the same VHID on a different interface
276+
$this->assert_does_not_throw(
277+
callable: function () {
278+
$vip = new VirtualIP(mode: 'carp', interface: 'wan');
279+
$vip->validate_vhid(vhid: 5);
280+
},
281+
);
282+
283+
# Clean up the VIP we created
284+
$vip->delete();
285+
}
245286
}

0 commit comments

Comments
 (0)