Skip to content

Commit

Permalink
fixup!: oops sub tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rgraber committed Sep 19, 2024
1 parent 86128a5 commit 8483c46
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions kobo/apps/audit_log/tests/test_one_time_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,40 @@ def side_effect(request):
self.assertTrue(log_exists)
self.assertEqual(AuditLog.objects.count(), 1)

def test_digest_auth_for_submission(self):
@data(
'kpi.authentication.DRFTokenAuthentication.authenticate',
'kpi.authentication.DRFBasicAuthentication.authenticate',
'kpi.authentication.OPOAuth2Authentication.authenticate',
'kobo.apps.openrosa.libs.authentication.BasicAuthentication.authenticate',
)
def test_any_auth_for_submissions(self, authetication_method):
"""
Test any normal one-time authenticated submission results in a submission access log
"""

with patch(
authetication_method,
return_value=(TestOneTimeAuthentication.user, 'something'),
):
# assume the submission works, we don't actually care
with patch(
'kobo.apps.openrosa.apps.api.viewsets.xform_submission_api.XFormSubmissionApi.create',
return_value=HttpResponse(status=200),
):
# try both v1 and v2
self.client.post(reverse('submissions'))
self.client.post(reverse('submissions-list'))
log_exists = AuditLog.objects.filter(
user_uid=TestOneTimeAuthentication.user.extra_details.uid,
action=AuditAction.AUTH,
metadata__auth_type='submission',
).exists()
self.assertTrue(log_exists)
self.assertEqual(AuditLog.objects.count(), 2)

def test_digest_auth_for_submissions(self):
"""
Test digest authentications for submissions result in an audit log being created with the 'Submission' type
Test digest-authenticated submissions result in a submission access log
"""

def side_effect(request):
Expand All @@ -146,14 +177,17 @@ def side_effect(request):
'kobo.apps.openrosa.apps.api.viewsets.xform_submission_api.XFormSubmissionApi.create',
return_value=HttpResponse(status=200),
):
# check v1 and v2
self.client.post(reverse('submissions'), **header)
self.client.post(reverse('submissions-list'), **header)

log_exists = AuditLog.objects.filter(
user_uid=TestOneTimeAuthentication.user.extra_details.uid,
action=AuditAction.AUTH,
metadata__auth_type='submission',
).exists()
self.assertTrue(log_exists)
self.assertEqual(AuditLog.objects.count(), 1)
self.assertEqual(AuditLog.objects.count(), 2)

def test_authorized_application_auth_creates_log(self):
app: AuthorizedApplication = AuthorizedApplication(name='Auth app')
Expand Down

0 comments on commit 8483c46

Please sign in to comment.