Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix profiler path validation #656

Merged
merged 16 commits into from Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Expand Up @@ -125,12 +125,16 @@ check: format lint test
@echo -e "${GRN}--- Pre-Push checks complete${NC}"
git status

# Generate Fedora rawhide rpms
fc-rpm:
@echo -e "${GRN}--- Fedora RPM generation...${NC}"
make -f .copr/Makefile vendor
podman build -t fapolicy-analyzer:rawhide -f Containerfile .
podman run --rm -it --network=none -v /tmp:/v fapolicy-analyzer:rawhide /v

# Generate RHEL rpms
el-rpm:
@echo -e "${GRN}--- Rhel RPM generation...${NC}"
make -f .copr/Makefile vendor
podman build -t fapolicy-analyzer:el -f scripts/srpm/Containerfile.el .
podman run --rm -it --network=none -v /tmp:/v fapolicy-analyzer:el /v
Expand All @@ -145,7 +149,7 @@ list-all:
@echo -e "${GRN}---Displaying all fapolicy-analyzer targets${NC}"
@echo
# Input to the loop is a list of targets extracted from this Makefile
@for t in `grep -E -o '^[^#].+*:' Makefile | egrep -v 'echo|@'`;\
@for t in `grep -E -o '^[^#].+*:' Makefile | egrep -v 'echo|@|podman'`;\
do # Output the target w/o a newline\
echo -e -n "$$t \t";\
# grep the Makefile for the target; print line immediately preceding it\
Expand Down
50 changes: 27 additions & 23 deletions fapolicy_analyzer/locale/fapolicy_analyzer.pot
Expand Up @@ -291,38 +291,42 @@ msgid ": file is not executable"
msgstr ""

#: fapolicy_analyzer/ui/strings.py:103
msgid ": user does not exist"
msgid ": command not found"
msgstr ""

#: fapolicy_analyzer/ui/strings.py:104
msgid ": working directory does not exist."
msgid ": user does not exist"
msgstr ""

#: fapolicy_analyzer/ui/strings.py:105
msgid ": working directory is not a directory."
msgid ": working directory does not exist."
msgstr ""

#: fapolicy_analyzer/ui/strings.py:106
msgid ": env vars not comma delimited K=V pairs"
msgid ": working directory is not a directory."
msgstr ""

#: fapolicy_analyzer/ui/strings.py:107
msgid ": env vars not comma delimited K=V pairs"
msgstr ""

#: fapolicy_analyzer/ui/strings.py:108
msgid "Error: Unknown Profiler Session arguments"
msgstr ""

#: fapolicy_analyzer/ui/strings.py:109
#: fapolicy_analyzer/ui/strings.py:110
msgid "File path(s) contains embedded whitespace."
msgstr ""

#: fapolicy_analyzer/ui/strings.py:110
#: fapolicy_analyzer/ui/strings.py:111
msgid ""
"fapolicyd currently does not support paths containing spaces. The "
"following paths will not be added to the Trusted Files List.\n"
"(fapolicyd: V TBD)\n"
"\n"
msgstr ""

#: fapolicy_analyzer/ui/strings.py:115
#: fapolicy_analyzer/ui/strings.py:116
msgid ""
"\n"
" Restore your prior session now?\n"
Expand All @@ -339,57 +343,57 @@ msgid ""
" "
msgstr ""

#: fapolicy_analyzer/ui/strings.py:131
#: fapolicy_analyzer/ui/strings.py:132
msgid "An error occurred trying to restore a prior autosaved edit session"
msgstr ""

#: fapolicy_analyzer/glade/loader.glade:44 fapolicy_analyzer/ui/strings.py:135
#: fapolicy_analyzer/glade/loader.glade:44 fapolicy_analyzer/ui/strings.py:136
msgid "Loading..."
msgstr ""

#: fapolicy_analyzer/ui/strings.py:137
#: fapolicy_analyzer/ui/strings.py:138
msgid "file"
msgstr ""

