Commit daf42ca5 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 88c1dade
......@@ -33,6 +33,7 @@ import httplib
import urlparse
import base64
import urllib
import pkg_resources
from AccessControl.SecurityManagement import newSecurityManager
from Testing import ZopeTestCase
......@@ -641,7 +642,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):
......@@ -668,7 +674,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):
......
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