From 5d54a08581ad1f42722c96d997f646ae653108e3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 28 Jun 2021 17:17:19 +0200 Subject: [PATCH] [calamares] Allow disabling the Python pre-script The test-application injects a script into Python code to render harmless functions in the subprocess module (eg to avoid Python code from running the package manager for real). There are cases, though, where that injection should be skipped (eg because the whole point of test- loading some Python is to check commands that are run). Add a -P option to the test-application to do that. --- src/calamares/testmain.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/calamares/testmain.cpp b/src/calamares/testmain.cpp index 250b047eb..2ce75d919 100644 --- a/src/calamares/testmain.cpp +++ b/src/calamares/testmain.cpp @@ -62,6 +62,7 @@ struct ModuleConfig QString m_language; QString m_branding; bool m_ui; + bool m_pythonInjection; }; static ModuleConfig @@ -86,7 +87,6 @@ handle_args( QCoreApplication& a ) QStringLiteral( "Enable UI" ) ); QCommandLineOption slideshowOption( QStringList() << QStringLiteral( "s" ) << QStringLiteral( "slideshow" ), QStringLiteral( "Run slideshow module" ) ); - QCommandLineParser parser; parser.setApplicationDescription( "Calamares module tester" ); parser.addHelpOption(); @@ -99,6 +99,12 @@ handle_args( QCoreApplication& a ) parser.addOption( brandOption ); parser.addOption( uiOption ); parser.addOption( slideshowOption ); +#ifdef WITH_PYTHON + QCommandLineOption pythonOption( QStringList() << QStringLiteral( "P" ) << QStringLiteral( "no-injected-python" ), + QStringLiteral( "Do not disable potentially-harmful Python commands" ) ); + parser.addOption( pythonOption ); +#endif + parser.addPositionalArgument( "module", "Path or name of module to run." ); parser.addPositionalArgument( "job.yaml", "Path of job settings document to use.", "[job.yaml]" ); @@ -123,12 +129,21 @@ handle_args( QCoreApplication& a ) jobSettings = args.at( 1 ); } + bool pythonInjection = true; +#ifdef WITH_PYTHON + if ( parser.isSet( pythonOption ) ) + { + pythonInjection = false; + } +#endif return ModuleConfig { parser.isSet( slideshowOption ) ? QStringLiteral( "-" ) : args.first(), jobSettings, parser.value( globalOption ), parser.value( langOption ), parser.value( brandOption ), - parser.isSet( slideshowOption ) || parser.isSet( uiOption ) }; + parser.isSet( slideshowOption ) || parser.isSet( uiOption ), + pythonInjection + }; } } @@ -430,7 +445,10 @@ main( int argc, char* argv[] ) } #ifdef WITH_PYTHON - Calamares::PythonJob::setInjectedPreScript(pythonPreScript); + if ( module.m_pythonInjection ) + { + Calamares::PythonJob::setInjectedPreScript(pythonPreScript); + } #endif #ifdef WITH_QML CalamaresUtils::initQmlModulesDir(); // don't care if failed