From 0cdd0e9b2b82d2c2bb8878c120370e34cb6fac3a Mon Sep 17 00:00:00 2001 From: zack olson Date: Wed, 14 Aug 2024 10:17:47 -0400 Subject: [PATCH] add windows serviceName tests --- ee/debug/shipper/shipper.go | 1 + pkg/launcher/pkg_utils_windows_test.go | 49 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 pkg/launcher/pkg_utils_windows_test.go diff --git a/ee/debug/shipper/shipper.go b/ee/debug/shipper/shipper.go index 41e1ef9836..0db33efc52 100644 --- a/ee/debug/shipper/shipper.go +++ b/ee/debug/shipper/shipper.go @@ -268,6 +268,7 @@ func enrollSecret(k types.Knapsack) string { return k.EnrollSecret() } + // TODO this will need to respect the identifier when determining the secret file location for dual-launcher installations b, err := os.ReadFile(launcher.DefaultPath(launcher.SecretFile)) if err != nil { return "" diff --git a/pkg/launcher/pkg_utils_windows_test.go b/pkg/launcher/pkg_utils_windows_test.go new file mode 100644 index 0000000000..63866489f4 --- /dev/null +++ b/pkg/launcher/pkg_utils_windows_test.go @@ -0,0 +1,49 @@ +//go:build windows +// +build windows + +package launcher + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func Test_ServiceName(t *testing.T) { + t.Parallel() + + for _, tt := range []struct { + testCaseName string + identifier string + expectedServiceName string + }{ + { + testCaseName: "empty identifier expecting default service name", + identifier: " ", + expectedServiceName: "LauncherKolideK2Svc", + }, + { + testCaseName: "default identifier expecting default service name", + identifier: "kolide-k2", + expectedServiceName: "LauncherKolideK2Svc", + }, + { + testCaseName: "preprod identifier expecting preprod service name", + identifier: "kolide-preprod-k2", + expectedServiceName: "LauncherKolidePreprodK2Svc", + }, + { + testCaseName: "mangled identifier expecting default service name", + identifier: "kolide-!@_k2", + expectedServiceName: "LauncherKolideK2Svc", + }, + } { + tt := tt + t.Run(tt.testCaseName, func(t *testing.T) { + t.Parallel() + + serviceName := ServiceName(tt.identifier) + require.Equal(t, tt.expectedServiceName, serviceName, "expected sanitized service name value to match") + }) + } +}