188 lines
5.1 KiB
Go
188 lines
5.1 KiB
Go
package app
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestEveryPageUsesStandaloneLogoMarkAsFavicon(t *testing.T) {
|
|
t.Parallel()
|
|
for _, file := range []string{
|
|
"templates/audit.html",
|
|
"templates/hosts.html",
|
|
"templates/login.html",
|
|
"templates/packages.html",
|
|
"templates/portal.html",
|
|
} {
|
|
content, err := webFiles.ReadFile(file)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(
|
|
string(content),
|
|
`<link rel="icon" type="image/svg+xml" href="/static/ta-mark.svg">`,
|
|
) {
|
|
t.Errorf("%s does not reference the standalone logo favicon", file)
|
|
}
|
|
}
|
|
mark, err := webFiles.ReadFile("static/ta-mark.svg")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if bytes.Count(mark, []byte("<polygon")) != 4 {
|
|
t.Fatal("standalone logo favicon does not contain the four original mark polygons")
|
|
}
|
|
}
|
|
|
|
func TestPortalTemplateExecutes(t *testing.T) {
|
|
t.Parallel()
|
|
templates, err := parseTemplates(time.UTC)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err = templates.ExecuteTemplate(io.Discard, "portal.html", pageData{
|
|
Title: "Test",
|
|
Technician: &technician{DisplayName: "Technician"},
|
|
Packages: []packageRecord{{
|
|
ID: 1,
|
|
Slug: "sentinelone-linux",
|
|
DisplayName: "SentinelOne Linux Agent",
|
|
PackageVersion: "26.1.1.31",
|
|
Enabled: true,
|
|
}},
|
|
Actions: []actionRecord{{
|
|
Slug: "install-rmm",
|
|
DisplayName: "Install RMM",
|
|
Enabled: true,
|
|
}},
|
|
Authorizations: []authorizationRecord{{
|
|
ID: 1,
|
|
CreatedBy: "taiadmin",
|
|
ExpiresAt: time.Now().Add(time.Hour),
|
|
Packages: "SentinelOne Linux Agent",
|
|
Actions: "Install RMM",
|
|
PackageIDs: map[uint64]bool{1: true},
|
|
ActionSlugs: map[string]bool{"install-rmm": true},
|
|
}},
|
|
DefaultDays: 7,
|
|
MaxHostLimit: 25,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestPackageAndAuditTemplatesExecute(t *testing.T) {
|
|
t.Parallel()
|
|
templates, err := parseTemplates(time.UTC)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
data := pageData{
|
|
Title: "Test",
|
|
Technician: &technician{DisplayName: "Technician"},
|
|
CSRFToken: "csrf",
|
|
CurrentView: "packages",
|
|
Packages: []packageRecord{{
|
|
ID: 1,
|
|
Slug: "sentinelone-linux",
|
|
DisplayName: "SentinelOne Linux Agent",
|
|
PackageVersion: "26.1.1.31",
|
|
Enabled: true,
|
|
}},
|
|
}
|
|
var packagesOutput bytes.Buffer
|
|
if err := templates.ExecuteTemplate(&packagesOutput, "packages.html", data); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(packagesOutput.String(), "Save status only") ||
|
|
!strings.Contains(packagesOutput.String(), `formaction="/portal/packages/status"`) {
|
|
t.Fatal("packages page does not include the status-only update control")
|
|
}
|
|
|
|
data.CurrentView = "audit"
|
|
data.AuditFilters.TimeRange = "30d"
|
|
data.AuditEventTypes = []string{"package_downloaded"}
|
|
data.AuditEvents = []auditRecord{{
|
|
EventType: "package_downloaded",
|
|
CustomerLabel: "Acme cluster refresh",
|
|
Hostname: "pve01",
|
|
SourceIP: "203.0.113.10",
|
|
CreatedAt: time.Now(),
|
|
}}
|
|
var auditOutput bytes.Buffer
|
|
if err := templates.ExecuteTemplate(&auditOutput, "audit.html", data); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(auditOutput.String(), "Failed code attempts") ||
|
|
!strings.Contains(auditOutput.String(), "audit_event=code_exchange_failed") {
|
|
t.Fatal("audit page does not include the failed-code-attempt shortcut")
|
|
}
|
|
if !strings.Contains(auditOutput.String(), "Download complete Excel") ||
|
|
!strings.Contains(auditOutput.String(), `/portal/audit/export?audit_range=all`) {
|
|
t.Fatal("audit page does not include the complete Excel export")
|
|
}
|
|
}
|
|
|
|
func TestFleetTemplateExecutes(t *testing.T) {
|
|
t.Parallel()
|
|
templates, err := parseTemplates(time.UTC)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err = templates.ExecuteTemplate(io.Discard, "hosts.html", pageData{
|
|
Title: "Test",
|
|
Technician: &technician{DisplayName: "Technician"},
|
|
CurrentView: "hosts",
|
|
FleetHosts: []fleetHostRecord{{
|
|
InstallationID: "123e4567-e89b-42d3-a456-426614174000",
|
|
Hostname: "pve01",
|
|
FirstSeenAt: time.Now(),
|
|
LastSeenAt: time.Now(),
|
|
LastEvent: "run_completed",
|
|
LastResult: "success",
|
|
ProxMenuVersion: "2026.7.26-7",
|
|
PVEVersion: "pve-manager/9.0.3",
|
|
OSVersion: "Debian GNU/Linux 13 (trixie)",
|
|
Architecture: "amd64",
|
|
}},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestAuditTemplateUsesConfiguredTimeZone(t *testing.T) {
|
|
t.Parallel()
|
|
location, err := time.LoadLocation("America/Chicago")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
templates, err := parseTemplates(location)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var output bytes.Buffer
|
|
err = templates.ExecuteTemplate(&output, "audit.html", pageData{
|
|
Title: "Test",
|
|
Technician: &technician{DisplayName: "Technician"},
|
|
CurrentView: "audit",
|
|
AuditFilters: auditFilters{
|
|
TimeRange: "30d",
|
|
},
|
|
AuditEvents: []auditRecord{{
|
|
EventType: "code_exchanged",
|
|
CreatedAt: time.Date(2026, time.January, 15, 12, 0, 0, 0, time.UTC),
|
|
}},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(output.String(), "Jan 15, 2026 6:00 AM CST") {
|
|
t.Fatalf("audit timestamp was not rendered in America/Chicago: %s", output.String())
|
|
}
|
|
}
|