Fixed test build. Some tests still failing.

Executed 85 tests, with 22 failures (17 unexpected) in 7.416 (8.531) seconds

// FREEBIE
pull/1/head
Michael Kirk
parent c711b4a66d
commit 2addb9e81d

1
.gitignore vendored

@ -17,6 +17,7 @@ DerivedData
*.hmap
*.ipa
*.xcuserstate
xcshareddata
Pods/

@ -35,6 +35,8 @@
45AE484F1E072906004D96C2 /* OWSFakeNotificationsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 45AE484E1E072906004D96C2 /* OWSFakeNotificationsManager.m */; };
45B700971D9841E400269FFD /* OWSDisappearingMessagesConfigurationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45B700961D9841E400269FFD /* OWSDisappearingMessagesConfigurationTest.m */; };
45B840211D988DA100F9E938 /* OWSReadReceiptTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45B840201D988DA100F9E938 /* OWSReadReceiptTest.m */; };
45C5F5A51EE38AB400E1D20D /* OWSFakePreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = 45C5F5A41EE38AB400E1D20D /* OWSFakePreferences.m */; };
45C5F5A61EE38AB400E1D20D /* OWSFakePreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = 45C5F5A41EE38AB400E1D20D /* OWSFakePreferences.m */; };
45C6A09A1D2F029B007D8AC0 /* TSMessageTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45C6A0991D2F029B007D8AC0 /* TSMessageTest.m */; };
45D7243F1D67899F00E0CA54 /* OWSDeviceProvisionerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45D7243E1D67899F00E0CA54 /* OWSDeviceProvisionerTest.m */; };
45E741B61E5D14E800735842 /* OWSIncomingMessageFinderTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45E741B51E5D14E800735842 /* OWSIncomingMessageFinderTest.m */; };
@ -100,6 +102,8 @@
45AE484E1E072906004D96C2 /* OWSFakeNotificationsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSFakeNotificationsManager.m; path = ../../../tests/TestSupport/Fakes/OWSFakeNotificationsManager.m; sourceTree = "<group>"; };
45B700961D9841E400269FFD /* OWSDisappearingMessagesConfigurationTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSDisappearingMessagesConfigurationTest.m; path = ../../../tests/Contacts/OWSDisappearingMessagesConfigurationTest.m; sourceTree = "<group>"; };
45B840201D988DA100F9E938 /* OWSReadReceiptTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSReadReceiptTest.m; path = ../../../tests/Devices/OWSReadReceiptTest.m; sourceTree = "<group>"; };
45C5F5A31EE38AB400E1D20D /* OWSFakePreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OWSFakePreferences.h; path = ../../../tests/TestSupport/Fakes/OWSFakePreferences.h; sourceTree = "<group>"; };
45C5F5A41EE38AB400E1D20D /* OWSFakePreferences.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSFakePreferences.m; path = ../../../tests/TestSupport/Fakes/OWSFakePreferences.m; sourceTree = "<group>"; };
45C6A0991D2F029B007D8AC0 /* TSMessageTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TSMessageTest.m; path = ../../../tests/Messages/Interactions/TSMessageTest.m; sourceTree = "<group>"; };
45D7243E1D67899F00E0CA54 /* OWSDeviceProvisionerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSDeviceProvisionerTest.m; path = ../../../tests/Devices/OWSDeviceProvisionerTest.m; sourceTree = "<group>"; };
45E741B51E5D14E800735842 /* OWSIncomingMessageFinderTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSIncomingMessageFinderTest.m; path = ../../../tests/Messages/OWSIncomingMessageFinderTest.m; sourceTree = "<group>"; };
@ -169,6 +173,8 @@
45AE484E1E072906004D96C2 /* OWSFakeNotificationsManager.m */,
452137211E8D6D2F0048FD10 /* OWSFakeMessageSender.h */,
452137221E8D6D2F0048FD10 /* OWSFakeMessageSender.m */,
45C5F5A31EE38AB400E1D20D /* OWSFakePreferences.h */,
45C5F5A41EE38AB400E1D20D /* OWSFakePreferences.m */,
);
name = Fakes;
sourceTree = "<group>";
@ -457,7 +463,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
276B029791E679B0E87877B7 /* [CP] Copy Pods Resources */ = {
@ -532,7 +538,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
@ -543,6 +549,7 @@
buildActionMask = 2147483647;
files = (
B6273DDC1C13A2E500738558 /* ViewController.m in Sources */,
45C5F5A51EE38AB400E1D20D /* OWSFakePreferences.m in Sources */,
B6273DD91C13A2E500738558 /* AppDelegate.m in Sources */,
B6273DD61C13A2E500738558 /* main.m in Sources */,
);
@ -572,6 +579,7 @@
45458B7A1CC342B600A02153 /* TSStorageSignedPreKeyStore.m in Sources */,
453E1FDB1DA83EFB00DDD7B7 /* OWSFakeContactsUpdater.m in Sources */,
452137231E8D6D2F0048FD10 /* OWSFakeMessageSender.m in Sources */,
45C5F5A61EE38AB400E1D20D /* OWSFakePreferences.m in Sources */,
D2AECE731DE8C3360068CE15 /* ContactSortingTest.m in Sources */,
453E1FD81DA83E1000DDD7B7 /* OWSFakeContactsManager.m in Sources */,
454021ED1D960ABF00F2126D /* OWSDisappearingMessageFinderTest.m in Sources */,

@ -26,10 +26,7 @@
{
// Sanity Check
XCTAssertNotNil(self.localNumber);
[[[SignalRecipient alloc] initWithTextSecureIdentifier:self.localNumber
relay:nil
supportsVoice:YES
supportsWebRTC:YES] save];
[[[SignalRecipient alloc] initWithTextSecureIdentifier:self.localNumber relay:nil] save];
XCTAssertNotNil([SignalRecipient recipientWithTextSecureIdentifier:self.localNumber]);
SignalRecipient *me = [SignalRecipient selfRecipient];

@ -66,7 +66,8 @@
XCTAssertEqual(0, [thread numberOfInteractions]);
NSError *error;
TSAttachmentStream *incomingAttachment = [[TSAttachmentStream alloc] initWithContentType:@"image/jpeg"];
TSAttachmentStream *incomingAttachment = [[TSAttachmentStream alloc] initWithContentType:@"image/jpeg"
sourceFilename:nil];
[incomingAttachment writeData:[NSData new] error:&error];
[incomingAttachment save];
@ -83,7 +84,8 @@
expiresInSeconds:0];
[incomingMessage save];
TSAttachmentStream *outgoingAttachment = [[TSAttachmentStream alloc] initWithContentType:@"image/jpeg"];
TSAttachmentStream *outgoingAttachment = [[TSAttachmentStream alloc] initWithContentType:@"image/jpeg"
sourceFilename:nil];
[outgoingAttachment writeData:[NSData new] error:&error];
[outgoingAttachment save];
@ -94,7 +96,7 @@
TSOutgoingMessage *outgoingMessage = [[TSOutgoingMessage alloc] initWithTimestamp:10000
inThread:thread
messageBody:@"outgoing message body"
attachmentIds:@[ outgoingAttachment.uniqueId ]];
attachmentIds:[@[ outgoingAttachment.uniqueId ] mutableCopy]];
[outgoingMessage save];
// Sanity check

