Skip to content

Commit

Permalink
[3.0.34] Fix backend and fronted bugs
Browse files Browse the repository at this point in the history
 - [back] Password share relative links
 - [front] Sub table search
 - [front] Order table first line
  • Loading branch information
mauricelambert committed May 23, 2024
1 parent 66dbbf7 commit 53f3a6a
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 156 deletions.
2 changes: 1 addition & 1 deletion WebScripts.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: WebScripts
Version: 3.0.33
Version: 3.0.34
Summary: This tool runs CLI scripts and displays output in a Web Interface.
Home-page: https://github.com/mauricelambert/WebScripts
Author: Maurice Lambert
Expand Down
25 changes: 17 additions & 8 deletions test/TestCommons.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,21 @@ def test_get_scripts_from_configuration(self):
configuration.scripts = {"test.py": "test"}
configuration.force_file_permissions = True

with self.assertRaises(WebScriptsConfigurationError), patch.object(
WebScripts.commons, "check_file_permission", return_value=True
with (
self.assertRaises(WebScriptsConfigurationError),
patch.object(
WebScripts.commons, "check_file_permission", return_value=True
),
):
ScriptConfig.get_scripts_from_configuration(configuration, None)

configuration.test = {}

with patch.object(
ScriptConfig, "get_script_path"
) as mock_config_path, patch.object(
WebScripts.commons, "check_file_permission", return_value=True
with (
patch.object(ScriptConfig, "get_script_path") as mock_config_path,
patch.object(
WebScripts.commons, "check_file_permission", return_value=True
),
):
mock_config_path.return_value = "/fake/path/test.py"
script_configs = ScriptConfig.get_scripts_from_configuration(
Expand All @@ -235,8 +239,13 @@ def test_get_scripts_from_configuration(self):
WebScripts.commons, "get_real_path"
) as mock_real_path:
mock_real_path.return_value = "/fake/path/test.py"
with self.assertRaises(WebScriptsConfigurationError), patch.object(
WebScripts.commons, "check_file_permission", return_value=True
with (
self.assertRaises(WebScriptsConfigurationError),
patch.object(
WebScripts.commons,
"check_file_permission",
return_value=True,
),
):
ScriptConfig.get_scripts_from_configuration(
configuration, configuration
Expand Down
257 changes: 143 additions & 114 deletions test/TestPages.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,20 @@ def test_execute_scripts(self):
script = Mock(path="path", launcher=None)
Pages.scripts = {"test": script}

with patch.object(
Module,
"get_environ",
return_value={"test": "test1"},
) as m_get_environ, patch.object(
Module, "Popen", return_value="process"
) as m_popen, patch.object(
Module,
"start_process",
return_value=("stdout", "stderr", "key", "error", "code"),
) as m_start_process, patch.object(
Module, "execution_logs"
) as m_logs:
with (
patch.object(
Module,
"get_environ",
return_value={"test": "test1"},
) as m_get_environ,
patch.object(Module, "Popen", return_value="process") as m_popen,
patch.object(
Module,
"start_process",
return_value=("stdout", "stderr", "key", "error", "code"),
) as m_start_process,
patch.object(Module, "execution_logs") as m_logs,
):
out, err, key, code, error = execute_scripts(
"test",
"User",
Expand Down Expand Up @@ -143,19 +144,20 @@ def test_execute_scripts(self):
script = Mock(path="path", launcher="launcher")
Pages.scripts = {"test": script}

with patch.object(
Module,
"get_environ",
return_value={"test": "test1"},
) as m_get_environ, patch.object(
Module, "Popen", return_value="process"
) as m_popen, patch.object(
Module,
"start_process",
return_value=("stdout", "stderr", "key", "error", "code"),
) as m_start_process, patch.object(
Module, "execution_logs"
) as m_logs:
with (
patch.object(
Module,
"get_environ",
return_value={"test": "test1"},
) as m_get_environ,
patch.object(Module, "Popen", return_value="process") as m_popen,
patch.object(
Module,
"start_process",
return_value=("stdout", "stderr", "key", "error", "code"),
) as m_start_process,
patch.object(Module, "execution_logs") as m_logs,
):
out, err, key, code, error = execute_scripts(
"test",
"User",
Expand Down Expand Up @@ -417,11 +419,14 @@ class MyObjectTest:
self.assertFalse(check_categories_scripts_access(user, configuration))

def test_decode_output(self):
with patch.object(
WebScripts.utils, "getpreferredencoding", return_value=None
) as m1, patch.object(
WebScripts.utils, "device_encoding", return_value=None
) as m2:
with (
patch.object(
WebScripts.utils, "getpreferredencoding", return_value=None
) as m1,
patch.object(
WebScripts.utils, "device_encoding", return_value=None
) as m2,
):
self.assertEqual("\u2588", decode_output(b"\xe2\x96\x88"))
self.assertEqual("\xff\xfe\xef", decode_output(b"\xff\xfe\xef"))
self.assertEqual("€", decode_output(b"\x80"))
Expand Down Expand Up @@ -696,14 +701,16 @@ def test_scripts(self):
)
user.check_csrf = True

with patch.object(
Module,
"execute_scripts",
return_value=(b"result", b"error", "key", 0, "TimeoutError"),
) as mock, patch.object(
Module.TokenCSRF, "check_csrf", return_value=True
), patch.object(
Module.TokenCSRF, "build_token", return_value="token"
with (
patch.object(
Module,
"execute_scripts",
return_value=(b"result", b"error", "key", 0, "TimeoutError"),
) as mock,
patch.object(Module.TokenCSRF, "check_csrf", return_value=True),
patch.object(
Module.TokenCSRF, "build_token", return_value="token"
),
):
code, headers, data = self.api.scripts(
Mock(), user, server, "other.sh", Mock(), Mock(), "token"
Expand Down Expand Up @@ -795,25 +802,31 @@ def test_doc(self):
server = Mock()
env = Mock()

with patch.object(
Module,
"check_right",
return_value=True,
) as rigth, patch.object(
Module,
"Popen",
return_value=Mock(),
) as popen, patch.object(
Module, "get_environ", return_value={"env": "env"}
) as getenv, patch.object(
Module.ScriptConfig,
"get_docfile_from_configuration",
return_value=None,
) as get_docfile, patch.object(
Module,
"get_real_path",
return_value="file.txt",
) as get_file:
with (
patch.object(
Module,
"check_right",
return_value=True,
) as rigth,
patch.object(
Module,
"Popen",
return_value=Mock(),
) as popen,
patch.object(
Module, "get_environ", return_value={"env": "env"}
) as getenv,
patch.object(
Module.ScriptConfig,
"get_docfile_from_configuration",
return_value=None,
) as get_docfile,
patch.object(
Module,
"get_real_path",
return_value="file.txt",
) as get_file,
):
code, headers, data = self.web.doc(
env, user, server, "test.go", Mock(), Mock(), Mock()
)
Expand All @@ -833,23 +846,28 @@ def test_doc(self):
script.command_generate_documentation = None
script.get_dict = None

with patch.object(
Module,
"check_right",
return_value=True,
) as rigth, patch.object(
Module.path,
"isfile",
return_value=True,
) as isfile, patch.object(
Module,
"get_file_content",
return_value=b"data",
) as getcontent, patch.object(
Module,
"get_real_path",
return_value="file.txt",
) as get_file:
with (
patch.object(
Module,
"check_right",
return_value=True,
) as rigth,
patch.object(
Module.path,
"isfile",
return_value=True,
) as isfile,
patch.object(
Module,
"get_file_content",
return_value=b"data",
) as getcontent,
patch.object(
Module,
"get_real_path",
return_value="file.txt",
) as get_file,
):
code, headers, data = self.web.doc(
env, user, server, "test.go", Mock(), Mock(), Mock()
)
Expand All @@ -863,23 +881,28 @@ def test_doc(self):
self.assertDictEqual(headers, {"Content-Type": "html; charset=utf-8"})
self.assertEqual(data, b"data")

with patch.object(
Module,
"check_right",
return_value=True,
) as rigth, patch.object(
Module.ScriptConfig,
"get_docfile_from_configuration",
return_value="file.txt",
) as get_docfile, patch.object(
Module,
"get_file_content",
return_value=b"data",
) as getcontent, patch.object(
Module,
"get_real_path",
return_value="file.txt",
) as get_file:
with (
patch.object(
Module,
"check_right",
return_value=True,
) as rigth,
patch.object(
Module.ScriptConfig,
"get_docfile_from_configuration",
return_value="file.txt",
) as get_docfile,
patch.object(
Module,
"get_file_content",
return_value=b"data",
) as getcontent,
patch.object(
Module,
"get_real_path",
return_value="file.txt",
) as get_file,
):
code, headers, data = self.web.doc(
env, user, server, "test.go", Mock(), Mock(), Mock()
)
Expand Down Expand Up @@ -944,9 +967,10 @@ def test_scripts(self):

Pages.scripts["other.sh"] = "other"

with patch.object(
Module, "check_right", return_value=True
), patch.object(Module, "CallableFile", return_value=None):
with (
patch.object(Module, "check_right", return_value=True),
patch.object(Module, "CallableFile", return_value=None),
):
code, headers, data = self.web.scripts(
Mock(), Mock(), server, "other.sh", Mock(), Mock()
)
Expand All @@ -964,10 +988,11 @@ def test_scripts(self):
self.assertDictEqual({}, headers)
self.assertEqual(data, b"")

with patch.object(
Module, "check_right", return_value=True
), patch.object(
Module, "CallableFile", return_value=Mock(return_value="test")
with (
patch.object(Module, "check_right", return_value=True),
patch.object(
Module, "CallableFile", return_value=Mock(return_value="test")
),
):
self.assertEqual(
"test",
Expand Down Expand Up @@ -1127,21 +1152,25 @@ def test_auth(self):
)

user_session = Mock(id=1)
with patch.object(
Module,
"execute_scripts",
return_value=(
b'{"data":"data"}',
b"",
"key",
0,
"TimeoutError",
),
) as mock, patch.object(
Module.User, "default_build", return_value=user_session
) as getuser, patch.object(
Module.Session, "build_session", return_value="cookie"
) as session:
with (
patch.object(
Module,
"execute_scripts",
return_value=(
b'{"data":"data"}',
b"",
"key",
0,
"TimeoutError",
),
) as mock,
patch.object(
Module.User, "default_build", return_value=user_session
) as getuser,
patch.object(
Module.Session, "build_session", return_value="cookie"
) as session,
):
code, headers, data = self.pages.auth(
env, user, server, script, command, inputs
)
Expand Down
Loading

0 comments on commit 53f3a6a

Please sign in to comment.