Add server certificate methods to UD manager.
This commit is contained in:
parent
b714e528f5
commit
7fd15d2fd9
|
@ -54,6 +54,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
OWSMessageManager *messageManager = [[OWSMessageManager alloc] initWithPrimaryStorage:primaryStorage];
|
||||
OWSBlockingManager *blockingManager = [[OWSBlockingManager alloc] initWithPrimaryStorage:primaryStorage];
|
||||
OWSIdentityManager *identityManager = [[OWSIdentityManager alloc] initWithPrimaryStorage:primaryStorage];
|
||||
id<OWSUDManager> udManager = [[OWSUDManagerImpl alloc] initWithPrimaryStorage:primaryStorage];
|
||||
|
||||
[Environment setShared:[[Environment alloc] initWithPreferences:preferences]];
|
||||
|
||||
|
@ -65,7 +66,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
networkManager:networkManager
|
||||
messageManager:messageManager
|
||||
blockingManager:blockingManager
|
||||
identityManager:identityManager]];
|
||||
identityManager:identityManager
|
||||
udManager:udManager]];
|
||||
|
||||
appSpecificSingletonBlock();
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public enum OWSSignalAddressError: Error {
|
||||
case assertionError(description: String)
|
||||
}
|
||||
|
||||
@objc
|
||||
public class OWSSignalAddress: NSObject {
|
||||
@objc
|
||||
public let recipientId: String
|
||||
|
||||
@objc
|
||||
public let deviceId: UInt
|
||||
|
||||
// MARK: Initializers
|
||||
|
||||
@objc public init(recipientId: String, deviceId: UInt) throws {
|
||||
guard recipientId.count > 0 else {
|
||||
throw OWSSignalAddressError.assertionError(description: "Invalid recipient id: \(deviceId)")
|
||||
}
|
||||
|
||||
guard deviceId > 0 else {
|
||||
throw OWSSignalAddressError.assertionError(description: "Invalid device id: \(deviceId)")
|
||||
}
|
||||
|
||||
self.recipientId = recipientId
|
||||
self.deviceId = deviceId
|
||||
}
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import PromiseKit
|
||||
|
||||
public enum OWSUDError: Error {
|
||||
case assertionError(description: String)
|
||||
}
|
||||
|
||||
@objc public protocol OWSUDManager: class {
|
||||
|
||||
@objc func isUDRecipientId(_ recipientId: String) -> Bool
|
||||
|
||||
// No-op if this recipient id is already marked as a "UD recipient".
|
||||
@objc func addUDRecipientId(_ recipientId: String)
|
||||
|
||||
// No-op if this recipient id is already marked as _NOT_ a "UD recipient".
|
||||
@objc func removeUDRecipientId(_ recipientId: String)
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
|
||||
@objc
|
||||
public class OWSUDManagerImpl: NSObject, OWSUDManager {
|
||||
|
||||
private let dbConnection: YapDatabaseConnection
|
||||
|
||||
private let kUDRecipientModeCollection = "kUDRecipientModeCollection"
|
||||
private let kUDCollection = "kUDCollection"
|
||||
private let kUDCurrentServerCertificateKey = "kUDCurrentServerCertificateKey"
|
||||
|
||||
@objc
|
||||
public required init(primaryStorage: OWSPrimaryStorage) {
|
||||
self.dbConnection = primaryStorage.newDatabaseConnection()
|
||||
|
||||
super.init()
|
||||
|
||||
SwiftSingletons.register(self)
|
||||
}
|
||||
|
||||
// MARK: - Singletons
|
||||
|
||||
private var networkManager: TSNetworkManager {
|
||||
return SSKEnvironment.shared.networkManager
|
||||
}
|
||||
|
||||
// MARK: - Recipient state
|
||||
|
||||
@objc
|
||||
public func isUDRecipientId(_ recipientId: String) -> Bool {
|
||||
return dbConnection.bool(forKey: recipientId, inCollection: kUDRecipientModeCollection, defaultValue: false)
|
||||
}
|
||||
|
||||
@objc
|
||||
public func addUDRecipientId(_ recipientId: String) {
|
||||
dbConnection.setBool(true, forKey: recipientId, inCollection: kUDRecipientModeCollection)
|
||||
}
|
||||
|
||||
@objc
|
||||
public func removeUDRecipientId(_ recipientId: String) {
|
||||
dbConnection.removeObject(forKey: recipientId, inCollection: kUDRecipientModeCollection)
|
||||
}
|
||||
|
||||
// MARK: - Server Certificate
|
||||
|
||||
#if DEBUG
|
||||
@objc
|
||||
public func hasServerCertificate() -> Bool {
|
||||
return serverCertificate() != nil
|
||||
}
|
||||
#endif
|
||||
|
||||
private func serverCertificate() -> Data? {
|
||||
guard let certificateData = dbConnection.object(forKey: kUDCurrentServerCertificateKey, inCollection: kUDCollection) as? Data else {
|
||||
return nil
|
||||
}
|
||||
// TODO: Parse certificate and ensure that it is still valid.
|
||||
return certificateData
|
||||
}
|
||||
|
||||
private func setServerCertificate(_ certificateData: Data) {
|
||||
dbConnection.setObject(certificateData, forKey: kUDCurrentServerCertificateKey, inCollection: kUDCollection)
|
||||
}
|
||||
|
||||
@objc
|
||||
public func ensureServerCertificateObjC(success:@escaping (Data) -> Void,
|
||||
failure:@escaping (Error) -> Void) {
|
||||
ensureServerCertificate()
|
||||
.then(execute: { certificateData in
|
||||
success(certificateData)
|
||||
})
|
||||
.catch(execute: { (error) in
|
||||
failure(error)
|
||||
}).retainUntilComplete()
|
||||
}
|
||||
|
||||
public func ensureServerCertificate() -> Promise<Data> {
|
||||
return Promise { fulfill, reject in
|
||||
// If there is an existing server certificate, use that.
|
||||
if let certificateData = serverCertificate() {
|
||||
fulfill(certificateData)
|
||||
return
|
||||
}
|
||||
// Try to obtain a new server certificate.
|
||||
requestServerCertificate()
|
||||
.then(execute: { certificateData in
|
||||
fulfill(certificateData)
|
||||
})
|
||||
.catch(execute: { (error) in
|
||||
reject(error)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private func requestServerCertificate() -> Promise<Data> {
|
||||
return Promise { fulfill, reject in
|
||||
let request = OWSRequestFactory.udServerCertificateRequest()
|
||||
self.networkManager.makeRequest(
|
||||
request,
|
||||
success: { (_: URLSessionDataTask?, responseObject: Any?) -> Void in
|
||||
do {
|
||||
let certificateData = try self.parseServerCertificateResponse(responseObject: responseObject)
|
||||
|
||||
fulfill(certificateData)
|
||||
} catch {
|
||||
|
||||
reject(error)
|
||||
}
|
||||
},
|
||||
failure: { (_: URLSessionDataTask?, error: Error?) in
|
||||
guard let error = error else {
|
||||
Logger.error("Missing error.")
|
||||
return
|
||||
}
|
||||
|
||||
reject(error)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private func parseServerCertificateResponse(responseObject: Any?) throws -> Data {
|
||||
guard let parser = ParamParser(responseObject: responseObject) else {
|
||||
throw OWSUDError.assertionError(description: "Invalid server certificate response")
|
||||
}
|
||||
|
||||
return try parser.requiredBase64EncodedData(key: "certificate")
|
||||
}
|
||||
}
|
|
@ -40,16 +40,10 @@ typedef NS_ENUM(NSUInteger, TSVerificationTransport) { TSVerificationTransportVo
|
|||
|
||||
+ (TSRequest *)attachmentRequestWithAttachmentId:(UInt64)attachmentId;
|
||||
|
||||
+ (TSRequest *)availablePreKeysCountRequest;
|
||||
|
||||
+ (TSRequest *)contactsIntersectionRequestWithHashesArray:(NSArray<NSString *> *)hashes;
|
||||
|
||||
+ (TSRequest *)currentSignedPreKeyRequest;
|
||||
|
||||
+ (TSRequest *)profileAvatarUploadFormRequest;
|
||||
|
||||
+ (TSRequest *)recipientPrekeyRequestWithRecipient:(NSString *)recipientNumber deviceId:(NSString *)deviceId;
|
||||
|
||||
+ (TSRequest *)registerForPushRequestWithPushIdentifier:(NSString *)identifier voipIdentifier:(NSString *)voipId;
|
||||
|
||||
+ (TSRequest *)updateAttributesRequestWithManualMessageFetching:(BOOL)enableManualMessageFetching;
|
||||
|
@ -63,12 +57,22 @@ typedef NS_ENUM(NSUInteger, TSVerificationTransport) { TSVerificationTransportVo
|
|||
messages:(NSArray *)messages
|
||||
timeStamp:(uint64_t)timeStamp;
|
||||
|
||||
#pragma mark - Prekeys
|
||||
|
||||
+ (TSRequest *)availablePreKeysCountRequest;
|
||||
|
||||
+ (TSRequest *)currentSignedPreKeyRequest;
|
||||
|
||||
+ (TSRequest *)recipientPrekeyRequestWithRecipient:(NSString *)recipientNumber deviceId:(NSString *)deviceId;
|
||||
|
||||
+ (TSRequest *)registerSignedPrekeyRequestWithSignedPreKeyRecord:(SignedPreKeyRecord *)signedPreKey;
|
||||
|
||||
+ (TSRequest *)registerPrekeysRequestWithPrekeyArray:(NSArray *)prekeys
|
||||
identityKey:(NSData *)identityKeyPublic
|
||||
signedPreKey:(SignedPreKeyRecord *)signedPreKey;
|
||||
|
||||
#pragma mark - CDS
|
||||
|
||||
+ (TSRequest *)remoteAttestationRequest:(ECKeyPair *)keyPair
|
||||
enclaveId:(NSString *)enclaveId
|
||||
authUsername:(NSString *)authUsername
|
||||
|
@ -87,6 +91,10 @@ typedef NS_ENUM(NSUInteger, TSVerificationTransport) { TSVerificationTransportVo
|
|||
+ (TSRequest *)remoteAttestationAuthRequest;
|
||||
+ (TSRequest *)cdsFeedbackRequestWithResult:(NSString *)result NS_SWIFT_NAME(cdsFeedbackRequest(result:));
|
||||
|
||||
#pragma mark - UD
|
||||
|
||||
+ (TSRequest *)udServerCertificateRequest;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -346,6 +346,14 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"PUT" parameters:@{}];
|
||||
}
|
||||
|
||||
#pragma mark - UD
|
||||
|
||||
+ (TSRequest *)udServerCertificateRequest
|
||||
{
|
||||
NSString *path = @"/v1/certificate/delivery";
|
||||
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"GET" parameters:@{}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -17,6 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
@protocol NotificationsProtocol;
|
||||
@protocol OWSCallMessageHandler;
|
||||
@protocol ProfileManagerProtocol;
|
||||
@protocol OWSUDManager;
|
||||
|
||||
@interface SSKEnvironment : NSObject
|
||||
|
||||
|
@ -28,7 +29,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
networkManager:(TSNetworkManager *)networkManager
|
||||
messageManager:(OWSMessageManager *)messageManager
|
||||
blockingManager:(OWSBlockingManager *)blockingManager
|
||||
identityManager:(OWSIdentityManager *)identityManager NS_DESIGNATED_INITIALIZER;
|
||||
identityManager:(OWSIdentityManager *)identityManager
|
||||
udManager:(id<OWSUDManager>)udManager NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
|
@ -50,6 +52,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
@property (nonatomic, readonly) OWSMessageManager *messageManager;
|
||||
@property (nonatomic, readonly) OWSBlockingManager *blockingManager;
|
||||
@property (nonatomic, readonly) OWSIdentityManager *identityManager;
|
||||
@property (nonatomic, readonly) id<OWSUDManager> udManager;
|
||||
|
||||
// This property is configured after Environment is created.
|
||||
@property (atomic, nullable) id<OWSCallMessageHandler> callMessageHandler;
|
||||
|
|
|
@ -21,6 +21,7 @@ static SSKEnvironment *sharedSSKEnvironment;
|
|||
@property (nonatomic) OWSMessageManager *messageManager;
|
||||
@property (nonatomic) OWSBlockingManager *blockingManager;
|
||||
@property (nonatomic) OWSIdentityManager *identityManager;
|
||||
@property (nonatomic) id<OWSUDManager> udManager;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -41,6 +42,7 @@ static SSKEnvironment *sharedSSKEnvironment;
|
|||
messageManager:(OWSMessageManager *)messageManager
|
||||
blockingManager:(OWSBlockingManager *)blockingManager
|
||||
identityManager:(OWSIdentityManager *)identityManager
|
||||
udManager:(id<OWSUDManager>)udManager
|
||||
{
|
||||
self = [super init];
|
||||
if (!self) {
|
||||
|
@ -56,6 +58,7 @@ static SSKEnvironment *sharedSSKEnvironment;
|
|||
OWSAssertDebug(messageManager);
|
||||
OWSAssertDebug(blockingManager);
|
||||
OWSAssertDebug(identityManager);
|
||||
OWSAssertDebug(udManager);
|
||||
|
||||
_contactsManager = contactsManager;
|
||||
_messageSender = messageSender;
|
||||
|
@ -66,6 +69,7 @@ static SSKEnvironment *sharedSSKEnvironment;
|
|||
_messageManager = messageManager;
|
||||
_blockingManager = blockingManager;
|
||||
_identityManager = identityManager;
|
||||
_udManager = udManager;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#import "OWSIdentityManager.h"
|
||||
#import "OWSMessageManager.h"
|
||||
#import "OWSPrimaryStorage.h"
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
@ -47,6 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
OWSMessageManager *messageManager = [[OWSMessageManager alloc] initWithPrimaryStorage:primaryStorage];
|
||||
OWSBlockingManager *blockingManager = [[OWSBlockingManager alloc] initWithPrimaryStorage:primaryStorage];
|
||||
OWSIdentityManager *identityManager = [[OWSIdentityManager alloc] initWithPrimaryStorage:primaryStorage];
|
||||
id<OWSUDManager> udManager = [[OWSUDManagerImpl alloc] initWithPrimaryStorage:primaryStorage];
|
||||
|
||||
self = [super initWithContactsManager:contactsManager
|
||||
messageSender:messageSender
|
||||
|
@ -56,7 +58,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
networkManager:networkManager
|
||||
messageManager:messageManager
|
||||
blockingManager:blockingManager
|
||||
identityManager:identityManager];
|
||||
identityManager:identityManager
|
||||
udManager:udManager];
|
||||
if (!self) {
|
||||
return nil;
|
||||
}
|
||||
|
|
|
@ -48,8 +48,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
- (void)setProfileKeyData:(NSData *)profileKey forRecipientId:(NSString *)recipientId
|
||||
{
|
||||
OWSAES256Key *key = [OWSAES256Key keyWithData:profileKey];
|
||||
NSAssert(key, @"Unable to build key. Invalid key data?");
|
||||
OWSAES256Key *_Nullable key = [OWSAES256Key keyWithData:profileKey];
|
||||
OWSAssert(key);
|
||||
self.profileKeys[recipientId] = key;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
#if DEBUG
|
||||
|
||||
@objc
|
||||
public class OWSFakeUDManager: NSObject, OWSUDManager {
|
||||
|
||||
private var udRecipientSet = Set<String>()
|
||||
|
||||
// MARK: -
|
||||
|
||||
@objc
|
||||
public func isUDRecipientId(_ recipientId: String) -> Bool {
|
||||
return udRecipientSet.contains(recipientId)
|
||||
}
|
||||
|
||||
@objc
|
||||
public func addUDRecipientId(_ recipientId: String) {
|
||||
udRecipientSet.insert(recipientId)
|
||||
}
|
||||
|
||||
@objc
|
||||
public func removeUDRecipientId(_ recipientId: String) {
|
||||
udRecipientSet.remove(recipientId)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,5 +0,0 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
|
@ -3,7 +3,7 @@
|
|||
//
|
||||
|
||||
#import "OWSPrimaryStorage+SignedPreKeyStore.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import "TSPreKeyManager.h"
|
||||
#import <AxolotlKit/SignedPrekeyRecord.h>
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
|||
|
||||
@end
|
||||
|
||||
@interface SignedPreKeyDeletionTests : SSKBaseTest
|
||||
@interface SignedPreKeyDeletionTests : SSKBaseTestObjC
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
//
|
||||
|
||||
#import "TSAttributes.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import "TSAccountManager.h"
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
@interface TSAttributesTest : SSKBaseTest
|
||||
@interface TSAttributesTest : SSKBaseTestObjC
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -3,13 +3,16 @@
|
|||
//
|
||||
|
||||
#import "Contact.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
|
||||
//#import "SignalServiceKit_Unit_Tests-Swift.h"
|
||||
//#import <SignalServiceKit_Unit_Tests/SignalServiceKit_Unit_Tests-Swift.h>
|
||||
|
||||
@import Contacts;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface ContactSortingTest : SSKBaseTest
|
||||
@interface ContactSortingTest : SSKBaseTestObjC
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
//
|
||||
|
||||
#import "OWSDisappearingMessagesConfiguration.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface OWSDisappearingMessagesConfigurationTest : SSKBaseTest
|
||||
@interface OWSDisappearingMessagesConfigurationTest : SSKBaseTestObjC
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
//
|
||||
|
||||
#import "PhoneNumber.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
|
||||
@interface PhoneNumberTest : SSKBaseTest
|
||||
@interface PhoneNumberTest : SSKBaseTestObjC
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
//
|
||||
|
||||
#import "PhoneNumberUtil.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
|
||||
@interface PhoneNumberUtilTest : SSKBaseTest
|
||||
@interface PhoneNumberUtilTest : SSKBaseTestObjC
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#import "SignalRecipient.h"
|
||||
#import "MockSSKEnvironment.h"
|
||||
#import "OWSPrimaryStorage.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import "TSAccountManager.h"
|
||||
#import "TestAppContext.h"
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
@end
|
||||
|
||||
@interface SignalRecipientTest : SSKBaseTest
|
||||
@interface SignalRecipientTest : SSKBaseTestObjC
|
||||
|
||||
@property (nonatomic) NSString *localNumber;
|
||||
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
#import "TSContactThread.h"
|
||||
#import "MockSSKEnvironment.h"
|
||||
#import "OWSIdentityManager.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TSContactThreadTest : SSKBaseTest
|
||||
@interface TSContactThreadTest : SSKBaseTestObjC
|
||||
|
||||
@property (nonatomic) TSContactThread *contactThread;
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@
|
|||
//
|
||||
|
||||
#import "TSGroupThread.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TSGroupThreadTest : SSKBaseTest
|
||||
@interface TSGroupThreadTest : SSKBaseTestObjC
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#import "OWSDevice.h"
|
||||
#import "OWSPrimaryStorage.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import "TSAttachmentStream.h"
|
||||
#import "TSContactThread.h"
|
||||
#import "TSIncomingMessage.h"
|
||||
|
@ -12,7 +12,7 @@
|
|||
#import "TestAppContext.h"
|
||||
#import <SignalServiceKit/SignalServiceKit-Swift.h>
|
||||
|
||||
@interface TSThreadTest : SSKBaseTest
|
||||
@interface TSThreadTest : SSKBaseTestObjC
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#import "OWSDeviceProvisioningCodeService.h"
|
||||
#import "OWSDeviceProvisioningService.h"
|
||||
#import "OWSFakeNetworkManager.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import "TSNetworkManager.h"
|
||||
|
||||
@interface OWSFakeDeviceProvisioningService : OWSDeviceProvisioningService
|
||||
|
@ -48,7 +48,7 @@
|
|||
|
||||
@end
|
||||
|
||||
@interface OWSDeviceProvisionerTest : SSKBaseTest
|
||||
@interface OWSDeviceProvisionerTest : SSKBaseTestObjC
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import <Curve25519Kit/Curve25519.h>
|
||||
#import <SignalCoreKit/Cryptography.h>
|
||||
#import <SignalServiceKit/OWSProvisioningCipher.h>
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
@end
|
||||
|
||||
@interface OWSProvisioningCipherTest : SSKBaseTest
|
||||
@interface OWSProvisioningCipherTest : SSKBaseTestObjC
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SSKBaseTest.h"
|
||||
#import "TSMessage.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import "TSAttachmentStream.h"
|
||||
#import "TSContactThread.h"
|
||||
#import "TSMessage.h"
|
||||
#import <SignalCoreKit/NSDate+OWS.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TSMessageTest : SSKBaseTest
|
||||
@interface TSMessageTest : SSKBaseTestObjC
|
||||
|
||||
@property TSThread *thread;
|
||||
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
#import "TSOutgoingMessage.h"
|
||||
#import "OWSPrimaryStorage.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import "TSContactThread.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TSOutgoingMessageTest : SSKBaseTest
|
||||
@interface TSOutgoingMessageTest : SSKBaseTestObjC
|
||||
|
||||
@property (nonatomic) TSContactThread *thread;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#import "MockSSKEnvironment.h"
|
||||
#import "OWSDisappearingMessagesFinder.h"
|
||||
#import "OWSPrimaryStorage.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import "TSContactThread.h"
|
||||
#import "TSMessage.h"
|
||||
#import "TestAppContext.h"
|
||||
|
@ -24,7 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
#pragma mark -
|
||||
|
||||
@interface OWSDisappearingMessageFinderTest : SSKBaseTest
|
||||
@interface OWSDisappearingMessageFinderTest : SSKBaseTestObjC
|
||||
|
||||
@property (nonatomic, nullable) OWSDisappearingMessagesFinder *finder;
|
||||
@property (nonatomic, nullable) TSThread *thread;
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSDisappearingMessagesJob.h"
|
||||
#import "OWSDisappearingMessagesConfiguration.h"
|
||||
#import "OWSDisappearingMessagesFinder.h"
|
||||
#import "OWSDisappearingMessagesJob.h"
|
||||
#import "OWSFakeContactsManager.h"
|
||||
#import "OWSPrimaryStorage.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import "TSContactThread.h"
|
||||
#import "TSMessage.h"
|
||||
#import <SignalCoreKit/NSDate+OWS.h>
|
||||
|
@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@end
|
||||
|
||||
@interface OWSDisappearingMessagesJobTest : SSKBaseTest
|
||||
@interface OWSDisappearingMessagesJobTest : SSKBaseTestObjC
|
||||
|
||||
@property TSThread *thread;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#import "OWSIncomingMessageFinder.h"
|
||||
#import "OWSDevice.h"
|
||||
#import "OWSPrimaryStorage.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import "TSContactThread.h"
|
||||
#import "TSIncomingMessage.h"
|
||||
|
||||
|
@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@end
|
||||
|
||||
@interface OWSIncomingMessageFinderTest : SSKBaseTest
|
||||
@interface OWSIncomingMessageFinderTest : SSKBaseTestObjC
|
||||
|
||||
@property (nonatomic) NSString *sourceId;
|
||||
@property (nonatomic) TSThread *thread;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#import "OWSIdentityManager.h"
|
||||
#import "OWSMessageSender.h"
|
||||
#import "OWSPrimaryStorage.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import "TSGroupThread.h"
|
||||
#import "TSNetworkManager.h"
|
||||
#import <SignalCoreKit/Cryptography.h>
|
||||
|
@ -42,7 +42,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
#pragma mark -
|
||||
|
||||
@interface OWSMessageManagerTest : SSKBaseTest
|
||||
@interface OWSMessageManagerTest : SSKBaseTestObjC
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#import "OWSFakeNetworkManager.h"
|
||||
#import "OWSPrimaryStorage.h"
|
||||
#import "OWSUploadOperation.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import "TSAccountManager.h"
|
||||
#import "TSContactThread.h"
|
||||
#import "TSGroupModel.h"
|
||||
|
@ -206,7 +206,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
#pragma mark -
|
||||
|
||||
@interface OWSMessageSenderTest : SSKBaseTest
|
||||
@interface OWSMessageSenderTest : SSKBaseTestObjC
|
||||
|
||||
@property (nonatomic) TSThread *thread;
|
||||
@property (nonatomic) TSOutgoingMessage *expiringMessage;
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SignalServiceKit
|
||||
import XCTest
|
||||
|
||||
class OWSSignalAddressTest: SSKBaseTestSwift {
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
func testInitializer() {
|
||||
let recipientId = "+13213214321"
|
||||
let deviceId: UInt = 1
|
||||
let address = try! OWSSignalAddress(recipientId: recipientId, deviceId: deviceId)
|
||||
XCTAssertEqual(address.recipientId, recipientId)
|
||||
XCTAssertEqual(address.deviceId, deviceId)
|
||||
}
|
||||
|
||||
func testInitializer_badRecipientId() {
|
||||
let recipientId = ""
|
||||
let deviceId: UInt = 1
|
||||
XCTAssertThrowsError(try OWSSignalAddress(recipientId: recipientId, deviceId: deviceId))
|
||||
}
|
||||
|
||||
func testInitializer_badDeviceId() {
|
||||
let recipientId = "+13213214321"
|
||||
let deviceId: UInt = 0
|
||||
XCTAssertThrowsError(try OWSSignalAddress(recipientId: recipientId, deviceId: deviceId))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import Foundation
|
||||
import SignalServiceKit
|
||||
|
||||
class OWSUDManagerTest: SSKBaseTestSwift {
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
// Put setup code here. This method is called before the invocation of each test method in the class.
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
func testInitializer() {
|
||||
}
|
||||
}
|
|
@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
#ifdef DEBUG
|
||||
|
||||
@interface SSKBaseTest : XCTestCase
|
||||
@interface SSKBaseTestObjC : XCTestCase
|
||||
|
||||
- (void)readWithBlock:(void (^)(YapDatabaseReadTransaction *transaction))block;
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import "OWSPrimaryStorage.h"
|
||||
#import "SSKEnvironment.h"
|
||||
#import "TestAppContext.h"
|
||||
|
@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
#ifdef DEBUG
|
||||
|
||||
@implementation SSKBaseTest
|
||||
@implementation SSKBaseTestObjC
|
||||
|
||||
- (void)setUp
|
||||
{
|
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import SignalServiceKit
|
||||
|
||||
@objc
|
||||
public class SSKBaseTestSwift: XCTestCase {
|
||||
|
||||
@objc
|
||||
public override func setUp() {
|
||||
super.setUp()
|
||||
|
||||
ClearCurrentAppContextForTests()
|
||||
SetCurrentAppContext(TestAppContext())
|
||||
|
||||
MockSSKEnvironment.activate()
|
||||
}
|
||||
|
||||
@objc
|
||||
public override func tearDown() {
|
||||
super.tearDown()
|
||||
|
||||
SSKEnvironment.shared.primaryStorage.closeForTests()
|
||||
|
||||
ClearCurrentAppContextForTests()
|
||||
SSKEnvironment.clearSharedForTests()
|
||||
}
|
||||
|
||||
@objc
|
||||
public func read(_ block: @escaping (YapDatabaseReadTransaction) -> Swift.Void) {
|
||||
return OWSPrimaryStorage.shared().dbReadConnection.read(block)
|
||||
}
|
||||
|
||||
@objc
|
||||
public func readWrite(_ block: @escaping (YapDatabaseReadWriteTransaction) -> Swift.Void) {
|
||||
return OWSPrimaryStorage.shared().dbReadWriteConnection.readWrite(block)
|
||||
}
|
||||
}
|
|
@ -3,10 +3,10 @@
|
|||
//
|
||||
|
||||
#import "OWSFingerprint.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import <Curve25519Kit/Curve25519.h>
|
||||
|
||||
@interface OWSFingerprintTest : SSKBaseTest
|
||||
@interface OWSFingerprintTest : SSKBaseTestObjC
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#import "OWSIdentityManager.h"
|
||||
#import "OWSPrimaryStorage.h"
|
||||
#import "OWSRecipientIdentity.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import "SSKEnvironment.h"
|
||||
#import "YapDatabaseConnection+OWS.h"
|
||||
#import <Curve25519Kit/Curve25519.h>
|
||||
|
@ -14,7 +14,7 @@
|
|||
|
||||
extern NSString *const OWSPrimaryStorageTrustedKeysCollection;
|
||||
|
||||
@interface TSStorageIdentityKeyStoreTests : SSKBaseTest
|
||||
@interface TSStorageIdentityKeyStoreTests : SSKBaseTestObjC
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
//
|
||||
|
||||
#import "OWSPrimaryStorage+PreKeyStore.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
|
||||
@interface TSStoragePreKeyStoreTests : SSKBaseTest
|
||||
@interface TSStoragePreKeyStoreTests : SSKBaseTestObjC
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
//
|
||||
|
||||
#import "OWSAnalytics.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import <SignalCoreKit/NSData+OWS.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface OWSAnalyticsTests : SSKBaseTest
|
||||
@interface OWSAnalyticsTests : SSKBaseTestObjC
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
//
|
||||
|
||||
#import "OWSPrimaryStorage.h"
|
||||
#import "SSKBaseTest.h"
|
||||
#import "SSKBaseTestObjC.h"
|
||||
#import "TSContactThread.h"
|
||||
#import "TSGroupThread.h"
|
||||
#import "TSIncomingMessage.h"
|
||||
|
@ -13,7 +13,7 @@
|
|||
#import "YapDatabaseConnection+OWS.h"
|
||||
#import <SignalCoreKit/Cryptography.h>
|
||||
|
||||
@interface TSMessageStorageTests : SSKBaseTest
|
||||
@interface TSMessageStorageTests : SSKBaseTestObjC
|
||||
|
||||
@property TSContactThread *thread;
|
||||
|
||||
|
|
Loading…
Reference in New Issue