@ -1,4 +1,6 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved.
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "NSDate+millisecondTimeStamp.h"
#import "TSAttachmentStream.h"
@ -75,7 +77,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)testDescriptionWithPhotoAttachmentId
{
TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"image/jpeg"];
TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"image/jpeg" sourceFilename:nil];
[attachment save];
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
@ -89,7 +91,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)testDescriptionWithVideoAttachmentId
{
TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"video/mp4"];
TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"video/mp4" sourceFilename:nil];
[attachment save];
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
@ -103,7 +105,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)testDescriptionWithAudioAttachmentId
{
TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"audio/mp3"];
TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"audio/mp3" sourceFilename:nil];
[attachment save];
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
@ -116,7 +118,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)testDescriptionWithUnkownAudioContentType
{
TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"non/sense"];
TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"non/sense" sourceFilename:nil];
[attachment save];
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1

@ -1,5 +1,6 @@
// Created by Michael Kirk on 10/7/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSContactThread.h"
#import "TSOutgoingMessage.h"
@ -34,18 +35,7 @@ NS_ASSUME_NONNULL_BEGIN
messageBody:nil
attachmentIds:[NSMutableArray new]
expiresInSeconds:10];
message.messageState = TSOutgoingMessageStateSent;
XCTAssert(message.shouldStartExpireTimer);
}
- (void)testShouldStartExpireTimerWithDeliveredMessage
{
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:100
inThread:self.thread
messageBody:nil
attachmentIds:[NSMutableArray new]
expiresInSeconds:10];
message.messageState = TSOutgoingMessageStateDelivered;
[message updateWithMessageState:TSOutgoingMessageStateSentToService];
XCTAssert(message.shouldStartExpireTimer);
}
@ -56,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
messageBody:nil
attachmentIds:[NSMutableArray new]
expiresInSeconds:10];
message.messageState = TSOutgoingMessageStateUnsent;
[message updateWithMessageState:TSOutgoingMessageStateUnsent];
XCTAssertFalse(message.shouldStartExpireTimer);
}
@ -67,7 +57,7 @@ NS_ASSUME_NONNULL_BEGIN
messageBody:nil
attachmentIds:[NSMutableArray new]
expiresInSeconds:10];
message.messageState = TSOutgoingMessageStateAttemptingOut;
[message updateWithMessageState:TSOutgoingMessageStateAttemptingOut];
XCTAssertFalse(message.shouldStartExpireTimer);
}

