Skip to content

Commit

Permalink
Clean number of hours in error log search form
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Feb 20, 2025
1 parent 041d2e1 commit 70d3d20
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/3246.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Check hours in radius error log search
11 changes: 11 additions & 0 deletions python/nav/web/radius/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ def __init__(self, *args, **kwargs):
],
)

def clean_time(self):
time_type, time = self.cleaned_data["time"]
if time_type == "hours":
try:
datetime.now() - timedelta(hours=int(time))
except OverflowError:
raise forms.ValidationError(
"They did not have computers %s hours ago" % time
)
return time


class AccountLogSearchForm(forms.Form):
"""Form for searching in the radius account log"""
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/web/radius_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ def test_top_talkers_should_not_crash_on_big_days(db, client):

assert response.status_code == 200
assert 'They did not have computers' in smart_str(response.content)


def test_error_log_search_should_not_crash_on_big_hours(db, client, admin_username):
url = reverse('radius-log_search')
url = (
url
+ f'?query_0=username&query_1={admin_username}&log_entry_type=&time_0=hours&time_1=123123123123123&send=Search'
)
response = client.get(url)

assert response.status_code == 200
assert 'They did not have computers' in smart_str(response.content)

0 comments on commit 70d3d20

Please sign in to comment.