fleet/server/mdm/apple/mobileconfig/mobileconfig_test.go
Roberto Dip 63a46343b8
allow special characters in enrollment profile org name (#21630)
for #19808

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files)
for more information.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
2024-08-28 15:00:11 -03:00

36 lines
975 B
Go

package mobileconfig
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestXMLEscapeString(t *testing.T) {
tests := []struct {
input string
expected string
}{
// characters that should be escaped
{"hello & world", "hello &amp; world"},
{"this is a <test>", "this is a &lt;test&gt;"},
{"\"quotes\" and 'single quotes'", "&#34;quotes&#34; and &#39;single quotes&#39;"},
{"special chars: \t\n\r", "special chars: &#x9;&#xA;&#xD;"},
// no special characters
{"plain string", "plain string"},
// string that already contains escaped characters
{"already &lt;escaped&gt;", "already &amp;lt;escaped&amp;gt;"},
// empty string
{"", ""},
// multiple special characters
{"A&B<C>D\"'E\tF\nG\r", "A&amp;B&lt;C&gt;D&#34;&#39;E&#x9;F&#xA;G&#xD;"},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
out, err := XMLEscapeString(tt.input)
require.NoError(t, err)
require.Equal(t, tt.expected, out)
})
}
}