@ -1,5 +1,6 @@
// Created by Michael Kirk on 9/23/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "NSDate+millisecondTimeStamp.h"
#import "OWSDisappearingMessagesConfiguration.h"
@ -61,12 +62,12 @@ NS_ASSUME_NONNULL_BEGIN
expireStartedAt:0];
[unExpiringMessage save];
OWSDisappearingMessagesJob *job =
[[OWSDisappearingMessagesJob alloc] initWithStorageManager:[TSStorageManager sharedManager]];
OWSDisappearingMessagesJob *job = [OWSDisappearingMessagesJob sharedJob];
// Sanity Check.
XCTAssertEqual(4, [TSMessage numberOfKeysInCollection]);
[job run];
[job startIfNecessary];
XCTAssertEqual(2, [TSMessage numberOfKeysInCollection]);
}
@ -75,9 +76,8 @@ NS_ASSUME_NONNULL_BEGIN
TSThread *thread = [[TSThread alloc] initWithUniqueId:@"fake-thread-id"];
[thread save];
OWSDisappearingMessagesJob *job =
[[OWSDisappearingMessagesJob alloc] initWithStorageManager:[TSStorageManager sharedManager]];
OWSDisappearingMessagesJob *job = [OWSDisappearingMessagesJob sharedJob];
OWSDisappearingMessagesConfiguration *configuration =
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId];
[configuration remove];
@ -90,8 +90,7 @@ NS_ASSUME_NONNULL_BEGIN
expireStartedAt:0];
[expiringMessage save];
[job becomeConsistentWithConfigurationForMessage:expiringMessage contactsManager:[OWSFakeContactsManager new]];
[OWSDisappearingMessagesJob becomeConsistentWithConfigurationForMessage:expiringMessage contactsManager:[OWSFakeContactsManager new]];
configuration = [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId];
XCTAssertNotNil(configuration);
@ -104,14 +103,10 @@ NS_ASSUME_NONNULL_BEGIN
TSThread *thread = [[TSThread alloc] initWithUniqueId:@"fake-thread-id"];
[thread save];
OWSDisappearingMessagesJob *job =
[[OWSDisappearingMessagesJob alloc] initWithStorageManager:[TSStorageManager sharedManager]];
OWSDisappearingMessagesConfiguration *configuration =
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId];
[configuration remove];
TSMessage *unExpiringMessage = [[TSMessage alloc] initWithTimestamp:1
inThread:thread
messageBody:@"unexpiringMessage"
@ -119,7 +114,7 @@ NS_ASSUME_NONNULL_BEGIN
expiresInSeconds:0
expireStartedAt:0];
[unExpiringMessage save];
[job becomeConsistentWithConfigurationForMessage:unExpiringMessage contactsManager:[OWSFakeContactsManager new]];
[OWSDisappearingMessagesJob becomeConsistentWithConfigurationForMessage:unExpiringMessage contactsManager:[OWSFakeContactsManager new]];
XCTAssertNil([OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId]);
}

