diff --git a/.github/workflows/pythontest.yml b/.github/workflows/pythontest.yml index 256c0faa4..018b02890 100644 --- a/.github/workflows/pythontest.yml +++ b/.github/workflows/pythontest.yml @@ -4,9 +4,11 @@ on: push: paths: - "salt/sensoroni/files/analyzers/**" + - "salt/manager/tools/sbin" pull_request: paths: - "salt/sensoroni/files/analyzers/**" + - "salt/manager/tools/sbin" jobs: build: @@ -16,7 +18,7 @@ jobs: fail-fast: false matrix: python-version: ["3.10"] - python-code-path: ["salt/sensoroni/files/analyzers"] + python-code-path: ["salt/sensoroni/files/analyzers", "salt/manager/tools/sbin"] steps: - uses: actions/checkout@v3 diff --git a/salt/manager/tools/sbin/so-yaml.py b/salt/manager/tools/sbin/so-yaml.py index c8f102770..68f9b43fe 100755 --- a/salt/manager/tools/sbin/so-yaml.py +++ b/salt/manager/tools/sbin/so-yaml.py @@ -85,10 +85,8 @@ def main(): cmd = commands.get(args[0], showUsage) code = cmd(args[1:]) finally: - try: + if os.path.exists(lockFile): os.remove(lockFile) - except Exception: - print("Lock file (" + lockFile + ") already removed") sys.exit(code) diff --git a/salt/manager/tools/sbin/so-yaml_test.py b/salt/manager/tools/sbin/so-yaml_test.py index 7e03da9d0..0f2ac7d81 100644 --- a/salt/manager/tools/sbin/so-yaml_test.py +++ b/salt/manager/tools/sbin/so-yaml_test.py @@ -1,5 +1,5 @@ # Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one -# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at +# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at # https://securityonion.net/license; you may not use this file except in compliance with the # Elastic License 2.0. @@ -21,6 +21,19 @@ class TestRemove(unittest.TestCase): sysmock.assert_called_once_with(1) self.assertIn(mock_stdout.getvalue(), "Usage:") + def test_main_help_locked(self): + filename = "/tmp/so-yaml.lock" + file = open(filename, "w") + file.write = "fake lock file" + with patch('sys.exit', new=MagicMock()) as sysmock: + with patch('sys.stderr', new=StringIO()) as mock_stdout: + with patch('time.sleep', new=MagicMock()) as mock_sleep: + sys.argv = ["cmd", "help"] + soyaml.main() + sysmock.assert_called() + mock_sleep.assert_called_with(2) + self.assertIn(mock_stdout.getvalue(), "Usage:") + def test_main_help(self): with patch('sys.exit', new=MagicMock()) as sysmock: with patch('sys.stderr', new=StringIO()) as mock_stdout: