-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Added mac address authentication for roaming users #490
Closes #490
- Loading branch information
Showing
9 changed files
with
230 additions
and
52 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
openwisp_radius/migrations/0036_organizationradiussettings_mac_addr_roaming_enabled.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Generated by Django 3.2.21 on 2023-10-11 12:06 | ||
|
||
from django.db import migrations | ||
|
||
import openwisp_utils.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('openwisp_radius', '0035_organizationradiussettings_sms_cooldown'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='organizationradiussettings', | ||
name='mac_addr_roaming_enabled', | ||
field=openwisp_utils.fields.FallbackBooleanChoiceField( | ||
blank=True, | ||
default=None, | ||
fallback=False, | ||
help_text='Whether the MAC address roaming should be enabled or not.', | ||
null=True, | ||
verbose_name='MAC address roaming enabled', | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1466,6 +1466,130 @@ def test_user_accounting_list_empty_diff_organization(self): | |
self.assertEqual(len(response.json()), 0) | ||
|
||
|
||
class TestMacAddressRoaming(AcctMixin, ApiTokenMixin, BaseTestCase): | ||
_test_email = '[email protected]' | ||
|
||
def setUp(self): | ||
cache.clear() | ||
logging.disable(logging.WARNING) | ||
super().setUp() | ||
|
||
def test_mac_addr_roaming_authorize_view(self): | ||
acct_post_data = self.acct_post_data | ||
acct_post_data['username'] = 'tester' | ||
acct_post_data['calling_station_id'] = '00-11-22-33-44-55' | ||
self._get_org_user() | ||
self._login_and_obtain_auth_token() | ||
|
||
with self.subTest('Test user does not have an open session'): | ||
response = self._authorize_user( | ||
username=acct_post_data['calling_station_id'], | ||
password=acct_post_data['calling_station_id'], | ||
) | ||
self.assertEqual(response.status_code, 403) | ||
|
||
self._create_radius_accounting(**acct_post_data) | ||
|
||
with self.subTest('Test mac address roaming is disabled'): | ||
response = self._authorize_user( | ||
username=acct_post_data['calling_station_id'], | ||
password=acct_post_data['calling_station_id'], | ||
) | ||
self.assertEqual(response.status_code, 403) | ||
|
||
OrganizationRadiusSettings.objects.update(mac_addr_roaming_enabled=True) | ||
with self.subTest( | ||
'Test user has open session and mac address roaming is enabled' | ||
): | ||
response = self._authorize_user( | ||
username=acct_post_data['calling_station_id'], | ||
password=acct_post_data['calling_station_id'], | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual( | ||
response.data, | ||
{ | ||
'control:Auth-Type': 'Accept', | ||
'Session-Timeout': 10539, | ||
'ChilliSpot-Max-Total-Octets': 1487813647, | ||
}, | ||
) | ||
OrganizationRadiusSettings.objects.update(mac_addr_roaming_enabled=False) | ||
|
||
def test_mac_addr_roaming_accounting_view(self): | ||
acct_post_data = self.acct_post_data | ||
acct_post_data['username'] = 'tester' | ||
acct_post_data['calling_station_id'] = '00-11-22-33-44-55' | ||
payload = acct_post_data.copy() | ||
payload.update( | ||
{ | ||
'unique_id': '119', | ||
'username': payload['calling_station_id'], | ||
'status_type': 'Start', | ||
'nas_ip_address': '172.16.64.92', | ||
'called_station_id': '66:55:44:33:22:11:hostname', | ||
} | ||
) | ||
|
||
self._get_org_user() | ||
self._login_and_obtain_auth_token() | ||
|
||
with self.subTest('Test user does not have an open session'): | ||
response = response = self.client.post( | ||
self._acct_url, | ||
data=json.dumps(payload), | ||
content_type='application/json', | ||
) | ||
self.assertEqual(response.status_code, 403) | ||
|
||
self._create_radius_accounting(update_time=now(), **acct_post_data) | ||
|
||
with self.subTest('Test mac address roaming is disabled'): | ||
response = response = self.client.post( | ||
self._acct_url, | ||
data=json.dumps(payload), | ||
content_type='application/json', | ||
) | ||
self.assertEqual(response.status_code, 403) | ||
|
||
OrganizationRadiusSettings.objects.update(mac_addr_roaming_enabled=True) | ||
with self.subTest( | ||
'Test user has open session and mac address roaming is enabled' | ||
): | ||
response = response = self.client.post( | ||
self._acct_url, | ||
data=json.dumps(payload), | ||
content_type='application/json', | ||
) | ||
self.assertEqual(response.status_code, 201) | ||
self.assertEqual( | ||
response.data, | ||
None, | ||
) | ||
self.assertEqual( | ||
RadiusAccounting.objects.filter(username='tester').count(), 2 | ||
) | ||
self.assertEqual( | ||
RadiusAccounting.objects.filter( | ||
username='tester', | ||
stop_time=None, | ||
nas_ip_address=payload['nas_ip_address'], | ||
called_station_id=payload['called_station_id'], | ||
).count(), | ||
1, | ||
) | ||
self.assertEqual( | ||
RadiusAccounting.objects.filter( | ||
username='tester', | ||
stop_time__isnull=False, | ||
nas_ip_address=acct_post_data['nas_ip_address'], | ||
called_station_id=acct_post_data['called_station_id'], | ||
).count(), | ||
1, | ||
) | ||
OrganizationRadiusSettings.objects.update(mac_addr_roaming_enabled=False) | ||
|
||
|
||
class TestApiReject(ApiTokenMixin, BaseTestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters