Commit 2d75cecc authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

tests: support CMF 2.3's redirections when Unauthorized

CMF 2.3 is "stricter" about Unauthorized exceptions, and will always
redirect to the login page.
parent 841a62b1
...@@ -33,6 +33,7 @@ import httplib ...@@ -33,6 +33,7 @@ import httplib
import urlparse import urlparse
import base64 import base64
import urllib import urllib
import pkg_resources
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Testing import ZopeTestCase from Testing import ZopeTestCase
...@@ -640,7 +641,11 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -640,7 +641,11 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional):
} }
) )
response = connection.getresponse() response = connection.getresponse()
self.assertEqual(response.status, 401) if pkg_resources.get_distribution("Products.CMFCore").version < "2.3":
self.assertEqual(response.status, 401)
else:
self.assertEqual(response.status, 302)
self.assertIn("/login_form", response.getheader('location'))
self.assertEqual(response.getheader('WWW-Authenticate'), None) self.assertEqual(response.getheader('WWW-Authenticate'), None)
def test_standardErrorMessageShouldNotRaiseUnauthorizeOnUnauthorizeDocument(self): def test_standardErrorMessageShouldNotRaiseUnauthorizeOnUnauthorizeDocument(self):
...@@ -667,7 +672,11 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -667,7 +672,11 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional):
document_1.standard_error_message(error_type="MyErrorType", error_message="my error message.") document_1.standard_error_message(error_type="MyErrorType", error_message="my error message.")
response = self.publish(document_1.getPath(), self.auth) response = self.publish(document_1.getPath(), self.auth)
self.assertEqual(response.getStatus(), 401) if pkg_resources.get_distribution("Products.CMFCore").version < "2.3":
self.assertEqual(response.getStatus(), 401)
else:
self.assertEqual(response.getStatus(), 302)
self.assertIn("/login_form", response.headers['location'])
self.assertNotIn("Also, the following error occurred", str(response)) self.assertNotIn("Also, the following error occurred", str(response))
def testCategoryExport(self): def testCategoryExport(self):
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
""" """
import itertools import itertools
import pkg_resources
import transaction import transaction
import unittest import unittest
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
...@@ -1067,7 +1068,11 @@ class TestLocalRoleManagement(RoleManagementTestCase): ...@@ -1067,7 +1068,11 @@ class TestLocalRoleManagement(RoleManagementTestCase):
self.assertEqual(response.getStatus(), 200) self.assertEqual(response.getStatus(), 200)
response = self.publish('/%s/first_last/getFirstName' % person_module_path, response = self.publish('/%s/first_last/getFirstName' % person_module_path,
basic='guest:guest') basic='guest:guest')
self.assertEqual(response.getStatus(), 401) if pkg_resources.get_distribution("Products.CMFCore").version < "2.3":
self.assertEqual(response.getStatus(), 401)
else:
self.assertEqual(response.getStatus(), 302)
self.assertIn("/login_form", response.headers['location'])
# Organisation does not have explicitly declared getTitle method in # Organisation does not have explicitly declared getTitle method in
# the class definition. # the class definition.
...@@ -1078,7 +1083,11 @@ class TestLocalRoleManagement(RoleManagementTestCase): ...@@ -1078,7 +1083,11 @@ class TestLocalRoleManagement(RoleManagementTestCase):
self.tic() self.tic()
response = self.publish('/%s/my_company/getTitle' % self.getOrganisationModule().absolute_url(relative=1), response = self.publish('/%s/my_company/getTitle' % self.getOrganisationModule().absolute_url(relative=1),
basic='guest:guest') basic='guest:guest')
self.assertEqual(response.getStatus(), 401) if pkg_resources.get_distribution("Products.CMFCore").version < "2.3":
self.assertEqual(response.getStatus(), 401)
else:
self.assertEqual(response.getStatus(), 302)
self.assertIn("/login_form", response.headers['location'])
class TestKeyAuthentication(RoleManagementTestCase): class TestKeyAuthentication(RoleManagementTestCase):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment