Testing csrf token in django

I want to check if csrf tokens work on my django site. The problem is that csrf_token returns the value of the token, not the custom value of 'csrftoken'. Is there a way to set the csrf value for testing? This is the code I'm working with:

token = 'csrftoken'
client = Client(enforce_csrf_checks=True)
client.login(username='user', password='pass')
client.get("/my/web/page/")
csrf_token = client.cookies[token].value
assetEqual(token, csrf_token)
+4
source share
1 answer

Is there any specific reason you are testing something that "Django's own tests already cover" in more detail?

Or, in another way, is there anything specific / non-standard that you do with the CSRF token, which means you need to test it?

, , Django

+3

Source: https://habr.com/ru/post/1546589/


All Articles