Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 52 additions & 8 deletions apparmor/apparmor_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,6 @@ func TestGenerateDefault(t *testing.T) {
},
skipParse: true, // Skip parsing because we use non-existing includes.
},
{
name: "with-special-characters",
data: profileData{
name: `foo"bar,*?[ab]{c,d}^\baz`,
daemonProfile: `daemon"bar,*?[ab]{c,d}^\baz`,
},
},
}

for _, tc := range tests {
Expand Down Expand Up @@ -316,14 +309,65 @@ func TestGenerateDefault(t *testing.T) {
}
}

func TestGenerateSpecialCharacters(t *testing.T) {
var profile strings.Builder
data := profileData{
name: `foo"bar,*?[ab]{c,d}^\baz`,
daemonProfile: `daemon"bar,*?[ab]{c,d}^\baz`,
}
if err := generate(&data, &profile, func(string) bool { return false }); err != nil {
t.Fatal(err)
}

const (
wantDeclaration = `"foo\"bar,*?[ab]{c,d}^\baz"`
wantContainerPeer = `"foo\"bar\,\*\?\[ab\]\{c\,d\}\^\\baz"`
wantDaemonPeer = `"daemon\"bar\,\*\?\[ab\]\{c\,d\}\^\\baz"`
)
tests := []struct {
name string
want string
}{
{
name: "profile declaration",
want: "profile " + wantDeclaration + " ",
},
{
name: "daemon signal peer",
want: "signal (receive) peer=" + wantDaemonPeer + ",",
},
{
name: "container signal peer",
want: "signal (send,receive) peer=" + wantContainerPeer + ",",
},
{
name: "container ptrace peer",
want: "ptrace (trace,tracedby,read,readby) peer=" + wantContainerPeer + ",",
},
}

got := profile.String()
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if !strings.Contains(got, tc.want) {
Comment on lines +349 to +352

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But isn't this weaker than a .golden file?

t.Errorf("generated profile is missing %q", tc.want)
}
})
}
}

func TestGenerateProfileName(t *testing.T) {
if _, err := exec.LookPath("apparmor_parser"); err != nil {
t.Skipf("apparmor_parser not available: %v", err)
}

const name = `foo"bar,*?[ab]{c,d}^\baz`
var profile strings.Builder
if err := generate(&profileData{name: name}, &profile, func(string) bool { return false }); err != nil {
data := profileData{
name: name,
daemonProfile: `daemon"bar,*?[ab]{c,d}^\baz`,
}
if err := generate(&data, &profile, func(string) bool { return false }); err != nil {
t.Fatal(err)
}

Expand Down
61 changes: 0 additions & 61 deletions apparmor/testdata/with-special-characters.golden

This file was deleted.

Loading