fix(build): ensure attachment nesting return value even on non valid string.

This commit is contained in:
Alexandre Pujol 2023-04-19 21:48:53 +01:00
parent 991d692a0d
commit d2c1aa72ff
No known key found for this signature in database
GPG Key ID: C5469996F0DF68EC
2 changed files with 20 additions and 1 deletions

View File

@ -100,7 +100,11 @@ func (p *AppArmorProfile) NestAttachments() string {
} else { } else {
res := []string{} res := []string{}
for _, attachment := range p.Attachments { for _, attachment := range p.Attachments {
if strings.HasPrefix(attachment, "/") {
res = append(res, attachment[1:]) res = append(res, attachment[1:])
} else {
res = append(res, attachment)
}
} }
return "/{" + strings.Join(res, ",") + "}" return "/{" + strings.Join(res, ",") + "}"
} }

View File

@ -185,6 +185,21 @@ func TestAppArmorProfile_NestAttachments(t *testing.T) {
}, },
want: "/{{usr/,}libexec/geoclue,{usr/,}libexec/geoclue-2.0/demos/agent}", 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 { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {