Skip to content

Commit 9ced7ed

Browse files
authored
fix(ci): add tests and arguments (#5)
1 parent 289b404 commit 9ced7ed

File tree

3 files changed

+325
-42
lines changed

3 files changed

+325
-42
lines changed

.github/workflows/build_test_ci.yml

+49-13
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,78 @@ jobs:
2323
run: gcc -o suricata-notify suricata-notify.c -ljansson
2424

2525
- name: Upload Build Artifact
26-
uses: actions/upload-artifact@v3
26+
uses: actions/upload-artifact@v4
2727
with:
2828
name: suricata-notify
2929
path: suricata-notify
3030
retention-days: 30
3131

32-
download:
32+
test:
3333
runs-on: ubuntu-latest
3434
needs: build
3535

3636
steps:
3737
- name: Download Artifact
38-
uses: actions/download-artifact@v3
38+
uses: actions/download-artifact@v4
3939
with:
4040
name: suricata-notify
4141
path: ./
42+
4243
- name: Install Dependencies
4344
run: |
44-
sudo apt-get update
45-
sudo apt-get install -y build-essential xvfb libnotify-bin strace
46-
47-
- name: List Downloaded Files
48-
run: ls -la
45+
sudo apt-get update
46+
# sudo apt-get install -y xvfb strace libnotify-bin dbus-x11
47+
sudo apt-get install -y xvfb xfce4-notifyd x11-apps x11-utils strace libnotify-bin dbus-x11
4948
5049
- name: Make Executable
5150
run: chmod +x suricata-notify
5251

52+
- name: Show Help
53+
run: ./suricata-notify --help
54+
5355
- name: Create Test Data
54-
run: echo '[{"event_type":"alert","timestamp":"2023-08-02T00:05:06.384656+0200","alert":{"signature":"Test Signature 1","category":"Test Category 1"}},{"event_type":"alert","timestamp":"2023-08-02T00:06:00.000000+0200","alert":{"signature":"Test Signature 2","category":"Test Category 2"}},{"event_type":"alert","timestamp":"2023-08-02T00:07:00.000000+0200","alert":{"signature":"Test Signature 3","category":"Test Category 3"}}]' > eve.json
56+
run: |
57+
current_time=$(date --utc --date="-33 seconds" +"%Y-%m-%dT%H:%M:%S.%6NZ")
58+
echo "Current Time: $current_time"
59+
# Create the JSON data with the timestamp embedded
60+
json_data='{"timestamp":"'"$current_time"'","flow_id":1234567890123456,"pcap_cnt":150,"event_type":"alert","src_ip":"192.168.1.100","src_port":8080,"dest_ip":"10.0.0.5","dest_port":80,"proto":"TCP","pkt_src":"wire/pcap","ether":{"src_mac":"00:11:22:33:44:55","dest_mac":"66:77:88:99:AA:BB"},"tx_id":2,"alert":{"action":"allowed","gid":1,"signature_id":1000001,"rev":1,"signature":"Test Signature Example","category":"Test Category","severity":2,"metadata":{"affected_product":["Linux_Server_64_Bit"],"attack_target":["Server_Endpoint"],"created_at":["2024_08_20"],"deployment":["Perimeter"],"former_category":["TEST_RESPONSE"],"signature_severity":["Minor"],"updated_at":["2024_08_20"]}},"http":{"hostname":"example.com","http_port":8080,"url":"/test","http_content_type":"application/json","http_method":"GET","protocol":"HTTP/1.1","status":200,"length":1024},"files":[{"filename":"/test","gaps":false,"state":"CLOSED","stored":false,"size":1024,"tx_id":2}],"app_proto":"http","direction":"to_server","flow":{"pkts_toserver":10,"pkts_toclient":8,"bytes_toserver":2048,"bytes_toclient":4096,"start":"2024-08-20T15:29:50.000000+0000","src_ip":"10.0.0.5","dest_ip":"192.168.1.100","src_port":80,"dest_port":8080}}'
61+
echo "$json_data"
62+
echo "$json_data" > eve.json
63+
echo "Test data written to eve.json"
5564
56-
- name: Prepare Virtual Display
57-
run: xvfb-run -a -s "-screen 0 1024x768x24" sh -c "strace -o strace.log ./suricata-notify eve.json"
65+
- name: Prepare Virtual Display and Test Notifications
66+
run: |
67+
# Run the program in a virtual display and capture strace logs
68+
# export DISPLAY=:99 && xvfb-run -a -s "-screen 0 1024x768x24" sh -c '
69+
export DISPLAY=:0 && xvfb-run -a -s "-screen 0 1024x768x24" sh -c '
70+
echo "Starting dbus-session...";
71+
eval $(dbus-launch --sh-syntax --exit-with-session);
72+
echo "Running suricata-notify with strace..."
73+
strace -f -o /tmp/suricata-notify-strace.log ./suricata-notify -v -w 60 -z 0 -e eve.json
74+
'
5875
5976
- name: Upload Strace Log
60-
uses: actions/upload-artifact@v3
77+
uses: actions/upload-artifact@v4
6178
with:
6279
name: strace-log
63-
path: strace.log
80+
path: /tmp/suricata-notify-strace.log
6481
retention-days: 30
82+
83+
- name: Check Strace Log
84+
run: |
85+
# Check for specific output in the strace log to determine success
86+
87+
# Check if the log contains the specific message we expect to send with notify-send
88+
if grep -q "Test Category" /tmp/suricata-notify-strace.log; then
89+
# Check if notify-send exited successfully
90+
if grep -q "notify-send failed" /tmp/suricata-notify-strace.log; then
91+
echo "Notification test failed due to notify-send error"
92+
exit 1
93+
else
94+
echo "Notification test passed"
95+
exit 0
96+
fi
97+
else
98+
echo "Notification test failed: Message not found in strace log"
99+
exit 1
100+
fi

.vscode/c_cpp_properties.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Mac",
5+
"includePath": [
6+
"${workspaceFolder}/**"
7+
],
8+
"defines": [],
9+
"macFrameworkPath": [
10+
"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/Frameworks"
11+
],
12+
"compilerPath": "/usr/bin/clang",
13+
"cStandard": "c17",
14+
"cppStandard": "c++17",
15+
"intelliSenseMode": "macos-clang-arm64"
16+
}
17+
],
18+
"version": 4
19+
}

0 commit comments

Comments
 (0)