@@ -82,72 +82,29 @@ def _build_request(self, *args, **kwargs):
8282            return  request 
8383
8484    csrf_OFF  =  NinjaExtraAPI (urls_namespace = "csrf_OFF" )
85-     csrf_ON  =  NinjaExtraAPI (urls_namespace = "csrf_ON" , csrf = True )
8685
8786    @csrf_OFF .post ("/post" ) 
8887    async  def  post_off (request ):
8988        return  {"success" : True }
9089
91-     @csrf_ON .post ("/post" ) 
92-     async  def  post_on (request ):
93-         return  {"success" : True }
94- 
95-     @csrf_ON .post ("/post-async-sync-auth" , auth = SyncKeyCookie ()) 
96-     async  def  auth_with_sync_auth (request ):
97-         return  {"success" : True }
98- 
9990    TOKEN  =  "1bcdefghij2bcdefghij3bcdefghij4bcdefghij5bcdefghij6bcdefghijABCD" 
10091    COOKIES  =  {settings .CSRF_COOKIE_NAME : TOKEN }
10192
102-     @pytest .mark .asyncio  
103-     async  def  test_auth_with_sync_auth_fails ():
104-         async_client  =  TestAsyncClient (csrf_ON )
105-         res  =  await  async_client .post ("/post-async-sync-auth" )
106-         assert  res .status_code  ==  401 
107-         assert  res .json () ==  {"detail" : "Authentication credentials were not provided." }
108- 
109-     @pytest .mark .asyncio  
110-     async  def  test_auth_with_sync_auth_works ():
111-         async_client  =  TestAsyncClient (csrf_ON )
112-         res  =  await  async_client .post (
113-             "/post-async-sync-auth" , COOKIES = {"key" : "keycookiersecret" }
114-         )
115-         assert  res .status_code  ==  200 
116-         assert  res .json () ==  {"success" : True }
117- 
11893    @pytest .mark .asyncio  
11994    async  def  test_csrf_off ():
12095        async_client  =  TestAsyncCSRFClient (csrf_OFF )
12196        res  =  await  async_client .post ("/post" , COOKIES = COOKIES )
12297        assert  res .status_code  ==  200 
12398
124-     @pytest .mark .asyncio  
125-     async  def  test_csrf_on ():
126-         async_client  =  TestAsyncCSRFClient (csrf_ON )
127-         res  =  await  async_client .post ("/post" , COOKIES = COOKIES )
128-         assert  res .status_code  ==  403 
129- 
130-         # check with token in formdata 
131-         response  =  await  async_client .post (
132-             "/post" , {"csrfmiddlewaretoken" : TOKEN }, COOKIES = COOKIES 
133-         )
134-         assert  response .status_code  ==  200 
135- 
136-         # check with headers 
137-         response  =  await  async_client .post (
138-             "/post" , COOKIES = COOKIES , headers = {"X-CSRFTOKEN" : TOKEN }
139-         )
140-         assert  response .status_code  ==  200 
141- 
14299
143100if  not  django .VERSION  <  (3 , 1 ):
144-     api  =  NinjaExtraAPI (csrf = True ,  urls_namespace = "async_auth" )
101+     api  =  NinjaExtraAPI (urls_namespace = "async_auth" )
145102
146103    for  path , auth  in  [
147104        ("callable" , callable_auth ),
148105        ("apikeyquery" , KeyQuery ()),
149106        ("apikeyheader" , KeyHeader ()),
150-         ("apikeycookie" , KeyCookie ()),
107+         ("apikeycookie" , KeyCookie (csrf = True )),
151108        ("basic" , BasicAuth ()),
152109        ("bearer" , BearerAuth ()),
153110    ]:
0 commit comments