From 40b99a15ed5e2706178e9a500c0e292bf5b909b2 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 9 Aug 2017 12:16:12 -0400 Subject: [PATCH] Fix up some tests Included plausible test implementation for an in-memory profile manager. Note two tests remain failing (they've been failing for a while) // FREEBIE --- Makefile | 1 + .../TSKitiOSTestApp.xcodeproj/project.pbxproj | 6 ++ .../TestSupport/Fakes/OWSFakeProfileManager.h | 13 ++++ .../TestSupport/Fakes/OWSFakeProfileManager.m | 62 +++++++++++++++++++ .../Fakes/OWSUnitTestEnvironment.m | 4 +- 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 SignalServiceKit/tests/TestSupport/Fakes/OWSFakeProfileManager.h create mode 100644 SignalServiceKit/tests/TestSupport/Fakes/OWSFakeProfileManager.m diff --git a/Makefile b/Makefile index 807b3c91d..d23dfdd1e 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ build: dependencies test: bundle exec fastlane scan + cd SignalServiceKit && make test clean: cd $(WORKING_DIR) && \ diff --git a/SignalServiceKit/Example/TSKitiOSTestApp/TSKitiOSTestApp.xcodeproj/project.pbxproj b/SignalServiceKit/Example/TSKitiOSTestApp/TSKitiOSTestApp.xcodeproj/project.pbxproj index 9c2748493..10d31d2ab 100644 --- a/SignalServiceKit/Example/TSKitiOSTestApp/TSKitiOSTestApp.xcodeproj/project.pbxproj +++ b/SignalServiceKit/Example/TSKitiOSTestApp/TSKitiOSTestApp.xcodeproj/project.pbxproj @@ -38,6 +38,7 @@ 45B840211D988DA100F9E938 /* OWSReadReceiptTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45B840201D988DA100F9E938 /* OWSReadReceiptTest.m */; }; 45C6A09A1D2F029B007D8AC0 /* TSMessageTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45C6A0991D2F029B007D8AC0 /* TSMessageTest.m */; }; 45D7243F1D67899F00E0CA54 /* OWSDeviceProvisionerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45D7243E1D67899F00E0CA54 /* OWSDeviceProvisionerTest.m */; }; + 45DC30C71F3B69B7008C4378 /* OWSFakeProfileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 45DC30C61F3B69B7008C4378 /* OWSFakeProfileManager.m */; }; 45E741B61E5D14E800735842 /* OWSIncomingMessageFinderTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45E741B51E5D14E800735842 /* OWSIncomingMessageFinderTest.m */; }; 51520592F83F2440F2DE4D67 /* libPods-TSKitiOSTestApp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B8362AB8E280E0F64352F08A /* libPods-TSKitiOSTestApp.a */; }; 6323E1F7730289398452E5C5 /* OWSFingerprintTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 6323E02A33682A8838FE3F27 /* OWSFingerprintTest.m */; }; @@ -104,6 +105,8 @@ 45B840201D988DA100F9E938 /* OWSReadReceiptTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSReadReceiptTest.m; path = ../../../tests/Devices/OWSReadReceiptTest.m; sourceTree = ""; }; 45C6A0991D2F029B007D8AC0 /* TSMessageTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TSMessageTest.m; path = ../../../tests/Messages/Interactions/TSMessageTest.m; sourceTree = ""; }; 45D7243E1D67899F00E0CA54 /* OWSDeviceProvisionerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSDeviceProvisionerTest.m; path = ../../../tests/Devices/OWSDeviceProvisionerTest.m; sourceTree = ""; }; + 45DC30C51F3B69B7008C4378 /* OWSFakeProfileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OWSFakeProfileManager.h; path = ../../../tests/TestSupport/Fakes/OWSFakeProfileManager.h; sourceTree = ""; }; + 45DC30C61F3B69B7008C4378 /* OWSFakeProfileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSFakeProfileManager.m; path = ../../../tests/TestSupport/Fakes/OWSFakeProfileManager.m; sourceTree = ""; }; 45E741B51E5D14E800735842 /* OWSIncomingMessageFinderTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSIncomingMessageFinderTest.m; path = ../../../tests/Messages/OWSIncomingMessageFinderTest.m; sourceTree = ""; }; 6323E02A33682A8838FE3F27 /* OWSFingerprintTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSFingerprintTest.m; path = ../../../tests/Security/OWSFingerprintTest.m; sourceTree = ""; }; 6323E3E540CF763D71DACB59 /* SignalRecipientTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SignalRecipientTest.m; path = ../../tests/Contacts/SignalRecipientTest.m; sourceTree = ""; }; @@ -157,6 +160,8 @@ 453E1FD51DA83DDC00DDD7B7 /* Fakes */ = { isa = PBXGroup; children = ( + 45DC30C51F3B69B7008C4378 /* OWSFakeProfileManager.h */, + 45DC30C61F3B69B7008C4378 /* OWSFakeProfileManager.m */, 453E1FD61DA83E1000DDD7B7 /* OWSFakeContactsManager.h */, 453E1FD71DA83E1000DDD7B7 /* OWSFakeContactsManager.m */, 453E1FD91DA83EFB00DDD7B7 /* OWSFakeContactsUpdater.h */, @@ -573,6 +578,7 @@ 45AE484C1E072871004D96C2 /* OWSFakeCallMessageHandler.m in Sources */, 45AE48491E072711004D96C2 /* OWSUnitTestEnvironment.m in Sources */, 459850C11D22C6F2006FFEDB /* PhoneNumberTest.m in Sources */, + 45DC30C71F3B69B7008C4378 /* OWSFakeProfileManager.m in Sources */, 45458B7A1CC342B600A02153 /* TSStorageSignedPreKeyStore.m in Sources */, 453E1FDB1DA83EFB00DDD7B7 /* OWSFakeContactsUpdater.m in Sources */, 452137231E8D6D2F0048FD10 /* OWSFakeMessageSender.m in Sources */, diff --git a/SignalServiceKit/tests/TestSupport/Fakes/OWSFakeProfileManager.h b/SignalServiceKit/tests/TestSupport/Fakes/OWSFakeProfileManager.h new file mode 100644 index 000000000..29469f3cc --- /dev/null +++ b/SignalServiceKit/tests/TestSupport/Fakes/OWSFakeProfileManager.h @@ -0,0 +1,13 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import "ProfileManagerProtocol.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface OWSFakeProfileManager : NSObject + +@end + +NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/tests/TestSupport/Fakes/OWSFakeProfileManager.m b/SignalServiceKit/tests/TestSupport/Fakes/OWSFakeProfileManager.m new file mode 100644 index 000000000..f9f12b410 --- /dev/null +++ b/SignalServiceKit/tests/TestSupport/Fakes/OWSFakeProfileManager.m @@ -0,0 +1,62 @@ +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// + +#import "OWSFakeProfileManager.h" +#import "TSThread.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface OWSFakeProfileManager () + +@property (nonatomic, readonly) NSMutableDictionary *profileKeys; +@property (nonatomic, readonly) NSMutableSet *recipientWhitelist; +@property (nonatomic, readonly) NSMutableSet *threadWhitelist; + +@end + +@implementation OWSFakeProfileManager + +- (instancetype)init +{ + self = [super init]; + if (!self) { + return self; + } + + _profileKeys = [NSMutableDictionary new]; + _recipientWhitelist = [NSMutableSet new]; + _threadWhitelist = [NSMutableSet new]; + + return self; +} + + +- (NSData *)localProfileKey +{ + return [@"fake-local-profile-key-for-testing" dataUsingEncoding:NSUTF8StringEncoding]; +} + +- (void)setProfileKey:(NSData *)profileKey forRecipientId:(NSString *)recipientId +{ + self.profileKeys[recipientId] = profileKey; +} + +- (BOOL)isUserInProfileWhitelist:(NSString *)recipientId +{ + return [self.recipientWhitelist containsObject:recipientId]; +} + +- (BOOL)isThreadInProfileWhitelist:(TSThread *)thread +{ + return [self.threadWhitelist containsObject:thread.uniqueId]; +} + +- (void)addUserToProfileWhitelist:(NSString *)recipientId +{ + [self.recipientWhitelist addObject:recipientId]; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/tests/TestSupport/Fakes/OWSUnitTestEnvironment.m b/SignalServiceKit/tests/TestSupport/Fakes/OWSUnitTestEnvironment.m index 6209e833a..846c0af32 100644 --- a/SignalServiceKit/tests/TestSupport/Fakes/OWSUnitTestEnvironment.m +++ b/SignalServiceKit/tests/TestSupport/Fakes/OWSUnitTestEnvironment.m @@ -7,6 +7,7 @@ #import "OWSFakeContactsManager.h" #import "OWSFakeMessageSender.h" #import "OWSFakeNotificationsManager.h" +#import "OWSFakeProfileManager.h" NS_ASSUME_NONNULL_BEGIN @@ -25,7 +26,8 @@ NS_ASSUME_NONNULL_BEGIN return [super initWithCallMessageHandler:[OWSFakeCallMessageHandler new] contactsManager:[OWSFakeContactsManager new] messageSender:[OWSFakeMessageSender new] - notificationsManager:[OWSFakeNotificationsManager new]]; + notificationsManager:[OWSFakeNotificationsManager new] + profileManager:[OWSFakeProfileManager new]]; } @end