2021-12-05 00:53:32 +01:00
|
|
|
// aa-log - Review AppArmor generated messages
|
|
|
|
// Copyright (C) 2021 Alexandre Pujol <alexandre@pujol.io>
|
|
|
|
// 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,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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-08-17 20:15:21 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|