#NEWLINE# def test_login_csrf_rotate( self , password = 'password' ) : #NEWLINE# #INDENT# '\n        Makes sure that a login rotates the currently-used CSRF token.\n        ' #NEWLINE# req = HttpRequest ( ) #NEWLINE# CsrfViewMiddleware ( ) . process_view ( req , login_view , ( ) , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# req . META [ 'CSRF_COOKIE_USED' ] = True #NEWLINE# resp = login_view ( req ) #NEWLINE# resp2 = CsrfViewMiddleware ( ) . process_response ( req , csrf_cookie ) #NEWLINE# csrf_cookie = resp2 . cookies . get ( settings . CSRF_COOKIE_NAME , None ) #NEWLINE# token1 = csrf_cookie . coded_value #NEWLINE# req = HttpRequest ( ) #NEWLINE# req . COOKIES [ settings . CSRF_COOKIE_NAME ] = token1 #NEWLINE# req . method = 'POST' #NEWLINE# req . POST = { #NEWLINE# #INDENT# 'username' : 'testclient' , #NEWLINE# 'password' : password , #NEWLINE# 'csrfmiddlewaretoken' : token1 , #NEWLINE# #UNINDENT# } #NEWLINE# req . REQUEST = req . POST #NEWLINE# SessionMiddleware ( ) . process_request ( req ) #NEWLINE# CsrfViewMiddleware ( ) . process_view ( req , login_view , ( ) , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# req . META [ 'SERVER_NAME' ] = 'testserver' #NEWLINE# req . META [ 'SERVER_PORT' ] = 80 #NEWLINE# resp = login_view ( req ) #NEWLINE# resp2 = CsrfViewMiddleware ( ) . process_response ( req , resp ) #NEWLINE# csrf_cookie = resp2 . cookies . get ( settings . CSRF_COOKIE_NAME , None ) #NEWLINE# token2 = csrf_cookie . coded_value #NEWLINE# self . assertNotEqual ( token1 , token2 )