@@ -921,6 +921,40 @@ def test_submission_data_collector(self):
921921 f'http://testserver/collector/{ dc .token } /submission' ,
922922 )
923923
924+ def test_digest_auth_allows_submission_on_username_endpoint (self ):
925+ """
926+ Test that Digest authentication works correctly on the
927+ `/<username>/submission` endpoint when the xform requires auth
928+ """
929+ username = self .user .username
930+
931+ # Ensure that POST to `/<username>/submission` fails without auth
932+ request = self .factory .post (f'/{ username } /submission' )
933+ response = self .view (request , username = username )
934+ self .assertEqual (response .status_code , status .HTTP_401_UNAUTHORIZED )
935+
936+ # Ensure that POST to `/<username>/submission` with Digest auth
937+ s = self .surveys [0 ]
938+ submission_path = os .path .join (
939+ self .main_directory , 'fixtures' ,
940+ 'transportation' , 'instances' , s , s + '.xml'
941+ )
942+ with open (submission_path ) as sf :
943+ request = self .factory .post (f'/{ username } /submission' , data = {})
944+ response = self .view (request , username = username )
945+ self .assertEqual (response .status_code , status .HTTP_401_UNAUTHORIZED )
946+
947+ data = {'xml_submission_file' : sf }
948+
949+ request = self .factory .post (f'/{ username } /submission' , data )
950+ auth = DigestAuth ('bob' , 'bobbob' )
951+ request .META .update (auth (request .META , response ))
952+
953+ response = self .view (request , username = username )
954+ self .assertContains (
955+ response , 'Successful submission' , status_code = status .HTTP_201_CREATED
956+ )
957+
924958
925959class ConcurrentSubmissionTestCase (RequestMixin , LiveServerTestCase ):
926960 """
0 commit comments