#: fapolicy_analyzer/ui/strings.py:138
#: fapolicy_analyzer/ui/strings.py:139
msgid "files"
msgstr ""

#: fapolicy_analyzer/ui/strings.py:139
#: fapolicy_analyzer/ui/strings.py:140
msgid "user"
msgstr ""

#: fapolicy_analyzer/ui/strings.py:140
#: fapolicy_analyzer/ui/strings.py:141
msgid "users"
msgstr ""

#: fapolicy_analyzer/ui/strings.py:141
#: fapolicy_analyzer/ui/strings.py:142
msgid "group"
msgstr ""

#: fapolicy_analyzer/ui/strings.py:142
#: fapolicy_analyzer/ui/strings.py:143
msgid "groups"
msgstr ""

#: fapolicy_analyzer/ui/strings.py:143
#: fapolicy_analyzer/ui/strings.py:144
msgid ""
"An error occurred trying to parse the event log file. Please try again or"
" select a different file."
msgstr ""

#: fapolicy_analyzer/ui/strings.py:146
#: fapolicy_analyzer/ui/strings.py:147
msgid "An error occurred trying to retrieve the user list. Please try again."
msgstr ""

#: fapolicy_analyzer/ui/strings.py:149
#: fapolicy_analyzer/ui/strings.py:150
msgid "An error occurred trying to retrieve the group list. Please try again."
msgstr ""

#: fapolicy_analyzer/ui/strings.py:153
#: fapolicy_analyzer/ui/strings.py:154
msgid "Could not load application resources"
msgstr ""

#: fapolicy_analyzer/ui/strings.py:154
#: fapolicy_analyzer/ui/strings.py:155
msgid ""
"The required application resource files could not be loaded from disk.\n"
"The fapolicy analyzer application cannot open.\n"
Expand All @@ -401,11 +405,11 @@ msgid ""
"2. An incorrectly configured fapolicyd rule set."
msgstr ""

#: fapolicy_analyzer/ui/strings.py:165
#: fapolicy_analyzer/ui/strings.py:166
msgid "Trust Database"
msgstr ""

#: fapolicy_analyzer/ui/strings.py:166
#: fapolicy_analyzer/ui/strings.py:167
msgid ""
"\n"
"The fapolicyd trusted resources database\n"
Expand All @@ -430,7 +434,7 @@ msgid ""
" "
msgstr ""

#: fapolicy_analyzer/ui/strings.py:190
#: fapolicy_analyzer/ui/strings.py:191
msgid "Error applying changes"
msgstr ""

Expand Down
16 changes: 16 additions & 0 deletions fapolicy_analyzer/tests/test_fapd_manager.py
Expand Up @@ -13,6 +13,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import os
import glob
import pytest
from unittest.mock import MagicMock
from fapolicy_analyzer.ui.fapd_manager import FapdManager, FapdMode, ServiceStatus
Expand Down Expand Up @@ -91,6 +93,12 @@ def test_start_profiling(fapdManager, mocker):
mockFapdHandle.stop.assert_called()
assert fapdManager.mode == FapdMode.PROFILING

# Clean up
for f in glob.glob("/tmp/fapd_profiling_*.stdout"):
os.remove(f)
for f in glob.glob("/tmp/fapd_profiling_*.stderr"):
os.remove(f)


def test_status_disabled(fapdManager, mocker):
fapdManager.mode = FapdMode.DISABLED
Expand Down Expand Up @@ -121,3 +129,11 @@ def test_status_profiling_fapd(fapdManager, mocker):
fapdManager.procProfile = MagicMock()
bStatus = fapdManager._status()
assert bStatus == ServiceStatus.TRUE


def test_initial_daemon_status(fapdManager, mocker):
mockFapdHandle = MagicMock()
fapdManager._fapd_ref = mockFapdHandle
fapdManager._fapd_ref.is_valid = False
bStatus = fapdManager._status()
assert bStatus == ServiceStatus.UNKNOWN