Commit d1e7e284 authored by Jérome Perrin's avatar Jérome Perrin

syncml: only use files from the subscriptions and publications

This comes with a small breaking change that when using file:// URLs,
they need to be well formed ( file:// + path and not file:/ + path )
parent d3706099
Pipeline #36532 passed with stage
in 0 seconds
...@@ -27,10 +27,11 @@ ...@@ -27,10 +27,11 @@
# #
############################################################################## ##############################################################################
from six.moves.urllib.parse import urlparse
import itertools
import os import os
from base64 import b16encode from base64 import b16encode
from unittest import expectedFailure from unittest import expectedFailure
import unittest
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
...@@ -99,9 +100,9 @@ class TestERP5DocumentSyncMLMixin(TestERP5SyncMLMixin): ...@@ -99,9 +100,9 @@ class TestERP5DocumentSyncMLMixin(TestERP5SyncMLMixin):
xml_mapping = 'asXML' xml_mapping = 'asXML'
pub_conduit = 'ERP5DocumentConduit' pub_conduit = 'ERP5DocumentConduit'
sub_conduit1 = 'ERP5DocumentConduit' sub_conduit1 = 'ERP5DocumentConduit'
publication_url = 'file:/%s/sync_server' % tests_home publication_url = 'file://%s/sync_server' % tests_home
subscription_url = {'two_way': 'file:/%s/sync_client1' % tests_home, subscription_url = {'two_way': 'file://%s/sync_client1' % tests_home,
'from_server': 'file:/%s/sync_client_from_server' % tests_home} 'from_server': 'file://%s/sync_client_from_server' % tests_home}
#for this tests #for this tests
nb_message_first_synchronization = 6 nb_message_first_synchronization = 6
nb_message_multi_first_synchronization = 12 nb_message_multi_first_synchronization = 12
...@@ -142,14 +143,10 @@ class TestERP5DocumentSyncMLMixin(TestERP5SyncMLMixin): ...@@ -142,14 +143,10 @@ class TestERP5DocumentSyncMLMixin(TestERP5SyncMLMixin):
def clearFiles(self): def clearFiles(self):
# reset files, because we do sync by files # reset files, because we do sync by files
for filename in self.subscription_url.values(): for filename in itertools.chain(
file_ = open(filename[len('file:/'):], 'w') self.subscription_url.values(), [self.publication_url]):
file_.write('') with open(urlparse(filename).path, 'w') as f:
file_.close() f.write('')
file_ = open(self.publication_url[len('file:/'):], 'w')
file_.write('')
file_.close()
def setSystemPreferences(self): def setSystemPreferences(self):
default_pref = self.portal.portal_preferences.default_site_preference default_pref = self.portal.portal_preferences.default_site_preference
...@@ -858,7 +855,3 @@ class TestERP5DocumentSyncML(TestERP5DocumentSyncMLMixin): ...@@ -858,7 +855,3 @@ class TestERP5DocumentSyncML(TestERP5DocumentSyncMLMixin):
self.assertXMLViewIsEqual(self.sub_id1, document_s, document_c, force=True, self.assertXMLViewIsEqual(self.sub_id1, document_s, document_c, force=True,
ignore_processing_status_workflow=True) ignore_processing_status_workflow=True)
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestERP5DocumentSyncML))
return suite
\ No newline at end of file
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
# #
############################################################################## ##############################################################################
import unittest
from base64 import b64encode, b64decode, b16encode from base64 import b64encode, b64decode, b16encode
from lxml import etree from lxml import etree
from unittest import expectedFailure from unittest import expectedFailure
...@@ -44,7 +43,7 @@ from erp5.component.module.SyncMLConstant import MAX_LEN ...@@ -44,7 +43,7 @@ from erp5.component.module.SyncMLConstant import MAX_LEN
from erp5.component.document import SyncMLSubscription from erp5.component.document import SyncMLSubscription
from erp5.component.module.testERP5SyncMLMixin import TestERP5SyncMLMixin \ from erp5.component.module.testERP5SyncMLMixin import TestERP5SyncMLMixin \
as TestMixin as TestMixin
from six.moves import range from zExceptions import Forbidden
class TestERP5SyncMLMixin(TestMixin): class TestERP5SyncMLMixin(TestMixin):
...@@ -103,9 +102,9 @@ class TestERP5SyncMLMixin(TestMixin): ...@@ -103,9 +102,9 @@ class TestERP5SyncMLMixin(TestMixin):
self._subscription_url1 = tests_home + '/sync_client1' self._subscription_url1 = tests_home + '/sync_client1'
self._subscription_url2 = tests_home + '/sync_client2' self._subscription_url2 = tests_home + '/sync_client2'
self._publication_url = tests_home + '/sync_server' self._publication_url = tests_home + '/sync_server'
self.subscription_url1 = 'file:/' + self._subscription_url1 self.subscription_url1 = 'file://' + self._subscription_url1
self.subscription_url2 = 'file:/' + self._subscription_url2 self.subscription_url2 = 'file://' + self._subscription_url2
self.publication_url = 'file:/' + self._publication_url self.publication_url = 'file://' + self._publication_url
def beforeTearDown(self): def beforeTearDown(self):
"""Clean up.""" """Clean up."""
...@@ -196,15 +195,9 @@ class TestERP5SyncMLMixin(TestMixin): ...@@ -196,15 +195,9 @@ class TestERP5SyncMLMixin(TestMixin):
def clearFiles(self): def clearFiles(self):
# reset files, because we do sync by files # reset files, because we do sync by files
file_ = open(self._subscription_url1, 'w') for filename in self._subscription_url1, self._subscription_url2, self._publication_url:
file_.write('') with open(filename, 'w') as f:
file_.close() f.write('')
file_ = open(self._subscription_url2, 'w')
file_.write('')
file_.close()
file_ = open(self._publication_url, 'w')
file_.write('')
file_.close()
def synchronize(self, id): # pylint: disable=redefined-builtin def synchronize(self, id): # pylint: disable=redefined-builtin
""" """
...@@ -1880,8 +1873,7 @@ return [context[%r]] ...@@ -1880,8 +1873,7 @@ return [context[%r]]
self.assertXMLViewIsEqual(self.sub_id1, person_s, person_c1) self.assertXMLViewIsEqual(self.sub_id1, person_s, person_c1)
self.assertXMLViewIsEqual(self.sub_id1, person_s, person_c2) self.assertXMLViewIsEqual(self.sub_id1, person_s, person_c2)
def test_readResponse_file(self):
def test_suite(): self.assertRaises(Forbidden,
suite = unittest.TestSuite() self.getSynchronizationTool().readResponse,
suite.addTest(unittest.makeSuite(TestERP5SyncML)) from_url='file:///etc/hosts')
return suite
\ No newline at end of file
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
from logging import getLogger from logging import getLogger
import six import six
from six.moves.urllib.parse import urlparse
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
...@@ -39,6 +40,8 @@ from erp5.component.module.SyncMLMessage import SyncMLRequest ...@@ -39,6 +40,8 @@ from erp5.component.module.SyncMLMessage import SyncMLRequest
from erp5.component.module.SyncMLEngineSynchronous import SyncMLSynchronousEngine from erp5.component.module.SyncMLEngineSynchronous import SyncMLSynchronousEngine
from erp5.component.module.SyncMLEngineAsynchronous import SyncMLAsynchronousEngine from erp5.component.module.SyncMLEngineAsynchronous import SyncMLAsynchronousEngine
from Products.ERP5.ERP5Site import getSite from Products.ERP5.ERP5Site import getSite
from zExceptions import Forbidden
synchronous_engine = SyncMLSynchronousEngine() synchronous_engine = SyncMLSynchronousEngine()
asynchronous_engine = SyncMLAsynchronousEngine() asynchronous_engine = SyncMLAsynchronousEngine()
...@@ -237,22 +240,20 @@ class SynchronizationTool(BaseTool): ...@@ -237,22 +240,20 @@ class SynchronizationTool(BaseTool):
# we use from only if we have a file # we use from only if we have a file
elif isinstance(from_url, six.string_types): elif isinstance(from_url, six.string_types):
if from_url.startswith('file:'): parsed_url = urlparse(from_url)
filename = from_url[len('file:'):] if parsed_url.scheme == 'file':
xml = None if (any(
try: from_url.startswith(pub.getUrlString())
stream = open(filename, 'rb') for pub in self.contentValues(portal_type='SyncML Publication'))
except IOError: or any(
# XXX-Aurel : Why raising here make unit tests to fail ? from_url.startswith(sub.getSubscriptionUrlString())
# raise ValueError("Impossible to read file %s, error is %s" for sub in self.contentValues(portal_type='SyncML Subscription'))):
# % (filename, msg)) with open(parsed_url.path, 'rb') as f:
pass xml = f.read()
else: syncml_logger.debug('readResponse xml from file is %s', xml)
xml = stream.read() return xml or None
stream.close() raise Forbidden
syncml_logger.debug('readResponse xml from file is %s', xml)
if xml:
return xml
# #
# End of part managing protocols # End of part managing protocols
# #
......
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