Contacts don't have safety numbers until they've exchanged keys.

// FREEBIE
pull/1/head
Michael Kirk 9 years ago
parent 2e06bb148f
commit 1ebb82f987

@ -10,6 +10,8 @@
308D7DFA789594CEA62740D9 /* libPods-TSKitiOSTestAppTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C0DC1A83C39CBC09FB2405A3 /* libPods-TSKitiOSTestAppTests.a */; };
45046FE01D95A6130015EFF2 /* TSMessagesManagerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45046FDF1D95A6130015EFF2 /* TSMessagesManagerTest.m */; };
450E3C9A1D96DD2600BF4EB6 /* OWSDisappearingMessagesJobTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 450E3C991D96DD2600BF4EB6 /* OWSDisappearingMessagesJobTest.m */; };
4516E3E81DD153CC00DC4206 /* TSGroupThreadTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4516E3E71DD153CC00DC4206 /* TSGroupThreadTest.m */; };
4516E3EA1DD1542300DC4206 /* TSContactThreadTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4516E3E91DD1542300DC4206 /* TSContactThreadTest.m */; };
452EE6CF1D4A754C00E934BA /* TSThreadTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 452EE6CE1D4A754C00E934BA /* TSThreadTest.m */; };
452EE6D51D4AC43300E934BA /* OWSOrphanedDataCleanerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 452EE6D41D4AC43300E934BA /* OWSOrphanedDataCleanerTest.m */; };
453E1FCF1DA8313100DDD7B7 /* OWSMessageSenderTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 453E1FCE1DA8313100DDD7B7 /* OWSMessageSenderTest.m */; };
@ -59,6 +61,8 @@
36DA6C703F99948D553F4E3F /* Pods-TSKitiOSTestAppTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TSKitiOSTestAppTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-TSKitiOSTestAppTests/Pods-TSKitiOSTestAppTests.debug.xcconfig"; sourceTree = "<group>"; };
45046FDF1D95A6130015EFF2 /* TSMessagesManagerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TSMessagesManagerTest.m; path = ../../../tests/Messages/TSMessagesManagerTest.m; sourceTree = "<group>"; };
450E3C991D96DD2600BF4EB6 /* OWSDisappearingMessagesJobTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSDisappearingMessagesJobTest.m; path = ../../../tests/Messages/OWSDisappearingMessagesJobTest.m; sourceTree = "<group>"; };
4516E3E71DD153CC00DC4206 /* TSGroupThreadTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TSGroupThreadTest.m; path = ../../../tests/Contacts/TSGroupThreadTest.m; sourceTree = "<group>"; };
4516E3E91DD1542300DC4206 /* TSContactThreadTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TSContactThreadTest.m; path = ../../../tests/Contacts/TSContactThreadTest.m; sourceTree = "<group>"; };
452EE6CE1D4A754C00E934BA /* TSThreadTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TSThreadTest.m; path = ../../../tests/Contacts/TSThreadTest.m; sourceTree = "<group>"; };
452EE6D41D4AC43300E934BA /* OWSOrphanedDataCleanerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSOrphanedDataCleanerTest.m; sourceTree = "<group>"; };
453E1FCE1DA8313100DDD7B7 /* OWSMessageSenderTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OWSMessageSenderTest.m; path = ../../../tests/Messages/OWSMessageSenderTest.m; sourceTree = "<group>"; };
@ -201,6 +205,8 @@
459850C01D22C6F2006FFEDB /* PhoneNumberTest.m */,
452EE6CE1D4A754C00E934BA /* TSThreadTest.m */,
45B700961D9841E400269FFD /* OWSDisappearingMessagesConfigurationTest.m */,
4516E3E71DD153CC00DC4206 /* TSGroupThreadTest.m */,
4516E3E91DD1542300DC4206 /* TSContactThreadTest.m */,
);
name = Contacts;
sourceTree = "<group>";
@ -535,6 +541,7 @@
45458B751CC342B600A02153 /* SignedPreKeyDeletionTests.m in Sources */,
45458B7B1CC342B600A02153 /* CryptographyTests.m in Sources */,
45D7243F1D67899F00E0CA54 /* OWSDeviceProvisionerTest.m in Sources */,
4516E3E81DD153CC00DC4206 /* TSGroupThreadTest.m in Sources */,
45458B791CC342B600A02153 /* TSStoragePreKeyStoreTests.m in Sources */,
452EE6D51D4AC43300E934BA /* OWSOrphanedDataCleanerTest.m in Sources */,
450E3C9A1D96DD2600BF4EB6 /* OWSDisappearingMessagesJobTest.m in Sources */,
@ -547,6 +554,7 @@
453E1FDB1DA83EFB00DDD7B7 /* OWSFakeContactsUpdater.m in Sources */,
453E1FD81DA83E1000DDD7B7 /* OWSFakeContactsManager.m in Sources */,
454021ED1D960ABF00F2126D /* OWSDisappearingMessageFinderTest.m in Sources */,
4516E3EA1DD1542300DC4206 /* TSContactThreadTest.m in Sources */,
45458B771CC342B600A02153 /* TSMessageStorageTests.m in Sources */,
45046FE01D95A6130015EFF2 /* TSMessagesManagerTest.m in Sources */,
45458B7C1CC342B600A02153 /* MessagePaddingTests.m in Sources */,

