From 14635d1e4c2df1ed14c495e61fcc4acede0f864f Mon Sep 17 00:00:00 2001 From: Kurt Garloff Date: Wed, 6 Dec 2023 16:55:44 +0100 Subject: [PATCH] Feat/flavor form urllib (#403) * Use URLLIB. Prepare to parse generator as well. The latter uses global variables to store the state. The idea is that we can be invoked either way, parsing a flavor name (and generating a spec and a pretty description) or parsing the specs (and generating the name from it). * Avoid script injection. * Avoid any HTML tags in flavor name. * Appease flake8 Signed-off-by: Kurt Garloff --- Tests/iaas/flavor-naming/flavor-form.py | 70 +++++++++++++++---------- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/Tests/iaas/flavor-naming/flavor-form.py b/Tests/iaas/flavor-naming/flavor-form.py index 006fc38ac..e238fbbb9 100755 --- a/Tests/iaas/flavor-naming/flavor-form.py +++ b/Tests/iaas/flavor-naming/flavor-form.py @@ -12,43 +12,55 @@ or a human-readable description of the flavor. """ -# import os +import os import sys import re -# import traceback -# TODO: Replace cgi by urllib, cgi is deprecated -import cgi +import urllib.parse +import importlib +fnmck = importlib.import_module("flavor-name-check") +# Global variables +FLAVOR_NAME = "" +FLAVOR_SPEC = () +ERROR = "" -class TestForm: - "Class for testing via cmd line" - def __init__(self, fnm): - self.value = fnm + +def parse_name(fnm): + "return tuple with flavor description" + global FLAVOR_SPEC, FLAVOR_NAME, ERROR + # Sanitize + # fnm = re.sub(r"<( *script)", r"