mirror of
https://github.com/dkmstr/openuds.git
synced 2025-03-20 06:50:23 +03:00
Added new serization method to user interface
Now it's more flexible and secure. It's compatible reading old data
This commit is contained in:
parent
0e94fae1bf
commit
ca2227490e
@ -59,9 +59,6 @@ class UserinterfaceTest(UDSTestCase):
|
||||
self.assertEqual(ui.image_field.value, DEFAULTS['image_field'], 'image_field')
|
||||
self.assertEqual(ui.date_field.value, DEFAULTS['date_field'], 'date_field')
|
||||
|
||||
def test_serialization(self):
|
||||
pass
|
||||
|
||||
def test_old_serialization(self):
|
||||
# This test is to ensure that old serialized data can be loaded
|
||||
# This data is from a
|
||||
|
@ -1216,8 +1216,8 @@ class UserInterface(metaclass=UserInterfaceType):
|
||||
# Any unexpected type will raise an exception
|
||||
arr = [(k, v.type.name, fw_converters[v.type](v)) for k, v in self._gui.items() if fw_converters[v.type](v) is not None]
|
||||
|
||||
return codecs.encode(
|
||||
SERIALIZATION_HEADER + SERIALIZATION_VERSION + serialize(arr).encode(),
|
||||
return SERIALIZATION_HEADER + SERIALIZATION_VERSION + codecs.encode(
|
||||
serialize(arr).encode(),
|
||||
'zip',
|
||||
)
|
||||
|
||||
@ -1241,20 +1241,17 @@ class UserInterface(metaclass=UserInterfaceType):
|
||||
if not values:
|
||||
return
|
||||
|
||||
tmp_values = codecs.decode(values, 'zip')
|
||||
if not tmp_values:
|
||||
return
|
||||
|
||||
if not tmp_values.startswith(SERIALIZATION_HEADER):
|
||||
if not values.startswith(SERIALIZATION_HEADER):
|
||||
# Unserialize with old method
|
||||
self.oldUnserializeForm(values)
|
||||
return
|
||||
|
||||
values = tmp_values
|
||||
|
||||
|
||||
version = values[len(SERIALIZATION_HEADER) : len(SERIALIZATION_HEADER) + len(SERIALIZATION_VERSION)]
|
||||
# Currently, only 1 version is available, ignore it
|
||||
values = values[len(SERIALIZATION_HEADER) + len(SERIALIZATION_VERSION) :]
|
||||
|
||||
values = codecs.decode(values[len(SERIALIZATION_HEADER) + len(SERIALIZATION_VERSION) :], 'zip')
|
||||
if not values:
|
||||
return
|
||||
|
||||
arr = unserialize(values.decode())
|
||||
|
||||
# Set all values to defaults ones
|
||||
|
Loading…
x
Reference in New Issue
Block a user