@ -130,7 +130,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWSMessageSenderFakeNetworkManager : OWSFakeNetworkManager
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)init;
- (instancetype)initWithSuccess:(BOOL)shouldSucceed NS_DESIGNATED_INITIALIZER;
@property (nonatomic, readonly) BOOL shouldSucceed;
@ -141,7 +141,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithSuccess:(BOOL)shouldSucceed
{
self = [super init];
self = [self init];
if (!self) {
return self;
}
@ -316,7 +316,7 @@ NS_ASSUME_NONNULL_BEGIN
XCTestExpectation *markedAsSent = [self expectationWithDescription:@"markedAsSent"];
[messageSender sendMessage:message
success:^() {
if (message.messageState == TSOutgoingMessageStateSent) {
if (message.messageState == TSOutgoingMessageStateSentToService) {
[markedAsSent fulfill];
} else {
XCTFail(@"Unexpected message state");
@ -341,9 +341,10 @@ NS_ASSUME_NONNULL_BEGIN
XCTestExpectation *markedAsSent = [self expectationWithDescription:@"markedAsSent"];
[messageSender sendAttachmentData:[NSData new]
contentType:@"image/gif"
sourceFilename:nil
inMessage:message
success:^() {
if (message.messageState == TSOutgoingMessageStateSent) {
if (message.messageState == TSOutgoingMessageStateSentToService) {
[markedAsSent fulfill];
} else {
XCTFail(@"Unexpected message state");
@ -394,6 +395,7 @@ NS_ASSUME_NONNULL_BEGIN
XCTestExpectation *markedAsUnsent = [self expectationWithDescription:@"markedAsUnsent"];
[messageSender sendAttachmentData:[NSData new]
contentType:@"image/gif"
sourceFilename:nil
inMessage:message
success:^{
XCTFail(@"sendMessage should fail.");
@ -422,6 +424,7 @@ NS_ASSUME_NONNULL_BEGIN
XCTestExpectation *markedAsUnsent = [self expectationWithDescription:@"markedAsUnsent"];
[messageSender sendAttachmentData:[NSData new]
contentType:@"image/gif"
sourceFilename:nil
inMessage:message
success:^{
XCTFail(@"sendMessage should fail.");
@ -444,15 +447,9 @@ NS_ASSUME_NONNULL_BEGIN
NSData *groupIdData = [Cryptography generateRandomBytes:32];
SignalRecipient *successfulRecipient =
[[SignalRecipient alloc] initWithTextSecureIdentifier:@"successful-recipient-id"
relay:nil
supportsVoice:YES
supportsWebRTC:YES];
[[SignalRecipient alloc] initWithTextSecureIdentifier:@"successful-recipient-id" relay:nil];
SignalRecipient *successfulRecipient2 =
[[SignalRecipient alloc] initWithTextSecureIdentifier:@"successful-recipient-id2"
relay:nil
supportsVoice:YES
supportsWebRTC:YES];
[[SignalRecipient alloc] initWithTextSecureIdentifier:@"successful-recipient-id2" relay:nil];
TSGroupModel *groupModel = [[TSGroupModel alloc]
initWithTitle:@"group title"
@ -467,7 +464,7 @@ NS_ASSUME_NONNULL_BEGIN
XCTestExpectation *markedAsSent = [self expectationWithDescription:@"markedAsSent"];
[messageSender sendMessage:message
success:^{
if (message.messageState == TSOutgoingMessageStateSent) {
if (message.messageState == TSOutgoingMessageStateSentToService) {
[markedAsSent fulfill];
} else {
XCTFail(@"Unexpected message state");
@ -483,10 +480,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)testGetRecipients
{
SignalRecipient *recipient = [[SignalRecipient alloc] initWithTextSecureIdentifier:@"fake-recipient-id"
relay:nil
supportsVoice:YES
supportsWebRTC:YES];
SignalRecipient *recipient = [[SignalRecipient alloc] initWithTextSecureIdentifier:@"fake-recipient-id" relay:nil];
[recipient save];
OWSMessageSender *messageSender = self.successfulMessageSender;

@ -77,7 +77,7 @@
- (void)testFilesWithoutInteractionsAreDeleted
{
NSError *error;
TSAttachmentStream *attachmentStream = [[TSAttachmentStream alloc] initWithContentType:@"image/jpeg"];
TSAttachmentStream *attachmentStream = [[TSAttachmentStream alloc] initWithContentType:@"image/jpeg" sourceFilename:nil];
[attachmentStream writeData:[NSData new] error:&error];
[attachmentStream save];
NSString *orphanedFilePath = [attachmentStream filePath];
@ -97,7 +97,7 @@
[savedThread save];
NSError *error;
TSAttachmentStream *attachmentStream = [[TSAttachmentStream alloc] initWithContentType:@"image/jpeg"];
TSAttachmentStream *attachmentStream = [[TSAttachmentStream alloc] initWithContentType:@"image/jpeg" sourceFilename:nil];
[attachmentStream writeData:[NSData new] error:&error];
[attachmentStream save];
@ -125,7 +125,7 @@
- (void)testFilesWithoutAttachmentStreamsAreDeleted
{
NSError *error;
TSAttachmentStream *attachmentStream = [[TSAttachmentStream alloc] initWithContentType:@"image/jpeg"];
TSAttachmentStream *attachmentStream = [[TSAttachmentStream alloc] initWithContentType:@"image/jpeg" sourceFilename:nil];
[attachmentStream writeData:[NSData new] error:&error];
// Intentionally not saved, because we want a lingering file.

@ -1,9 +1,5 @@
//
// TSStorageIdentityKeyStoreTests.m
// TextSecureKit
//
// Created by Frederic Jacobs on 06/11/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import <XCTest/XCTest.h>
@ -11,7 +7,6 @@
#import "OWSUnitTestEnvironment.h"
#import "SecurityUtils.h"
#import "TSPrivacyPreferences.h"
#import "TSStorageManager+IdentityKeyStore.h"
#import "TSStorageManager.h"
#import "TextSecureKitEnv.h"
@ -37,7 +32,8 @@
NSData *newKey = [SecurityUtils generateRandomBytes:32];
NSString *recipientId = @"test@gmail.com";
XCTAssert([[TSStorageManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId]);
XCTAssert([[TSStorageManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
XCTAssert([[TSStorageManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
}
- (void)testAlreadyRegisteredKey {
@ -46,48 +42,28 @@
[[TSStorageManager sharedManager] saveRemoteIdentity:newKey recipientId:recipientId];
XCTAssert([[TSStorageManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId]);
XCTAssert([[TSStorageManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
XCTAssert([[TSStorageManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
}
- (void)testChangedKeyWithBlockingIdentityChanges
- (void)testChangedKey
{
TSPrivacyPreferences *preferences = [TSPrivacyPreferences sharedInstance];
preferences.shouldBlockOnIdentityChange = YES;
[preferences save];
NSData *originalKey = [SecurityUtils generateRandomBytes:32];
NSString *recipientId = @"test@protonmail.com";
NSData *newKey = [SecurityUtils generateRandomBytes:32];
NSString *recipientId = @"test@gmail.com";
[[TSStorageManager sharedManager] saveRemoteIdentity:newKey recipientId:recipientId];
[[TSStorageManager sharedManager] saveRemoteIdentity:originalKey recipientId:recipientId];
XCTAssert([[TSStorageManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId]);
XCTAssert([[TSStorageManager sharedManager] isTrustedIdentityKey:originalKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
XCTAssert([[TSStorageManager sharedManager] isTrustedIdentityKey:originalKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
NSData *otherKey = [SecurityUtils generateRandomBytes:32];
XCTAssertFalse([[TSStorageManager sharedManager] isTrustedIdentityKey:otherKey recipientId:recipientId]);
XCTAssertFalse([[TSStorageManager sharedManager] isTrustedIdentityKey:otherKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
XCTAssert([[TSStorageManager sharedManager] isTrustedIdentityKey:otherKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
}
- (void)testChangedKeyWithNonBlockingIdentityChanges
{
TSPrivacyPreferences *preferences = [TSPrivacyPreferences sharedInstance];
preferences.shouldBlockOnIdentityChange = NO;
[preferences save];
NSData *newKey = [SecurityUtils generateRandomBytes:32];
NSString *recipientId = @"test@gmail.com";
[[TSStorageManager sharedManager] saveRemoteIdentity:newKey recipientId:recipientId];
XCTAssert([[TSStorageManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId]);
NSData *otherKey = [SecurityUtils generateRandomBytes:32];
[TextSecureKitEnv setSharedEnv:[OWSUnitTestEnvironment new]];
XCTAssertTrue([[TSStorageManager sharedManager] isTrustedIdentityKey:otherKey recipientId:recipientId]);
}
- (void)testIdentityKey {
[[TSStorageManager sharedManager] generateNewIdentityKey];

@ -13,9 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
{
NSLog(@"[OWSFakeContactsUpdater] Faking contact lookup.");
return [[SignalRecipient alloc] initWithTextSecureIdentifier:@"fake-recipient-id"
relay:nil
supportsVoice:YES
supportsWebRTC:YES];
relay:nil];
}
@end

@ -9,6 +9,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWSFakeMessageSender : OWSMessageSender
- (instancetype)init;
- (instancetype)initWithExpectation:(XCTestExpectation *)expectation;
@property (nonatomic, readonly) XCTestExpectation *expectation;

@ -0,0 +1,14 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "TSPreferences.h"
NS_ASSUME_NONNULL_BEGIN
@interface OWSFakePreferences : NSObject <TSPreferences>
@end
NS_ASSUME_NONNULL_END

@ -0,0 +1,14 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSFakePreferences.h"
@implementation OWSFakePreferences
- (BOOL)isSendingIdentityApprovalRequired
{
return NO;
}
@end

@ -7,6 +7,7 @@
#import "OWSFakeContactsManager.h"
#import "OWSFakeMessageSender.h"
#import "OWSFakeNotificationsManager.h"
#import "OWSFakePreferences.h"
NS_ASSUME_NONNULL_BEGIN
@ -17,7 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
return [super initWithCallMessageHandler:[OWSFakeCallMessageHandler new]
contactsManager:[OWSFakeContactsManager new]
messageSender:[OWSFakeMessageSender new]
notificationsManager:[OWSFakeNotificationsManager new]];
notificationsManager:[OWSFakeNotificationsManager new]
preferences:[OWSFakePreferences new]];
}
@end

Loading…
Cancel
Save