From d2c1aa72ff47c24be0a745ac787493afc9553c04 Mon Sep 17 00:00:00 2001 From: Alexandre Pujol Date: Wed, 19 Apr 2023 21:48:53 +0100 Subject: [PATCH] fix(build): ensure attachment nesting return value even on non valid string. --- pkg/aa/profile.go | 6 +++++- pkg/aa/profile_test.go | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/aa/profile.go b/pkg/aa/profile.go index 69f3e844..4797a921 100644 --- a/pkg/aa/profile.go +++ b/pkg/aa/profile.go @@ -100,7 +100,11 @@ func (p *AppArmorProfile) NestAttachments() string { } else { res := []string{} for _, attachment := range p.Attachments { - res = append(res, attachment[1:]) + if strings.HasPrefix(attachment, "/") { + res = append(res, attachment[1:]) + } else { + res = append(res, attachment) + } } return "/{" + strings.Join(res, ",") + "}" } diff --git a/pkg/aa/profile_test.go b/pkg/aa/profile_test.go index 7524bb52..1f083a2d 100644 --- a/pkg/aa/profile_test.go +++ b/pkg/aa/profile_test.go @@ -185,6 +185,21 @@ func TestAppArmorProfile_NestAttachments(t *testing.T) { }, want: "/{{usr/,}libexec/geoclue,{usr/,}libexec/geoclue-2.0/demos/agent}", }, + { + name: "null", + Attachments: []string{}, + want: "", + }, + { + name: "empty", + Attachments: []string{""}, + want: "", + }, + { + name: "not valid aare", + Attachments: []string{"/file", "relative"}, + want: "/{file,relative}", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {