forked from EmpireProject/Empire
-
-
Notifications
You must be signed in to change notification settings - Fork 692
Expand file tree
/
Copy pathps-empire
More file actions
executable file
·130 lines (117 loc) · 3.71 KB
/
Copy pathps-empire
File metadata and controls
executable file
·130 lines (117 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
INSTALL=0
TEST=0
YES_OPTION=""
FORCE_OPTION=""
OVERRIDE_OPTION=""
COMPILE_OPTION=""
EMPIRE_ARGS=()
TEST_ARGS=()
# Once we see "test", all remaining args go to pytest
COLLECTING_TEST_ARGS=0
for arg in "$@"; do
if [ $COLLECTING_TEST_ARGS -eq 1 ]; then
TEST_ARGS+=("$arg")
continue
fi
case $arg in
install)
INSTALL=1
;;
test)
TEST=1
COLLECTING_TEST_ARGS=1
;;
-y)
YES_OPTION="-y"
;;
-f)
FORCE_OPTION="-f"
;;
-o)
OVERRIDE_OPTION="-o"
;;
-c)
COMPILE_OPTION="-c"
;;
-h)
SHOW_HELP="-h"
;;
*)
EMPIRE_ARGS+=("$arg")
;;
esac
done
if [ $INSTALL -eq 1 ] && [ $TEST -eq 1 ]; then
echo -e "\x1b[1;31m[!] 'install' and 'test' cannot be used together.\x1b[0m"
exit 1
fi
if [ $INSTALL -eq 1 ]; then
./setup/install.sh $SHOW_HELP $YES_OPTION $FORCE_OPTION $OVERRIDE_OPTION $COMPILE_OPTION
exit $?
fi
# Top-level -h (without install/test) — pass through to empire.py
if [ $TEST -eq 0 ] && [ -n "$SHOW_HELP" ]; then
EMPIRE_ARGS+=("$SHOW_HELP")
fi
# ./ps-empire test [pytest args...]
# All arguments after "test" are passed directly to pytest so that
# pytest flags are not consumed by ps-empire's own argument parser.
#
# Examples:
# ./ps-empire test # run all tests
# ./ps-empire test -v # verbose output
# ./ps-empire test --runslow # include slow tests
# ./ps-empire test --cov=empire/server # with coverage
# ./ps-empire test empire/test/test_agent_api.py # single file
# ./ps-empire test empire/test/test_agent_api.py::test_get_agent # single test
# ./ps-empire test -v --runslow --nodocker # combine flags
if [ $TEST -eq 1 ]; then
# Check if -h/--help was passed after "test" (in TEST_ARGS)
for targ in "${TEST_ARGS[@]}"; do
if [ "$targ" = "-h" ] || [ "$targ" = "--help" ]; then
SHOW_HELP="-h"
break
fi
done
if [ -n "$SHOW_HELP" ]; then
echo "Usage: ./ps-empire test [pytest-args...]"
echo ""
echo "Run the Empire test suite via pytest."
echo "All arguments after 'test' are passed directly to pytest."
echo ""
echo "Common options:"
echo " -v Verbose output"
echo " --runslow Include slow tests"
echo " --nodocker Skip tests that fail in Docker"
echo " --cov=empire/server Run with coverage"
echo " -k EXPRESSION Only run tests matching expression"
echo " path/to/test.py Run a specific test file"
echo " path::test_name Run a specific test"
echo ""
echo "Examples:"
echo " ./ps-empire test"
echo " ./ps-empire test -v --runslow"
echo " ./ps-empire test empire/test/test_agent_api.py -v"
echo " ./ps-empire test --cov=empire/server --runslow"
exit 0
fi
if ! command -v poetry &> /dev/null; then
echo -e "\x1b[1;31m[!] poetry is not installed. Run './ps-empire install' or see https://python-poetry.org/docs/#installation\x1b[0m"
exit 1
fi
poetry run pytest "${TEST_ARGS[@]}"
rc=$?
if [ $rc -ne 0 ] && [ $rc -ne 1 ] && [ $rc -ne 2 ] && [ $rc -ne 5 ]; then
# Pytest codes 0=OK, 1=failures, 2=interrupted, 5=no tests. Codes 3/4 indicate internal or usage errors.
echo -e "\x1b[1;33m[*] pytest exited with unexpected code $rc. If the virtualenv is broken, try: poetry install\x1b[0m"
fi
exit $rc
fi
if [ "$EUID" -eq 0 ] && [ -z "$FORCE_OPTION" ]; then
echo -e "\x1b[1;31m[!] This script should not be run as root. Use the -f option to force run as root (not recommended).\x1b[0m"
exit 1
fi
if [ $INSTALL -eq 0 ]; then
sudo -E poetry run python empire.py "${EMPIRE_ARGS[@]}"
fi