Skip to content

Commit e31b95a

Browse files
pandafynemesifier
authored andcommitted
[chores/fix] Allow blank for Calling and Called Station ID in AuthorizeView #649
Related to #649
1 parent fc948b9 commit e31b95a

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

openwisp_radius/api/serializers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ class AuthorizeSerializer(serializers.Serializer):
112112
)
113113
password = serializers.CharField(style={"input_type": "password"}, write_only=True)
114114
called_station_id = serializers.CharField(
115-
max_length=253, required=False, allow_blank=False, write_only=True
115+
max_length=253, required=False, allow_blank=True, write_only=True
116116
)
117117
calling_station_id = serializers.CharField(
118-
max_length=253, required=False, allow_blank=False, write_only=True
118+
max_length=253, required=False, allow_blank=True, write_only=True
119119
)
120120

121121

openwisp_radius/tests/test_api/test_freeradius_api.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,6 +1814,55 @@ def test_authorize_without_user_auth(self):
18141814
),
18151815
)
18161816

1817+
def test_authorize_optional_fields(self):
1818+
username = "tester"
1819+
password = "tester"
1820+
self._create_user(
1821+
username=username,
1822+
1823+
password="password",
1824+
)
1825+
authorize_path = reverse("radius:authorize")
1826+
payload = {"username": username, "password": password}
1827+
with self.subTest("Test without called and calling station id"):
1828+
response = self.client.post(
1829+
authorize_path,
1830+
payload,
1831+
HTTP_AUTHORIZATION=self.auth_header,
1832+
content_type="application/json",
1833+
)
1834+
self.assertEqual(response.status_code, 200)
1835+
1836+
with self.subTest("Test with empty called and calling station id"):
1837+
payload.update(
1838+
{
1839+
"called_station_id": "",
1840+
"calling_station_id": "",
1841+
}
1842+
)
1843+
response = self.client.post(
1844+
authorize_path,
1845+
payload,
1846+
HTTP_AUTHORIZATION=self.auth_header,
1847+
content_type="application/json",
1848+
)
1849+
self.assertEqual(response.status_code, 200)
1850+
1851+
with self.subTest("Test with called and calling station id"):
1852+
payload.update(
1853+
{
1854+
"called_station_id": "00-11-22-33-44-55",
1855+
"calling_station_id": "66-55-44-33-22-11",
1856+
}
1857+
)
1858+
response = self.client.post(
1859+
authorize_path,
1860+
payload,
1861+
HTTP_AUTHORIZATION=self.auth_header,
1862+
content_type="application/json",
1863+
)
1864+
self.assertEqual(response.status_code, 200)
1865+
18171866
def test_user_auth_token_disposed_after_auth(self):
18181867
self._get_org_user()
18191868
rad_token = self._login_and_obtain_auth_token()

0 commit comments

Comments
 (0)