From c32291b1dc42b76456bf5998f73dc57d26354e91 Mon Sep 17 00:00:00 2001 From: Peter Mathis Date: Tue, 30 Apr 2019 14:26:13 +0200 Subject: [PATCH] Validate imported field values --- news/38.bugfix | 2 ++ plone/app/registry/exportimport/handler.py | 3 +++ plone/app/registry/tests/test_exportimport.py | 26 ++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 news/38.bugfix diff --git a/news/38.bugfix b/news/38.bugfix new file mode 100644 index 0000000..7a2800d --- /dev/null +++ b/news/38.bugfix @@ -0,0 +1,2 @@ +validate imported field values +[petschki] diff --git a/plone/app/registry/exportimport/handler.py b/plone/app/registry/exportimport/handler.py index f34cf5e..548b801 100644 --- a/plone/app/registry/exportimport/handler.py +++ b/plone/app/registry/exportimport/handler.py @@ -285,6 +285,9 @@ def importRecord(self, node): if value is _marker: value = field.default value_purge = True + else: + # validate incoming value + field.validate(value) if existing_record is not None: if change_field: diff --git a/plone/app/registry/tests/test_exportimport.py b/plone/app/registry/tests/test_exportimport.py index 8a97391..4895b37 100644 --- a/plone/app/registry/tests/test_exportimport.py +++ b/plone/app/registry/tests/test_exportimport.py @@ -14,13 +14,14 @@ from plone.registry.interfaces import IRegistry from plone.supermodel.utils import prettyXML from plone.testing import zca -from Products.GenericSetup.tests.common import DummyImportContext as BaseDummyImportContext +from Products.GenericSetup.tests.common import DummyImportContext as BaseDummyImportContext # noqa from Products.GenericSetup.tests.common import DummyExportContext from zope.component import provideUtility from zope.configuration import xmlconfig from zope.interface import alsoProvides import unittest +import zope.schema configuration = """\ @@ -393,6 +394,29 @@ def test_import_value_only(self): self.registry['test.export.simple'] ) + def test_import_value_validation(self): + xml = """\ + + + + + +""" + context = DummyImportContext(self.site, purge=False) + context._files = {'registry.xml': xml} + + self.registry.records['test.export.simple'] = \ + Record(field.TextLine(title=u"Simple record", default=u"N/A"), + value=u"Sample value") + + try: + importRegistry(context) + except zope.schema._bootstrapinterfaces.RequiredMissing: + # this should raise RequiredMissing + pass + else: + self.fail() + def test_import_value_only_condition_installed(self): xml = """\