@@ -288,3 +288,48 @@ def test_setup_lighttpd_bind(
288288 assert "server.bind" not in config .stdout
289289 else :
290290 assert f'server.bind = "{ expected_bind } "' in config .stdout
291+
292+ @pytest .fixture (autouse = True )
293+ def run_around_test_setup_web_theme (docker ):
294+ """Fixture to execute around test_setup_web_theme"""
295+ docker .run ("touch /var/www/html/admin/style/themes/{badtheme,bad.theme.css,goodtheme.css}" )
296+
297+ yield
298+
299+ docker .run ("rm /var/www/html/admin/style/themes/{badtheme,bad.theme.css,goodtheme.css}" )
300+
301+ @pytest .mark .parametrize (
302+ "args_env,test_theme,expected_success" ,
303+ [
304+ ("-e WEBTHEME=asd" , "asd" , False ),
305+ ("-e WEBTHEME=default-light" , "default-light" , True ),
306+ #("-e WEBTHEME=", "", False), # the tested function does nothing in this case
307+ ("-e WEBTHEME=default-dark" , "default-dark" , True ),
308+ ("-e WEBTHEME=efault-dark" , "efault-dark" , False ),
309+ ("-e WEBTHEME=efault-dar" , "efault-dar" , False ),
310+ ("-e WEBTHEME=default-dar" , "default-dar" , False ),
311+ ("-e WEBTHEME=xdefault-dark" , "xdefault-dark" , False ),
312+ ("-e WEBTHEME=xdefault-darkx" , "xdefault-darkx" , False ),
313+ ("-e WEBTHEME=default-darkx" , "default-darkx" , False ),
314+ ("-e WEBTHEME=badtheme" , "badtheme" , False ), # the theme file does not have the right extension
315+ ("-e WEBTHEME=badtheme.css" , "badtheme.css" , False ), # hacking attempt ?
316+ ("-e WEBTHEME=bad.theme" , "bad.theme" , False ), # invalid name - has dot
317+ ("-e WEBTHEME=goodtheme" , "goodtheme" , True ),
318+ ("-e WEBTHEME=goodtheme.css" , "goodtheme.css" , False ), # hacking attempt ?
319+ ("-e WEBTHEME=+" , "+" , False ),
320+ ("-e WEBTHEME=." , "." , False ),
321+ ],
322+ )
323+ def test_setup_web_theme (
324+ docker , args_env , test_theme , expected_success
325+ ):
326+ """Web theme name validation works"""
327+ DEFAULT_THEME = "default-light"
328+ function = docker .run (". /usr/local/bin/bash_functions.sh ; setup_web_theme" )
329+
330+ if expected_success :
331+ assert f' [i] setting web theme based on webtheme variable, using value { test_theme } ' in function .stdout .lower ()
332+ assert docker .run (_grep (f'^WEBTHEME={ test_theme } $' , SETUPVARS_LOC )).rc == 0
333+ else :
334+ assert f' [!] invalid theme name supplied: { test_theme } , falling back to { DEFAULT_THEME } .' in function .stdout .lower ()
335+ assert docker .run (_grep (f'^WEBTHEME={ DEFAULT_THEME } $' , SETUPVARS_LOC )).rc == 0
0 commit comments