Commit 878be4aa by 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.

cf commit c3bde10e
1 parent c3bde10e
......@@ -33,6 +33,7 @@ import httplib
import urlparse
import base64
import urllib
import pkg_resources
from AccessControl.SecurityManagement import newSecurityManager
from Testing import ZopeTestCase
......@@ -640,7 +641,12 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional):
}
)
response = connection.getresponse()
self.assertEqual(response.status, 401)
if pkg_resources.get_distribution("Products.CMFCore").version < "2.3":
self.assertEqual(response.status, 401)
else:
# BBB: no longer required after we drop Products.CMFDefault
self.assertEqual(response.status, 302)
self.assertIn("/login_form", response.getheader('location'))
self.assertEqual(response.getheader('WWW-Authenticate'), None)
def test_standardErrorMessageShouldNotRaiseUnauthorizeOnUnauthorizeDocument(self):
......@@ -667,7 +673,12 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional):
document_1.standard_error_message(error_type="MyErrorType", error_message="my error message.")
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:
# BBB: no longer required after we drop Products.CMFDefault
self.assertEqual(response.getStatus(), 302)
self.assertIn("/login_form", response.headers['location'])
self.assertNotIn("Also, the following error occurred", str(response))
def testCategoryExport(self):
......
......@@ -31,6 +31,7 @@
"""
import itertools
import pkg_resources
import transaction
import unittest
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
......@@ -1067,7 +1068,12 @@ class TestLocalRoleManagement(RoleManagementTestCase):
self.assertEqual(response.getStatus(), 200)
response = self.publish('/%s/first_last/getFirstName' % person_module_path,
basic='guest:guest')
self.assertEqual(response.getStatus(), 401)
if pkg_resources.get_distribution("Products.CMFCore").version < "2.3":
self.assertEqual(response.getStatus(), 401)
else:
# BBB: no longer required after we drop Products.CMFDefault
self.assertEqual(response.getStatus(), 302)
self.assertIn("/login_form", response.headers['location'])
# Organisation does not have explicitly declared getTitle method in
# the class definition.
......@@ -1078,7 +1084,11 @@ class TestLocalRoleManagement(RoleManagementTestCase):
self.tic()
response = self.publish('/%s/my_company/getTitle' % self.getOrganisationModule().absolute_url(relative=1),
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):
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!