@ -64,6 +64,8 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (BOOL)hasUnreadMessages;
- (BOOL)hasSafetyNumbers;
- (void)markAllAsRead;
- (void)markAllAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;

@ -84,6 +84,11 @@ NS_ASSUME_NONNULL_BEGIN
return nil;
}
- (BOOL)hasSafetyNumbers
{
return NO;
}
#pragma mark Interactions
/**

@ -3,6 +3,7 @@
#import "TSContactThread.h"
#import "ContactsUpdater.h"
#import "TSStorageManager+identityKeyStore.h"
#import "TextSecureKitEnv.h"
#import <YapDatabase/YapDatabaseConnection.h>
#import <YapDatabase/YapDatabaseTransaction.h>
@ -74,6 +75,11 @@ NS_ASSUME_NONNULL_BEGIN
return false;
}
- (BOOL)hasSafetyNumbers
{
return !![self.storageManager identityKeyForRecipientId:self.contactIdentifier];
}
- (NSString *)name
{
return [[TextSecureKitEnv sharedEnv].contactsManager nameStringForPhoneIdentifier:self.contactIdentifier];

@ -29,6 +29,9 @@ static uint32_t const OWSFingerprintDefaultHashIterations = 5200;
theirIdentityKey:(NSData *)theirIdentityKeyWithoutKeyType
hashIterations:(uint32_t)hashIterations
{
NSParameterAssert(theirIdentityKeyWithoutKeyType.length == 32);
NSParameterAssert(myIdentityKeyWithoutKeyType.length == 32);
self = [super init];
if (!self) {
return self;

@ -3,6 +3,7 @@
#import <Mantle/MTLModel+NSCoding.h>
@class TSStorageManager;
@class YapDatabaseConnection;
@class YapDatabaseReadTransaction;
@class YapDatabaseReadWriteTransaction;
@ -61,6 +62,9 @@
- (YapDatabaseConnection *)dbConnection;
+ (YapDatabaseConnection *)dbConnection;
- (TSStorageManager *)storageManager;
+ (TSStorageManager *)storageManager;
/**
* Fetches the object with the provided identifier
*

@ -65,11 +65,21 @@
return [[self class] dbConnection];
}
- (TSStorageManager *)storageManager
{
return [[self class] storageManager];
}
#pragma mark Class Methods
+ (YapDatabaseConnection *)dbConnection
{
return [TSStorageManager sharedManager].dbConnection;
return [self storageManager].dbConnection;
}
+ (TSStorageManager *)storageManager
{
return [TSStorageManager sharedManager];
}
+ (NSString *)collection

@ -0,0 +1,38 @@
// Created by Michael Kirk on 11/7/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
#import "TSContactThread.h"
#import "TSStorageManager+identityKeyStore.h"
#import <XCTest/XCTest.h>
NS_ASSUME_NONNULL_BEGIN
@interface TSContactThreadTest : XCTestCase
@property (nonatomic) TSContactThread *contactThread;
@end
@implementation TSContactThreadTest
- (void)setUp
{
self.contactThread = [TSContactThread getOrCreateThreadWithContactId:@"fake-contact-id"];
[self.contactThread.storageManager removeIdentityKeyForRecipient:self.contactThread.contactIdentifier];
}
- (void)testHasSafetyNumbersWithoutRemoteIdentity
{
XCTAssertFalse(self.contactThread.hasSafetyNumbers);
}
- (void)testHasSafetyNumbersWithRemoteIdentity
{
[self.contactThread.storageManager saveRemoteIdentity:[NSData new]
recipientId:self.contactThread.contactIdentifier];
XCTAssert(self.contactThread.hasSafetyNumbers);
}
@end
NS_ASSUME_NONNULL_END

@ -0,0 +1,23 @@
// Created by Michael Kirk on 11/7/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
#import "TSGroupThread.h"
#import <XCTest/XCTest.h>
NS_ASSUME_NONNULL_BEGIN
@interface TSGroupThreadTest : XCTestCase
@end
@implementation TSGroupThreadTest
- (void)testHasSafetyNumbers
{
TSGroupThread *groupThread = [TSGroupThread new];
XCTAssertFalse(groupThread.hasSafetyNumbers);
}
@end
NS_ASSUME_NONNULL_END
Loading…
Cancel
Save