From 2fe3711a3219a973cfa64958555c6ad7a685ed84 Mon Sep 17 00:00:00 2001 From: Russell Hancox Date: Fri, 5 Nov 2021 17:28:21 -0400 Subject: [PATCH] Tests: Fix some flaky tests. 1. OCMock objects don't need stopMocking to be called - it's only necessary to call that in cases where the original object behavior must be restored before the end of the test. Otherwise the mock automatically restores during deallocation. 2. SNTMetricRawJSONFormat still used a plain NSDateFormatter and so was applying timezone calculations. In tests we've switched to using NSISO8601DateFormatter but this requires 10.13 and our deployment target is still 10.9 so I've stuck to applying the UTC timezone to the formatter instead. --- Source/santad/SNTExecutionControllerTest.m | 10 ---------- .../Formats/SNTMetricRawJSONFormat.m | 3 ++- .../Writers/SNTMetricHTTPWriterTest.m | 6 ------ 3 files changed, 2 insertions(+), 17 deletions(-) diff --git a/Source/santad/SNTExecutionControllerTest.m b/Source/santad/SNTExecutionControllerTest.m index 86a6f730d..bf376bdea 100644 --- a/Source/santad/SNTExecutionControllerTest.m +++ b/Source/santad/SNTExecutionControllerTest.m @@ -87,16 +87,6 @@ - (santa_vnode_id_t)getVnodeId { return (santa_vnode_id_t){.fsid = 1234, .fileid = 5678}; } -- (void)tearDown { - [self.mockFileInfo stopMocking]; - [self.mockCodesignChecker stopMocking]; - [self.mockDriverManager stopMocking]; - [self.mockRuleDatabase stopMocking]; - [self.mockEventDatabase stopMocking]; - - [super tearDown]; -} - - (void)testBinaryAllowRule { OCMStub([self.mockFileInfo isMachO]).andReturn(YES); OCMStub([self.mockFileInfo SHA256]).andReturn(@"a"); diff --git a/Source/santametricservice/Formats/SNTMetricRawJSONFormat.m b/Source/santametricservice/Formats/SNTMetricRawJSONFormat.m index d1190a313..339ccd38f 100644 --- a/Source/santametricservice/Formats/SNTMetricRawJSONFormat.m +++ b/Source/santametricservice/Formats/SNTMetricRawJSONFormat.m @@ -23,7 +23,8 @@ - (instancetype)init { self = [super init]; if (self) { _dateFormatter = [[NSDateFormatter alloc] init]; - [_dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"]; + _dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; + _dateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0]; } return self; } diff --git a/Source/santametricservice/Writers/SNTMetricHTTPWriterTest.m b/Source/santametricservice/Writers/SNTMetricHTTPWriterTest.m index 1805d7cd9..eb54e401e 100644 --- a/Source/santametricservice/Writers/SNTMetricHTTPWriterTest.m +++ b/Source/santametricservice/Writers/SNTMetricHTTPWriterTest.m @@ -52,12 +52,6 @@ - (void)setUp { .andReturn(self.mockSessionDataTask); } -- (void)tearDown { - [self.mockSessionDataTask stopMocking]; - [self.mockSession stopMocking]; - [self.mockMOLAuthenticatingURLSession stopMocking]; -} - /// enqueues a mock HTTP response for testing. - (void)createMockResponseWithURL:(NSURL *)url withCode:(NSInteger)code