fix for datetime.strftime

This commit is contained in:
Elizabeth Esswein 2022-10-07 15:20:38 -04:00
parent d3e8ac7b9f
commit 1a3fde9401
2 changed files with 8 additions and 1 deletions

View File

@ -83,6 +83,12 @@ from spiffworkflow_backend.services.user_service import UserService
# Sorry about all this crap. I wanted to move this thing to another file, but
# importing a bunch of types causes circular imports.
def _import(name: str, glbls: Dict[str, Any], *args: Any) -> None:
if name not in glbls:
raise ImportError(f"Import not allowed: {name}", name=name)
DEFAULT_GLOBALS.update(
{
"datetime": datetime,
@ -92,6 +98,7 @@ DEFAULT_GLOBALS.update(
)
# This will overwrite the standard builtins
DEFAULT_GLOBALS.update(safe_globals)
DEFAULT_GLOBALS["__builtins__"]["__import__"] = _import
class CustomBpmnScriptEngine(PythonScriptEngine): # type: ignore

View File

@ -55,4 +55,4 @@ class TestImportModule(BaseTest):
with pytest.raises(ApiError) as exception:
processor.do_engine_steps(save=True)
assert "ImportError:__import__ not found" in str(exception.value)
assert "Import not allowed: os" in str(exception.value)