Pārlūkot izejas kodu

HUE-5112 [oozie] Protect against invalid parameter values in document action

e.g.
  File "/home/romain/projects/hue/apps/oozie/src/oozie/models2.py", line 395, in find_parameters
    name, val = param['value'].split('=')
ValueError: need more than 1 value to unpack
Romain Rigaux 9 gadi atpakaļ
vecāks
revīzija
89fb005d22

+ 3 - 2
apps/oozie/src/oozie/models2.py

@@ -392,8 +392,9 @@ class Workflow(Job):
     for node in self.nodes:
       if 'document' in node.data['type']:
         for param in node.data['properties']['parameters']:
-          name, val = param['value'].split('=')
-          parameters[name] = val
+          if param['value'] and '=' in param['value']:
+            name, val = param['value'].split('=', 1)
+            parameters[name] = val
       else:
         extra = node.find_parameters()
         if extra:

+ 16 - 0
apps/oozie/src/oozie/models2_tests.py

@@ -1051,6 +1051,22 @@ class TestModelAPI(OozieMockBase):
     assert_equal(len(_data['workflow']['nodes']), 4)
 
 
+  def test_find_all_parameters_check_validity(self):
+    wf_data = Workflow.get_default_workflow()
+
+    wf_data['properties'] = Workflow.get_properties()
+    wf_data['nodes'] = [{
+          u'name': u'Start',
+          u'properties': {'parameters': [{'value': 'a=1'}, {'value': 'b'}, {'value': ''}, {'value':'c=d=1'}]},
+          u'id': u'3f107997-04cc-8733-60a9-a4bb62cebffc',
+          u'type': u'document-widget',
+          u'children': [{u'to': u'33430f0f-ebfa-c3ec-f237-3e77efa03d0a'}],
+          u'actionParameters': [],
+        }]
+
+    assert_equal({u'a': u'1', u'c': u'd=1'}, Workflow(data=json.dumps({'workflow': wf_data})).find_parameters())
+
+
   def test_gen_hive_xml(self):
     notebook = make_notebook(name='Browse', editor_type='hive', statement='SHOW TABLES', status='ready')
     notebook_doc, save_as = _save_notebook(notebook.get_data(), self.user)