2021-12-05 00:53:32 +01:00
|
|
|
// aa-log - Review AppArmor generated messages
|
2024-02-07 00:16:21 +01:00
|
|
|
// Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
|
2021-12-05 00:53:32 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2021-12-12 13:35:08 +01:00
|
|
|
func Test_app(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
2022-10-06 22:11:35 +02:00
|
|
|
logger string
|
2021-12-12 13:35:08 +01:00
|
|
|
path string
|
2022-02-10 22:30:51 +01:00
|
|
|
profile string
|
2023-08-17 20:15:21 +02:00
|
|
|
rules bool
|
2021-12-12 13:35:08 +01:00
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
2022-08-19 20:05:46 +02:00
|
|
|
name: "Test audit.log",
|
2022-10-06 22:11:35 +02:00
|
|
|
logger: "auditd",
|
2021-12-12 13:35:08 +01:00
|
|
|
path: "../../tests/audit.log",
|
2022-02-10 22:30:51 +01:00
|
|
|
profile: "",
|
2023-08-17 20:15:21 +02:00
|
|
|
rules: false,
|
2022-08-19 20:05:46 +02:00
|
|
|
wantErr: false,
|
|
|
|
},
|
2023-08-18 00:14:11 +02:00
|
|
|
{
|
|
|
|
name: "Test audit.log to rules",
|
|
|
|
logger: "auditd",
|
|
|
|
path: "../../tests/audit.log",
|
|
|
|
profile: "",
|
2023-09-01 20:26:52 +02:00
|
|
|
rules: true,
|
2023-08-18 00:14:11 +02:00
|
|
|
wantErr: false,
|
|
|
|
},
|
2022-08-19 20:05:46 +02:00
|
|
|
{
|
|
|
|
name: "Test Dbus Session",
|
2022-10-06 22:11:35 +02:00
|
|
|
logger: "systemd",
|
2022-08-19 20:05:46 +02:00
|
|
|
path: "../../tests/systemd.log",
|
|
|
|
profile: "",
|
2023-08-17 20:15:21 +02:00
|
|
|
rules: false,
|
2021-12-12 13:35:08 +01:00
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "No logfile",
|
2022-10-06 22:11:35 +02:00
|
|
|
logger: "auditd",
|
2021-12-12 13:35:08 +01:00
|
|
|
path: "../../tests/log",
|
2022-02-10 22:30:51 +01:00
|
|
|
profile: "",
|
2023-08-17 20:15:21 +02:00
|
|
|
rules: false,
|
2022-10-06 22:11:35 +02:00
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Logger not supported",
|
|
|
|
logger: "raw",
|
|
|
|
path: "../../tests/audit.log",
|
|
|
|
profile: "",
|
2023-08-17 20:15:21 +02:00
|
|
|
rules: false,
|
2021-12-12 13:35:08 +01:00
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2023-09-01 20:26:52 +02:00
|
|
|
rules = tt.rules
|
|
|
|
if err := aaLog(tt.logger, tt.path, tt.profile); (err != nil) != tt.wantErr {
|
2021-12-12 13:35:08 +01:00
|
|
|
t.Errorf("aaLog() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|