Merge branch 'charlesmchen/buildBreakage'

This commit is contained in:
Matthew Chen 2018-10-15 15:08:14 -04:00
commit dbaa49d2f9
14 changed files with 83 additions and 25 deletions

View file

@ -18,10 +18,10 @@ enum PushNotificationRequestResult: String {
} }
class FailingTSAccountManager: TSAccountManager { class FailingTSAccountManager: TSAccountManager {
override public init(networkManager: TSNetworkManager, primaryStorage: OWSPrimaryStorage) { override public init(primaryStorage: OWSPrimaryStorage) {
AssertIsOnMainThread() AssertIsOnMainThread()
super.init(networkManager: networkManager, primaryStorage: primaryStorage) super.init(primaryStorage: primaryStorage)
self.phoneNumberAwaitingVerification = "+13235555555" self.phoneNumberAwaitingVerification = "+13235555555"
} }
@ -47,10 +47,6 @@ class VerifyingTSAccountManager: FailingTSAccountManager {
success: @escaping () -> Void, failure: @escaping (Error) -> Void) { success: @escaping () -> Void, failure: @escaping (Error) -> Void) {
success() success()
} }
override func registerForManualMessageFetching(success successBlock: @escaping () -> Void, failure failureBlock: @escaping (Error) -> Void) {
successBlock()
}
} }
class TokenObtainingTSAccountManager: VerifyingTSAccountManager { class TokenObtainingTSAccountManager: VerifyingTSAccountManager {
@ -58,11 +54,20 @@ class TokenObtainingTSAccountManager: VerifyingTSAccountManager {
class AccountManagerTest: SignalBaseTest { class AccountManagerTest: SignalBaseTest {
let tsAccountManager = FailingTSAccountManager(networkManager: TSNetworkManager.shared(), primaryStorage: OWSPrimaryStorage.shared()) override func setUp() {
var preferences = OWSPreferences() super.setUp()
let tsAccountManager = FailingTSAccountManager(primaryStorage: OWSPrimaryStorage.shared())
let sskEnvironment = SSKEnvironment.shared as! MockSSKEnvironment
sskEnvironment.tsAccountManager = tsAccountManager
}
override func tearDown() {
super.tearDown()
}
func testRegisterWhenEmptyCode() { func testRegisterWhenEmptyCode() {
let accountManager = AccountManager(textSecureAccountManager: tsAccountManager, preferences: self.preferences) let accountManager = AccountManager()
let expectation = self.expectation(description: "should fail") let expectation = self.expectation(description: "should fail")
@ -83,7 +88,7 @@ class AccountManagerTest: SignalBaseTest {
} }
func testRegisterWhenVerificationFails() { func testRegisterWhenVerificationFails() {
let accountManager = AccountManager(textSecureAccountManager: tsAccountManager, preferences: self.preferences) let accountManager = AccountManager()
let expectation = self.expectation(description: "should fail") let expectation = self.expectation(description: "should fail")
@ -103,9 +108,11 @@ class AccountManagerTest: SignalBaseTest {
} }
func testSuccessfulRegistration() { func testSuccessfulRegistration() {
let tsAccountManager = TokenObtainingTSAccountManager(networkManager: TSNetworkManager.shared(), primaryStorage: OWSPrimaryStorage.shared()) let tsAccountManager = TokenObtainingTSAccountManager(primaryStorage: OWSPrimaryStorage.shared())
let sskEnvironment = SSKEnvironment.shared as! MockSSKEnvironment
sskEnvironment.tsAccountManager = tsAccountManager
let accountManager = AccountManager(textSecureAccountManager: tsAccountManager, preferences: self.preferences) let accountManager = AccountManager()
let expectation = self.expectation(description: "should succeed") let expectation = self.expectation(description: "should succeed")
@ -121,7 +128,7 @@ class AccountManagerTest: SignalBaseTest {
} }
func testUpdatePushTokens() { func testUpdatePushTokens() {
let accountManager = AccountManager(textSecureAccountManager: tsAccountManager, preferences: self.preferences) let accountManager = AccountManager()
let expectation = self.expectation(description: "should fail") let expectation = self.expectation(description: "should fail")

View file

@ -68,9 +68,9 @@ class SSKProtoEnvelopeTest: SignalBaseTest {
func testParse_roundtrip() { func testParse_roundtrip() {
let builder = SSKProtoEnvelope.builder(type: SSKProtoEnvelope.SSKProtoEnvelopeType.prekeyBundle, let builder = SSKProtoEnvelope.builder(type: SSKProtoEnvelope.SSKProtoEnvelopeType.prekeyBundle,
source: "+13213214321",
sourceDevice: 1,
timestamp: 123) timestamp: 123)
builder.setSource("+13213214321")
builder.setSourceDevice(1)
let phonyContent = "phony data".data(using: .utf8)! let phonyContent = "phony data".data(using: .utf8)!

View file

@ -23,8 +23,8 @@ NS_ASSUME_NONNULL_BEGIN
SetCurrentAppContext([TestAppContext new]); SetCurrentAppContext([TestAppContext new]);
[MockEnvironment activate];
[MockSSKEnvironment activate]; [MockSSKEnvironment activate];
[MockEnvironment activate];
} }
- (void)tearDown - (void)tearDown

View file

@ -12,6 +12,13 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init; - (instancetype)init;
@property (nonatomic) OWSContactsManager *contactsManager;
@property (nonatomic) OWSPreferences *preferences;
@property (nonatomic) OWSContactsSyncing *contactsSyncing;
@property (nonatomic) OWSSounds *sounds;
@property (nonatomic) LockInteractionController *lockInteractionController;
@property (nonatomic) OWSWindowManager *windowManager;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View file

@ -9,6 +9,19 @@
static Environment *sharedEnvironment = nil; static Environment *sharedEnvironment = nil;
@interface Environment ()
@property (nonatomic) OWSContactsManager *contactsManager;
@property (nonatomic) OWSPreferences *preferences;
@property (nonatomic) OWSContactsSyncing *contactsSyncing;
@property (nonatomic) OWSSounds *sounds;
@property (nonatomic) LockInteractionController *lockInteractionController;
@property (nonatomic) OWSWindowManager *windowManager;
@end
#pragma mark -
@implementation Environment @implementation Environment
+ (Environment *)shared + (Environment *)shared

View file

@ -16,6 +16,10 @@ extern NSString *const kNSNotificationName_IdentityStateDidChange;
// number of bytes in a signal identity key, excluding the key-type byte. // number of bytes in a signal identity key, excluding the key-type byte.
extern const NSUInteger kIdentityKeyLength; extern const NSUInteger kIdentityKeyLength;
#ifdef DEBUG
extern const NSUInteger kStoredIdentityKeyLength;
#endif
@class OWSRecipientIdentity; @class OWSRecipientIdentity;
@class OWSStorage; @class OWSStorage;
@class SSKProtoVerified; @class SSKProtoVerified;

View file

@ -7,7 +7,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
extern const NSUInteger kGroupIdLength; extern const int32_t kGroupIdLength;
@interface TSGroupModel : TSYapDatabaseObject @interface TSGroupModel : TSYapDatabaseObject

View file

@ -8,7 +8,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
const NSUInteger kGroupIdLength = 16; const int32_t kGroupIdLength = 16;
@interface TSGroupModel () @interface TSGroupModel ()

View file

@ -70,9 +70,12 @@ public class OWSUDManagerImpl: NSObject, OWSUDManager {
// MARK: Recipient State // MARK: Recipient State
private let kUnidentifiedAccessCollection = "kUnidentifiedAccessCollection" private let kUnidentifiedAccessCollection = "kUnidentifiedAccessCollection"
var certificateValidator: SMKCertificateValidator
@objc @objc
public required init(primaryStorage: OWSPrimaryStorage) { public required init(primaryStorage: OWSPrimaryStorage) {
self.dbConnection = primaryStorage.newDatabaseConnection() self.dbConnection = primaryStorage.newDatabaseConnection()
self.certificateValidator = SMKCertificateDefaultValidator(trustRoot: OWSUDManagerImpl.trustRoot())
super.init() super.init()
@ -281,8 +284,6 @@ public class OWSUDManagerImpl: NSObject, OWSUDManager {
let anHourFromNowMs = nowMs + kHourInMs let anHourFromNowMs = nowMs + kHourInMs
do { do {
let certificateValidator = SMKCertificateDefaultValidator(trustRoot: trustRoot())
try certificateValidator.validate(senderCertificate: certificate, validationTime: anHourFromNowMs) try certificateValidator.validate(senderCertificate: certificate, validationTime: anHourFromNowMs)
return true return true
} catch { } catch {
@ -298,6 +299,11 @@ public class OWSUDManagerImpl: NSObject, OWSUDManager {
@objc @objc
public func trustRoot() -> ECPublicKey { public func trustRoot() -> ECPublicKey {
return OWSUDManagerImpl.trustRoot()
}
@objc
public class func trustRoot() -> ECPublicKey {
guard let trustRootData = NSData(fromBase64String: kUDTrustRoot) else { guard let trustRootData = NSData(fromBase64String: kUDTrustRoot) else {
// This exits. // This exits.
owsFail("Invalid trust root data.") owsFail("Invalid trust root data.")

View file

@ -21,6 +21,17 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) OWSMessageManager *messageManager; @property (nonatomic) OWSMessageManager *messageManager;
@property (nonatomic) OWSBlockingManager *blockingManager; @property (nonatomic) OWSBlockingManager *blockingManager;
@property (nonatomic) OWSIdentityManager *identityManager; @property (nonatomic) OWSIdentityManager *identityManager;
@property (nonatomic) id<OWSUDManager> udManager;
@property (nonatomic) OWSMessageDecrypter *messageDecrypter;
@property (nonatomic) OWSBatchMessageProcessor *batchMessageProcessor;
@property (nonatomic) OWSMessageReceiver *messageReceiver;
@property (nonatomic) TSSocketManager *socketManager;
@property (nonatomic) TSAccountManager *tsAccountManager;
@property (nonatomic) OWS2FAManager *ows2FAManager;
@property (nonatomic) OWSDisappearingMessagesJob *disappearingMessagesJob;
@property (nonatomic) ContactDiscoveryService *contactDiscoveryService;
@property (nonatomic) OWSReadReceiptManager *readReceiptManager;
@property (nonatomic) OWSOutgoingReceiptManager *outgoingReceiptManager;
@end @end

View file

@ -61,6 +61,12 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();
OWSAssertDebug(block); OWSAssertDebug(block);
if (CurrentAppContext().isRunningTests) {
// We don't need to an any "on app ready" work
// in the tests.
return;
}
if (self.isAppReady) { if (self.isAppReady) {
block(); block();
return; return;
@ -93,6 +99,7 @@ NS_ASSUME_NONNULL_BEGIN
NSArray<AppReadyBlock> *appReadyBlocks = [self.appReadyBlocks copy]; NSArray<AppReadyBlock> *appReadyBlocks = [self.appReadyBlocks copy];
[self.appReadyBlocks removeAllObjects]; [self.appReadyBlocks removeAllObjects];
for (AppReadyBlock block in appReadyBlocks) { for (AppReadyBlock block in appReadyBlocks) {
block(); block();
} }

View file

@ -2,10 +2,10 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
#import "TSContactThread.h"
#import "MockSSKEnvironment.h" #import "MockSSKEnvironment.h"
#import "OWSIdentityManager.h" #import "OWSIdentityManager.h"
#import "SSKBaseTestObjC.h" #import "SSKBaseTestObjC.h"
#import "TSContactThread.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)testHasSafetyNumbersWithRemoteIdentity - (void)testHasSafetyNumbersWithRemoteIdentity
{ {
[[OWSIdentityManager sharedManager] saveRemoteIdentity:[NSData new] [[OWSIdentityManager sharedManager] saveRemoteIdentity:[[NSMutableData alloc] initWithLength:kStoredIdentityKeyLength]
recipientId:self.contactThread.contactIdentifier]; recipientId:self.contactThread.contactIdentifier];
XCTAssert(self.contactThread.hasSafetyNumbers); XCTAssert(self.contactThread.hasSafetyNumbers);
} }

View file

@ -49,7 +49,8 @@
expiresInSeconds:0 expiresInSeconds:0
quotedMessage:nil quotedMessage:nil
contactShare:nil contactShare:nil
serverTimestamp:nil]; serverTimestamp:nil
wasReceivedByUD:NO];
[incomingMessage save]; [incomingMessage save];
TSOutgoingMessage *outgoingMessage = TSOutgoingMessage *outgoingMessage =
@ -102,7 +103,8 @@
expiresInSeconds:0 expiresInSeconds:0
quotedMessage:nil quotedMessage:nil
contactShare:nil contactShare:nil
serverTimestamp:nil]; serverTimestamp:nil
wasReceivedByUD:NO];
[incomingMessage save]; [incomingMessage save];
TSAttachmentStream *outgoingAttachment = TSAttachmentStream *outgoingAttachment =

View file

@ -55,7 +55,8 @@ NS_ASSUME_NONNULL_BEGIN
expiresInSeconds:0 expiresInSeconds:0
quotedMessage:nil quotedMessage:nil
contactShare:nil contactShare:nil
serverTimestamp:nil]; serverTimestamp:nil
wasReceivedByUD:NO];
[incomingMessage save]; [incomingMessage save];
} }