mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2025-02-22 09:55:36 +01:00
refractor(aa): update test structure.
This commit is contained in:
parent
2923df2a73
commit
a0b5362589
2 changed files with 88 additions and 94 deletions
|
@ -28,7 +28,7 @@ func readprofile(path string) string {
|
||||||
return res[:len(res)-1]
|
return res[:len(res)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAppArmorProfile_String(t *testing.T) {
|
func TestAppArmorProfileFile_String(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
f *AppArmorProfileFile
|
f *AppArmorProfileFile
|
||||||
|
@ -124,97 +124,7 @@ func TestAppArmorProfile_String(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAppArmorProfile_AddRule(t *testing.T) {
|
func TestAppArmorProfileFile_Sort(t *testing.T) {
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
log map[string]string
|
|
||||||
want *AppArmorProfileFile
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "capability",
|
|
||||||
log: capability1Log,
|
|
||||||
want: &AppArmorProfileFile{
|
|
||||||
Profiles: []*Profile{{
|
|
||||||
Rules: []Rule{capability1},
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "network",
|
|
||||||
log: network1Log,
|
|
||||||
want: &AppArmorProfileFile{
|
|
||||||
Profiles: []*Profile{{
|
|
||||||
Rules: []Rule{network1},
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "mount",
|
|
||||||
log: mount2Log,
|
|
||||||
want: &AppArmorProfileFile{
|
|
||||||
Profiles: []*Profile{{
|
|
||||||
Rules: []Rule{mount2},
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "signal",
|
|
||||||
log: signal1Log,
|
|
||||||
want: &AppArmorProfileFile{
|
|
||||||
Profiles: []*Profile{{
|
|
||||||
Rules: []Rule{signal1},
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "ptrace",
|
|
||||||
log: ptrace2Log,
|
|
||||||
want: &AppArmorProfileFile{
|
|
||||||
Profiles: []*Profile{{
|
|
||||||
Rules: []Rule{ptrace2},
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "unix",
|
|
||||||
log: unix1Log,
|
|
||||||
want: &AppArmorProfileFile{
|
|
||||||
Profiles: []*Profile{{
|
|
||||||
Rules: []Rule{unix1},
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "dbus",
|
|
||||||
log: dbus2Log,
|
|
||||||
want: &AppArmorProfileFile{
|
|
||||||
Profiles: []*Profile{{
|
|
||||||
Rules: []Rule{dbus2},
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "file",
|
|
||||||
log: file2Log,
|
|
||||||
want: &AppArmorProfileFile{
|
|
||||||
Profiles: []*Profile{{
|
|
||||||
Rules: []Rule{file2},
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
got := NewAppArmorProfile()
|
|
||||||
got.AddRule(tt.log)
|
|
||||||
if !reflect.DeepEqual(got, tt.want) {
|
|
||||||
t.Errorf("AppArmorProfile.AddRule() = %v, want %v", got, tt.want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAppArmorProfile_Sort(t *testing.T) {
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
origin *AppArmorProfileFile
|
origin *AppArmorProfileFile
|
||||||
|
@ -251,7 +161,7 @@ func TestAppArmorProfile_Sort(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAppArmorProfile_MergeRules(t *testing.T) {
|
func TestAppArmorProfileFile_MergeRules(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
origin *AppArmorProfileFile
|
origin *AppArmorProfileFile
|
||||||
|
@ -282,7 +192,7 @@ func TestAppArmorProfile_MergeRules(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAppArmorProfile_Integration(t *testing.T) {
|
func TestAppArmorProfileFile_Integration(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
f *AppArmorProfileFile
|
f *AppArmorProfileFile
|
||||||
|
|
84
pkg/aa/profile_test.go
Normal file
84
pkg/aa/profile_test.go
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
// apparmor.d - Full set of apparmor profiles
|
||||||
|
// Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io>
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-only
|
||||||
|
|
||||||
|
package aa
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestProfile_AddRule(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
log map[string]string
|
||||||
|
want *Profile
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "capability",
|
||||||
|
log: capability1Log,
|
||||||
|
want: &Profile{
|
||||||
|
Rules: Rules{capability1},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "network",
|
||||||
|
log: network1Log,
|
||||||
|
want: &Profile{
|
||||||
|
Rules: Rules{network1},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "mount",
|
||||||
|
log: mount2Log,
|
||||||
|
want: &Profile{
|
||||||
|
Rules: Rules{mount2},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "signal",
|
||||||
|
log: signal1Log,
|
||||||
|
want: &Profile{
|
||||||
|
Rules: Rules{signal1},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "ptrace",
|
||||||
|
log: ptrace2Log,
|
||||||
|
want: &Profile{
|
||||||
|
Rules: Rules{ptrace2},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "unix",
|
||||||
|
log: unix1Log,
|
||||||
|
want: &Profile{
|
||||||
|
Rules: Rules{unix1},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "dbus",
|
||||||
|
log: dbus2Log,
|
||||||
|
want: &Profile{
|
||||||
|
Rules: Rules{dbus2},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "file",
|
||||||
|
log: file2Log,
|
||||||
|
want: &Profile{
|
||||||
|
Rules: Rules{file2},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got := &Profile{}
|
||||||
|
got.AddRule(tt.log)
|
||||||
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("Profile.AddRule() = |%v|, want |%v|", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue