From b75c603e6f480ad5faa4f3c1d6d8968c3f666903 Mon Sep 17 00:00:00 2001 From: Matt White <436037+mlw@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:19:33 -0400 Subject: [PATCH] Add tests to ensure EventTypeToString handles all subscriptions --- .../EventProviders/SNTEndpointSecurityAuthorizerTest.mm | 4 ++++ .../EventProviders/SNTEndpointSecurityDeviceManagerTest.mm | 4 ++++ .../SNTEndpointSecurityFileAccessAuthorizerTest.mm | 4 ++++ .../santad/EventProviders/SNTEndpointSecurityRecorderTest.mm | 4 ++++ .../EventProviders/SNTEndpointSecurityTamperResistanceTest.mm | 4 ++++ Source/santad/Metrics.h | 2 ++ 6 files changed, 22 insertions(+) diff --git a/Source/santad/EventProviders/SNTEndpointSecurityAuthorizerTest.mm b/Source/santad/EventProviders/SNTEndpointSecurityAuthorizerTest.mm index b5519c2cc..87d2c3ae6 100644 --- a/Source/santad/EventProviders/SNTEndpointSecurityAuthorizerTest.mm +++ b/Source/santad/EventProviders/SNTEndpointSecurityAuthorizerTest.mm @@ -81,6 +81,10 @@ - (void)testEnable { [authClient enable]; + for (const auto &event : expectedEventSubs) { + XCTAssertNoThrow(santa::santad::EventTypeToString(event)); + } + XCTBubbleMockVerifyAndClearExpectations(mockESApi.get()); } diff --git a/Source/santad/EventProviders/SNTEndpointSecurityDeviceManagerTest.mm b/Source/santad/EventProviders/SNTEndpointSecurityDeviceManagerTest.mm index 483a1e1e0..3a22acd0d 100644 --- a/Source/santad/EventProviders/SNTEndpointSecurityDeviceManagerTest.mm +++ b/Source/santad/EventProviders/SNTEndpointSecurityDeviceManagerTest.mm @@ -507,6 +507,10 @@ - (void)testEnable { [deviceClient enable]; + for (const auto &event : expectedEventSubs) { + XCTAssertNoThrow(santa::santad::EventTypeToString(event)); + } + XCTBubbleMockVerifyAndClearExpectations(mockESApi.get()); } diff --git a/Source/santad/EventProviders/SNTEndpointSecurityFileAccessAuthorizerTest.mm b/Source/santad/EventProviders/SNTEndpointSecurityFileAccessAuthorizerTest.mm index 78f5c208f..ba6547a62 100644 --- a/Source/santad/EventProviders/SNTEndpointSecurityFileAccessAuthorizerTest.mm +++ b/Source/santad/EventProviders/SNTEndpointSecurityFileAccessAuthorizerTest.mm @@ -753,6 +753,10 @@ - (void)testEnable { [fileAccessClient enable]; + for (const auto &event : expectedEventSubs) { + XCTAssertNoThrow(santa::santad::EventTypeToString(event)); + } + XCTBubbleMockVerifyAndClearExpectations(mockESApi.get()); } diff --git a/Source/santad/EventProviders/SNTEndpointSecurityRecorderTest.mm b/Source/santad/EventProviders/SNTEndpointSecurityRecorderTest.mm index 9b202118d..ca985da96 100644 --- a/Source/santad/EventProviders/SNTEndpointSecurityRecorderTest.mm +++ b/Source/santad/EventProviders/SNTEndpointSecurityRecorderTest.mm @@ -100,6 +100,10 @@ - (void)testEnable { [recorderClient enable]; + for (const auto &event : expectedEventSubs) { + XCTAssertNoThrow(santa::santad::EventTypeToString(event)); + } + XCTBubbleMockVerifyAndClearExpectations(mockESApi.get()); } diff --git a/Source/santad/EventProviders/SNTEndpointSecurityTamperResistanceTest.mm b/Source/santad/EventProviders/SNTEndpointSecurityTamperResistanceTest.mm index bd6187fa2..c5154e4d2 100644 --- a/Source/santad/EventProviders/SNTEndpointSecurityTamperResistanceTest.mm +++ b/Source/santad/EventProviders/SNTEndpointSecurityTamperResistanceTest.mm @@ -80,6 +80,10 @@ - (void)testEnable { [mockTamperClient enable]; + for (const auto &event : expectedEventSubs) { + XCTAssertNoThrow(santa::santad::EventTypeToString(event)); + } + XCTBubbleMockVerifyAndClearExpectations(mockESApi.get()); [mockTamperClient stopMocking]; } diff --git a/Source/santad/Metrics.h b/Source/santad/Metrics.h index 3f8e2b0a0..475667000 100644 --- a/Source/santad/Metrics.h +++ b/Source/santad/Metrics.h @@ -62,6 +62,8 @@ using FileAccessEventCountTuple = std::tuple; +NSString *const EventTypeToString(es_event_type_t eventType); + class Metrics : public std::enable_shared_from_this { public: static std::shared_ptr Create(SNTMetricSet *metric_set, uint64_t interval);