mirror of
https://github.com/fleetdm/fleet
synced 2026-04-28 17:07:43 +00:00
#9253 - ~[ ] Changes file added for user-visible changes in `changes/` or `orbit/changes/`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information.~ - ~[ ] Documented any API changes (docs/Using-Fleet/REST-API.md or docs/Contributing/API-for-contributors.md)~ - ~[ ] Documented any permissions changes~ - ~[ ] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements)~ - ~[ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for new osquery data ingestion features.~ - [X] Added/updated tests - [X] Manual QA for all new/changed functionality - For Orbit and Fleet Desktop changes: - [X] Manual QA must be performed in the three main OSs, macOS, Windows and Linux. - ~[ ] Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~ --------- Co-authored-by: Sharon Katz <121527325+sharon-fdm@users.noreply.github.com>
93 lines
2.3 KiB
Go
93 lines
2.3 KiB
Go
//go:build darwin
|
|
// +build darwin
|
|
|
|
package common
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestGetConsoleUidGid(t *testing.T) {
|
|
_, _, err := GetConsoleUidGid()
|
|
if err != nil {
|
|
t.Fatalf(`Err expected to be nil. got %s`, err)
|
|
}
|
|
}
|
|
|
|
func TestGetValFromXMLWithTags(t *testing.T) {
|
|
testXML := `<?xml version="1.0" encoding="UTF-8" ?>
|
|
<rss version="2.0">
|
|
<channel>
|
|
<title>W3Schools Home Page</title>
|
|
<link>https://www.w3schools.com</link>
|
|
<description>Free web building tutorials</description>
|
|
<parentTag>
|
|
<tag>tagValue</tag>
|
|
<integer>11</integer>
|
|
</parentTag>
|
|
<item>
|
|
<title>RSS Tutorial</title>
|
|
<link>https://www.w3schools.com/xml/xml_rss.asp</link>
|
|
<description>New RSS tutorial on W3Schools</description>
|
|
</item>
|
|
<item>
|
|
<title>XML Tutorial</title>
|
|
<link>https://www.w3schools.com/xml</link>
|
|
<description>New XML tutorial on W3Schools</description>
|
|
</item>
|
|
</channel>
|
|
</rss>`
|
|
|
|
val, err := GetValFromXMLWithTags(testXML, "parentTag", "tag", "tagValue", "integer")
|
|
if err != nil {
|
|
t.Fatalf(`Err expected to be nil. got %s`, err)
|
|
}
|
|
if val != "11" {
|
|
t.Fatalf(`Val expected "11", got %s`, val)
|
|
}
|
|
}
|
|
|
|
func TestGetValFromXMLWithTagsBadXML(t *testing.T) {
|
|
testXML := `<?xml veools.com</link>
|
|
<description>Free web build
|
|
<integer>11</integer>
|
|
</parentTag>
|
|
<item>://www.w3s_rss.asp</lin
|
|
<description>New RSS tutorial on W3Schools</description>
|
|
</itess>`
|
|
|
|
_, err := GetValFromXMLWithTags(testXML, "parentTag", "tag", "tagValue", "integer")
|
|
if err == nil {
|
|
t.Fatalf("Err expected. Got nil")
|
|
}
|
|
}
|
|
|
|
func TestGetValFromXMLWithTagsNoTag(t *testing.T) {
|
|
testXML := `<?xml version="1.0" encoding="UTF-8" ?>
|
|
<rss version="2.0">
|
|
<channel>
|
|
<title>W3Schools Home Page</title>
|
|
<link>https://www.w3schools.com</link>
|
|
<description>Free web building tutorials</description>
|
|
<parentTag>
|
|
<tag>tagValue</tag>
|
|
<integer>11</integer>
|
|
</parentTag>
|
|
<item>
|
|
<title>RSS Tutorial</title>
|
|
<link>https://www.w3schools.com/xml/xml_rss.asp</link>
|
|
<description>New RSS tutorial on W3Schools</description>
|
|
</item>
|
|
<item>
|
|
<title>XML Tutorial</title>
|
|
<link>https://www.w3schools.com/xml</link>
|
|
<description>New XML tutorial on W3Schools</description>
|
|
</item>
|
|
</channel>
|
|
</rss>`
|
|
|
|
_, err := GetValFromXMLWithTags(testXML, "badTag", "BadTag", "BadValue", "integer")
|
|
if err == nil {
|
|
t.Fatalf("Err expected. Got nil")
|
|
}
|
|
}
|