2023-04-17 00:31:05 +02:00
|
|
|
// apparmor.d - Full set of apparmor profiles
|
2024-02-07 00:16:21 +01:00
|
|
|
// Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
|
2023-04-17 00:31:05 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
|
|
package logs
|
|
|
|
|
|
|
|
import (
|
2024-05-30 21:10:45 +02:00
|
|
|
"path/filepath"
|
2023-04-17 00:31:05 +02:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2024-05-30 21:10:45 +02:00
|
|
|
var (
|
|
|
|
testdata = "../../tests/testdata/logs"
|
|
|
|
)
|
|
|
|
|
2023-04-17 00:31:05 +02:00
|
|
|
func TestGetJournalctlLogs(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
path string
|
|
|
|
useFile bool
|
|
|
|
want AppArmorLogs
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "gsd-xsettings",
|
|
|
|
useFile: true,
|
2024-05-30 21:10:45 +02:00
|
|
|
path: filepath.Join(testdata, "systemd.log"),
|
2023-04-17 00:31:05 +02:00
|
|
|
want: AppArmorLogs{
|
|
|
|
{
|
|
|
|
"apparmor": "ALLOWED",
|
|
|
|
"label": "gsd-xsettings",
|
|
|
|
"operation": "dbus_method_call",
|
2023-08-17 20:12:02 +02:00
|
|
|
"name": ":*",
|
2023-04-17 00:31:05 +02:00
|
|
|
"mask": "receive",
|
|
|
|
"bus": "session",
|
|
|
|
"path": "/org/gtk/Settings",
|
|
|
|
"interface": "org.freedesktop.DBus.Properties",
|
|
|
|
"member": "GetAll",
|
|
|
|
"peer_label": "gnome-extension-ding",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "journalctl",
|
|
|
|
useFile: false,
|
|
|
|
path: "",
|
|
|
|
want: AppArmorLogs{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
reader, _ := GetJournalctlLogs(tt.path, tt.useFile)
|
|
|
|
if got := NewApparmorLogs(reader, tt.name); !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("NewApparmorLogs() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-01 20:26:52 +02:00
|
|
|
func TestSelectLogFile(t *testing.T) {
|
2023-04-17 00:31:05 +02:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
path string
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Get audit.log",
|
2024-05-30 21:10:45 +02:00
|
|
|
path: filepath.Join(testdata, "audit.log"),
|
|
|
|
want: filepath.Join(testdata, "audit.log"),
|
2023-04-17 00:31:05 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Get /var/log/audit/audit.log.1",
|
|
|
|
path: "1",
|
|
|
|
want: "/var/log/audit/audit.log.1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Get default log file",
|
|
|
|
path: "",
|
|
|
|
want: "/var/log/audit/audit.log",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2023-09-01 20:26:52 +02:00
|
|
|
if got := SelectLogFile(tt.path); got != tt.want {
|
2023-09-24 20:50:15 +02:00
|
|
|
t.Errorf("SelectLogFile() = %v, want %v", got, tt.want)
|
2023-04-17 00:31:05 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|