Skip to content

Commit cca3470

Browse files
fix anon appoint
1 parent 324f027 commit cca3470

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

Appointment/tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,20 @@ def test_no_underground_permission_creates_nothing(self):
220220
self.assertEqual(response.status_code, 302)
221221
self.assertEqual(Appoint.objects.count(), 0)
222222

223+
def test_invalid_account_creates_nothing(self):
224+
for invalid_type in (User.Type.SPECIAL, User.Type.UNAUTHORIZED):
225+
with self.subTest(invalid_type=invalid_type):
226+
self.attacker_user.utype = invalid_type
227+
self.attacker_user.save(update_fields=['utype'])
228+
self.client.force_login(self.attacker_user)
229+
response = self._post(
230+
Sid=self.victim.get_id(), Sname=self.victim.name,
231+
)
232+
self.assertEqual(response.status_code, 302)
233+
self.assertEqual(Appoint.objects.count(), 0)
234+
for side_effect_mock in self.mocks:
235+
side_effect_mock.assert_not_called()
236+
223237
def test_csrf_rejected_without_or_with_bad_token(self):
224238
csrf_client = Client(enforce_csrf_checks=True)
225239
csrf_client.force_login(self.attacker_user)

Appointment/utils/identity.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ def _wrapped_view(request: UserRequest, *args: P.args, **kwargs: P.kwargs):
166166
context = {}
167167

168168
if not request.user.is_valid():
169-
_allow_create = False
169+
wrong('您的账号无权访问地下室功能。', context)
170+
return redirect(message_url(context, reverse('welcome')))
170171

171172
cur_part = get_participant(request.user)
172173

0 commit comments

Comments
 (0)