def testVerifyCSRFToken_Truncated(self, mock_time): mock_time.return_value = self.base_clock token = self.valid_token[:4] with self.assertRaises(struct.error): csrfutil.verify_csrf_token(token, self.test_user) mock_time.reset_mock() token = 'a' self.assertFalse(csrfutil.verify_csrf_token(token, self.test_user)) mock_time.assert_not_called()
def testVerifyCSRFToken_TamperedTime(self, mock_time): mock_time.return_value = self.base_clock token = self.valid_token.replace('dMv', 'xxx') self.assertFalse(csrfutil.verify_csrf_token(token, self.test_user)) mock_time.assert_called_once_with()
def testVerifyCSRFToken_Expired(self, mock_time): mock_time.return_value = self.base_clock + (60 * 60 * 60) self.assertFalse( csrfutil.verify_csrf_token(self.valid_token, self.test_user)) mock_time.assert_called_once_with()
def testVerifyCSRFToken_Valid(self, mock_time): mock_time.return_value = self.base_clock self.assertTrue( csrfutil.verify_csrf_token(self.valid_token, self.test_user)) mock_time.assert_called_once_with()
def testVerifyCSRFToken_Expired(self, mock_time): mock_time.return_value = self.base_clock + (60 * 60 * 60) self.assertFalse(csrfutil.verify_csrf_token( self.valid_token, self.test_user)) mock_time.assert_called_once_with()
def testVerifyCSRFToken_Valid(self, mock_time): mock_time.return_value = self.base_clock self.assertTrue(csrfutil.verify_csrf_token( self.valid_token, self.test_user)) mock_time.assert_called_once_with()