|
4 | 4 | from django.urls import reverse |
5 | 5 | from swapper import load_model |
6 | 6 |
|
| 7 | +from openwisp_controller.config.tests.utils import TestWireguardVpnMixin |
7 | 8 | from openwisp_users.tests.utils import TestMultitenantAdminMixin |
8 | 9 |
|
9 | 10 | from .helpers import SubnetDivisionAdminTestMixin |
|
13 | 14 |
|
14 | 15 |
|
15 | 16 | class TestSubnetAdmin( |
16 | | - SubnetDivisionAdminTestMixin, TestMultitenantAdminMixin, TestCase |
| 17 | + SubnetDivisionAdminTestMixin, |
| 18 | + TestWireguardVpnMixin, |
| 19 | + TestMultitenantAdminMixin, |
| 20 | + TestCase, |
17 | 21 | ): |
18 | 22 | ipam_label = 'openwisp_ipam' |
19 | 23 | config_label = 'config' |
@@ -78,6 +82,50 @@ def test_device_filter_mutitenancy(self): |
78 | 82 | self.assertNotContains(response, self.config.device.name) |
79 | 83 | self.assertContains(response, config2.device.name) |
80 | 84 |
|
| 85 | + def test_vpn_filter(self): |
| 86 | + subnet_changelist = reverse(f'admin:{self.ipam_label}_subnet_changelist') |
| 87 | + org = self._get_org() |
| 88 | + subnet1 = self._create_subnet( |
| 89 | + name='Subnet 1', subnet='172.16.0.0/24', organization=org |
| 90 | + ) |
| 91 | + subnet2 = self._create_subnet( |
| 92 | + name='Subnet 2', subnet='172.16.1.0/24', organization=org |
| 93 | + ) |
| 94 | + vpn = self._create_wireguard_vpn(subnet=subnet1, organization=org) |
| 95 | + url = f'{subnet_changelist}?vpn={vpn.id}' |
| 96 | + response = self.client.get(url) |
| 97 | + self.assertContains( |
| 98 | + response, |
| 99 | + subnet1.name, |
| 100 | + ) |
| 101 | + self.assertNotContains(response, self.master_subnet.name) |
| 102 | + self.assertNotContains(response, subnet2.name) |
| 103 | + |
| 104 | + def test_vpn_filter_mutitenancy(self): |
| 105 | + subnet_changelist = reverse(f'admin:{self.ipam_label}_subnet_changelist') |
| 106 | + org1 = self._create_org(name='org1') |
| 107 | + org2 = self._create_org(name='org2') |
| 108 | + subnet1 = self._create_subnet( |
| 109 | + name='Subnet 1', subnet='172.16.0.0/24', organization=org1 |
| 110 | + ) |
| 111 | + subnet2 = self._create_subnet( |
| 112 | + name='Subnet 2', subnet='172.16.1.0/24', organization=org2 |
| 113 | + ) |
| 114 | + vpn1 = self._create_wireguard_vpn(subnet=subnet1, organization=org1) |
| 115 | + administrator = self._create_administrator([org2]) |
| 116 | + self.client.logout() |
| 117 | + self.client.force_login(administrator) |
| 118 | + url = f'{subnet_changelist}?vpn={vpn1.id}' |
| 119 | + response = self.client.get(url) |
| 120 | + self.assertNotContains( |
| 121 | + response, |
| 122 | + subnet1.name, |
| 123 | + ) |
| 124 | + self.assertNotContains( |
| 125 | + response, |
| 126 | + subnet2.name, |
| 127 | + ) |
| 128 | + |
81 | 129 | @patch('openwisp_controller.subnet_division.settings.HIDE_GENERATED_SUBNETS', True) |
82 | 130 | def test_hide_generated_subnets(self): |
83 | 131 | with self.subTest('Test SubnetAdmin'): |
|
0 commit comments