Commit ac27abb3 by Jérome Perrin

access_token: simplify test for dumb extraction plugin

This test does not need to create an actual user as it just check
plugin extract login & password from request.
This test does not need to install the plugin in PAS, the actual check
instanciate another ERP5DumbHTTPExtractionPlugin.
1 parent 9646f606
......@@ -42,14 +42,12 @@ class AccessTokenTestCase(ERP5TypeTestCase):
return ('erp5_base',
def _createPerson(self, new_id, password=None):
def _createPerson(self, new_id):
"""Creates a person in person module, and returns the object, after
indexing is done. """
person_module = self.getPersonModule()
person = person_module.newContent(portal_type='Person',
reference='TESTP-' + new_id)
if password:
person.newContent(portal_type='ERP5 Login', reference=new_id).validate()
......@@ -388,20 +386,6 @@ class TestERP5AccessTokenAlarm(AccessTokenTestCase):
class TestERP5DumbHTTPExtractionPlugin(AccessTokenTestCase):
test_id = 'test_erp5_dumb_http_extraction'
def generateNewId(self):
return str(self.portal.portal_ids.generateNewId(
def afterSetUp(self):
This is ran before anything, used to set the environment
self.new_id = self.generateNewId()
def do_fake_request(self, request_method, headers=None):
if headers is None:
headers = {}
......@@ -423,26 +407,10 @@ class TestERP5DumbHTTPExtractionPlugin(AccessTokenTestCase):
return HTTPRequest(StringIO.StringIO(), env, HTTPResponse())
def _setupDumbHTTPExtraction(self):
pas = self.portal.acl_users
access_extraction_list = [q for q in pas.objectValues() \
if q.meta_type == 'ERP5 Dumb HTTP Extraction Plugin']
if len(access_extraction_list) == 0:
dispacher = pas.manage_addProduct['ERP5Security']
getattr(pas, self.test_id).manage_activateInterfaces(
elif len(access_extraction_list) == 1:
self.test_id = access_extraction_list[0].getId()
elif len(access_extraction_list) > 1:
raise ValueError
def test_working_authentication(self):
self._createPerson(self.new_id, "test")
request = self.do_fake_request("GET", {"HTTP_AUTHORIZATION": "Basic " + base64.b64encode("%s:test" % self.new_id)})
request = self.do_fake_request("GET", {"HTTP_AUTHORIZATION": "Basic " + base64.b64encode("login:password")})
ret = ERP5DumbHTTPExtractionPlugin("default_extraction").extractCredentials(request)
self.assertEqual(ret, {'login': self.new_id, 'password': 'test', 'remote_host': '', 'remote_address': ' '})
self.assertEqual(ret, {'login': 'login', 'password': 'password', 'remote_host': '', 'remote_address': ' '})
class TestERP5AccessTokenUpgraderEnablePlugin(AccessTokenTestCase):
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!