Fix broken tests.

This commit is contained in:
Matthew Chen 2018-09-07 17:01:27 -04:00
parent 68714b296c
commit 62c55c9cfb
11 changed files with 146 additions and 121 deletions

View File

@ -155,6 +155,7 @@
347850711FDAEB17007B8332 /* OWSUserProfile.m in Sources */ = {isa = PBXBuildFile; fileRef = 3478506F1FDAEB16007B8332 /* OWSUserProfile.m */; };
347850721FDAEB17007B8332 /* OWSUserProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 347850701FDAEB16007B8332 /* OWSUserProfile.h */; settings = {ATTRIBUTES = (Public, ); }; };
34843B2421432293004DED45 /* SignalBaseTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34843B2221432292004DED45 /* SignalBaseTest.m */; };
34843B26214327C9004DED45 /* OWSOrphanedDataCleanerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 34843B25214327C9004DED45 /* OWSOrphanedDataCleanerTest.m */; };
348570A820F67575004FF32B /* OWSMessageHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 348570A620F67574004FF32B /* OWSMessageHeaderView.m */; };
348BB25D20A0C5530047AEC2 /* ContactShareViewHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 348BB25C20A0C5530047AEC2 /* ContactShareViewHelper.swift */; };
3491D9A121022DB7001EF5A1 /* CDSSigningCertificateTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3491D9A021022DB7001EF5A1 /* CDSSigningCertificateTest.m */; };
@ -793,6 +794,7 @@
347850701FDAEB16007B8332 /* OWSUserProfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSUserProfile.h; sourceTree = "<group>"; };
34843B2221432292004DED45 /* SignalBaseTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SignalBaseTest.m; sourceTree = "<group>"; };
34843B2321432293004DED45 /* SignalBaseTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SignalBaseTest.h; sourceTree = "<group>"; };
34843B25214327C9004DED45 /* OWSOrphanedDataCleanerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSOrphanedDataCleanerTest.m; sourceTree = "<group>"; };
348570A620F67574004FF32B /* OWSMessageHeaderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSMessageHeaderView.m; sourceTree = "<group>"; };
348570A720F67574004FF32B /* OWSMessageHeaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMessageHeaderView.h; sourceTree = "<group>"; };
348BB25C20A0C5530047AEC2 /* ContactShareViewHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContactShareViewHelper.swift; sourceTree = "<group>"; };
@ -2363,8 +2365,8 @@
B660F6A21C29868000687D6E /* util */ = {
isa = PBXGroup;
children = (
3491D9A021022DB7001EF5A1 /* CDSSigningCertificateTest.m */,
3421981B21061D2E00C57195 /* ByteParserTest.swift */,
3491D9A021022DB7001EF5A1 /* CDSSigningCertificateTest.m */,
45E7A6A61E71CA7E00D44FB5 /* DisplayableTextFilterTest.swift */,
B660F6AA1C29868000687D6E /* ExceptionsTest.h */,
B660F6AB1C29868000687D6E /* ExceptionsTest.m */,
@ -2373,6 +2375,7 @@
455AC69D1F4F8B0300134004 /* ImageCacheTest.swift */,
34DB0BEB2011548A007B313F /* OWSDatabaseConverterTest.h */,
34DB0BEC2011548B007B313F /* OWSDatabaseConverterTest.m */,
34843B25214327C9004DED45 /* OWSOrphanedDataCleanerTest.m */,
45666F571D9B2880008FE134 /* OWSScrubbingLogFormatterTest.m */,
34E8A8D02085238900B272B1 /* ProtoParsingTest.m */,
45360B8F1F9527DA00FA666C /* SearcherTest.swift */,
@ -3473,6 +3476,7 @@
340B02BA1FA0D6C700F9CFEC /* ConversationViewItemTest.m in Sources */,
458E383A1D6699FA0094BD24 /* OWSDeviceProvisioningURLParserTest.m in Sources */,
3421981C21061D2E00C57195 /* ByteParserTest.swift in Sources */,
34843B26214327C9004DED45 /* OWSOrphanedDataCleanerTest.m in Sources */,
45360B901F9527DA00FA666C /* SearcherTest.swift in Sources */,
B660F7561C29988E00687D6E /* PushManager.m in Sources */,
34DB0BED2011548B007B313F /* OWSDatabaseConverterTest.m in Sources */,

View File

@ -3,3 +3,4 @@
//
#import "Signal-Bridging-Header.h"
#import "SignalBaseTest.h"

View File

@ -2,21 +2,21 @@
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSOrphanedDataCleaner.h"
#import "OWSDevice.h"
#import "OWSOrphanDataCleaner.h"
#import "OWSPrimaryStorage.h"
#import "SSKBaseTest.h"
#import "TSAttachmentStream.h"
#import "TSContactThread.h"
#import "TSIncomingMessage.h"
@interface OWSOrphanedDataCleanerTest : SSKBaseTest
@interface OWSOrphanDataCleanerTest : SSKBaseTest
@end
#pragma mark -
@implementation OWSOrphanedDataCleanerTest
@implementation OWSOrphanDataCleanerTest
- (void)setUp
{
@ -43,7 +43,7 @@
- (NSUInteger)numberOfItemsInAttachmentsFolder
{
return [OWSOrphanedDataCleaner filePathsInAttachmentsFolder].count;
return [OWSOrphanDataCleaner filePathsInAttachmentsFolder].count;
}
- (TSIncomingMessage *)createIncomingMessageWithThread:(TSThread *)thread
@ -91,7 +91,7 @@
XCTAssertEqual(1, [TSIncomingMessage numberOfKeysInCollection]);
XCTestExpectation *expectation = [self expectationWithDescription:@"Cleanup"];
[OWSOrphanedDataCleaner auditAndCleanupAsync:^{
[OWSOrphanDataCleaner auditAndCleanupAsync:^{
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5.0
@ -114,7 +114,7 @@
XCTAssertEqual(1, [TSIncomingMessage numberOfKeysInCollection]);
XCTestExpectation *expectation = [self expectationWithDescription:@"Cleanup"];
[OWSOrphanedDataCleaner auditAndCleanupAsync:^{
[OWSOrphanDataCleaner auditAndCleanupAsync:^{
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5.0
@ -142,7 +142,7 @@
// Do multiple cleanup passes.
for (int i = 0; i < 2; i++) {
XCTestExpectation *expectation = [self expectationWithDescription:@"Cleanup"];
[OWSOrphanedDataCleaner auditAndCleanupAsync:^{
[OWSOrphanDataCleaner auditAndCleanupAsync:^{
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5.0
@ -174,7 +174,7 @@
XCTAssertEqual(1, [self numberOfItemsInAttachmentsFolder]);
XCTestExpectation *expectation = [self expectationWithDescription:@"Cleanup"];
[OWSOrphanedDataCleaner auditAndCleanupAsync:^{
[OWSOrphanDataCleaner auditAndCleanupAsync:^{
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5.0
@ -203,7 +203,7 @@
XCTAssertEqual(1, [self numberOfItemsInAttachmentsFolder]);
XCTestExpectation *expectation = [self expectationWithDescription:@"Cleanup"];
[OWSOrphanedDataCleaner auditAndCleanupAsync:^{
[OWSOrphanDataCleaner auditAndCleanupAsync:^{
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5.0

View File

@ -44,29 +44,31 @@
- (void)testIncrementalMessageNumbers
{
__block NSInteger messageInt;
NSString *body = @"I don't see myself as a hero because what I'm doing is self-interested: I don't want to live in a world where there's no privacy and therefore no room for intellectual exploration and creativity.";
[[OWSPrimaryStorage sharedManager].newDatabaseConnection readWriteWithBlock:^(
YapDatabaseReadWriteTransaction *transaction) {
NSString* messageId;
for (uint64_t i = 0; i<50; i++) {
TSOutgoingMessage *newMessage =
[[TSOutgoingMessage alloc] initWithTimestamp:i inThread:self.thread messageBody:body];
[newMessage saveWithTransaction:transaction];
if (i == 0) {
messageId = newMessage.uniqueId;
NSString *body
= @"I don't see myself as a hero because what I'm doing is self-interested: I don't want to live in a world "
@"where there's no privacy and therefore no room for intellectual exploration and creativity.";
[[OWSPrimaryStorage sharedManager].newDatabaseConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
NSString *messageId;
for (uint64_t i = 0; i < 50; i++) {
TSOutgoingMessage *newMessage =
[[TSOutgoingMessage alloc] initWithTimestamp:i inThread:self.thread messageBody:body];
[newMessage saveWithTransaction:transaction];
if (i == 0) {
messageId = newMessage.uniqueId;
}
}
}
messageInt = [messageId integerValue];
for (NSInteger i = messageInt; i < messageInt+50; i++) {
TSOutgoingMessage *message =
[TSOutgoingMessage fetchObjectWithUniqueID:[@(i) stringValue] transaction:transaction];
XCTAssert(message != nil);
XCTAssert(message.body == body);
}
}];
messageInt = [messageId integerValue];
for (NSInteger i = messageInt; i < messageInt + 50; i++) {
TSOutgoingMessage *message =
[TSOutgoingMessage fetchObjectWithUniqueID:[@(i) stringValue] transaction:transaction];
XCTAssert(message != nil);
XCTAssert(message.body == body);
}
}];
[[OWSPrimaryStorage sharedManager].newDatabaseConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
@ -89,8 +91,11 @@
{
__block NSString *messageId;
uint64_t timestamp = 666;
NSString *body = @"A child born today will grow up with no conception of privacy at all. Theyll never know what it means to have a private moment to themselves an unrecorded, unanalyzed thought. And thats a problem because privacy matters; privacy is what allows us to determine who we are and who we want to be.";
NSString *body
= @"A child born today will grow up with no conception of privacy at all. Theyll never know what it means to "
@"have a private moment to themselves an unrecorded, unanalyzed thought. And thats a problem because "
@"privacy matters; privacy is what allows us to determine who we are and who we want to be.";
TSIncomingMessage *newMessage = [[TSIncomingMessage alloc] initWithTimestamp:timestamp
inThread:self.thread
@ -114,7 +119,10 @@
- (void)testMessagesDeletedOnThreadDeletion
{
NSString *body = @"A child born today will grow up with no conception of privacy at all. Theyll never know what it means to have a private moment to themselves an unrecorded, unanalyzed thought. And thats a problem because privacy matters; privacy is what allows us to determine who we are and who we want to be.";
NSString *body
= @"A child born today will grow up with no conception of privacy at all. Theyll never know what it means to "
@"have a private moment to themselves an unrecorded, unanalyzed thought. And thats a problem because "
@"privacy matters; privacy is what allows us to determine who we are and who we want to be.";
NSMutableArray<TSIncomingMessage *> *messages = [NSMutableArray new];
for (int i = 0; i < 10; i++) {
@ -149,7 +157,10 @@
- (void)testGroupMessagesDeletedOnThreadDeletion
{
NSString *body = @"A child born today will grow up with no conception of privacy at all. Theyll never know what it means to have a private moment to themselves an unrecorded, unanalyzed thought. And thats a problem because privacy matters; privacy is what allows us to determine who we are and who we want to be.";
NSString *body
= @"A child born today will grow up with no conception of privacy at all. Theyll never know what it means to "
@"have a private moment to themselves an unrecorded, unanalyzed thought. And thats a problem because "
@"privacy matters; privacy is what allows us to determine who we are and who we want to be.";
__block TSGroupThread *thread;
[[OWSPrimaryStorage sharedManager].dbReadWriteConnection readWriteWithBlock:^(

View File

@ -17,34 +17,46 @@
@implementation TSStorageIdentityKeyStoreTests
- (void)setUp {
- (void)setUp
{
[super setUp];
[[OWSPrimaryStorage sharedManager] purgeCollection:OWSPrimaryStorageTrustedKeysCollection];
[OWSRecipientIdentity removeAllObjectsInCollection];
}
- (void)tearDown {
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testNewEmptyKey {
- (void)testNewEmptyKey
{
NSData *newKey = [SecurityUtils generateRandomBytes:32];
NSString *recipientId = @"test@gmail.com";
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey
recipientId:recipientId
direction:TSMessageDirectionOutgoing]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey
recipientId:recipientId
direction:TSMessageDirectionIncoming]);
}
- (void)testAlreadyRegisteredKey {
- (void)testAlreadyRegisteredKey
{
NSData *newKey = [SecurityUtils generateRandomBytes:32];
NSString *recipientId = @"test@gmail.com";
[[OWSIdentityManager sharedManager] saveRemoteIdentity:newKey recipientId:recipientId];
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey
recipientId:recipientId
direction:TSMessageDirectionOutgoing]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey
recipientId:recipientId
direction:TSMessageDirectionIncoming]);
}
@ -54,20 +66,29 @@
NSString *recipientId = @"test@protonmail.com";
[[OWSIdentityManager sharedManager] saveRemoteIdentity:originalKey recipientId:recipientId];
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:originalKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:originalKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:originalKey
recipientId:recipientId
direction:TSMessageDirectionOutgoing]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:originalKey
recipientId:recipientId
direction:TSMessageDirectionIncoming]);
NSData *otherKey = [SecurityUtils generateRandomBytes:32];
XCTAssertFalse([[OWSIdentityManager sharedManager] isTrustedIdentityKey:otherKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:otherKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
XCTAssertFalse([[OWSIdentityManager sharedManager] isTrustedIdentityKey:otherKey
recipientId:recipientId
direction:TSMessageDirectionOutgoing]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:otherKey
recipientId:recipientId
direction:TSMessageDirectionIncoming]);
}
- (void)testIdentityKey {
- (void)testIdentityKey
{
[[OWSIdentityManager sharedManager] generateNewIdentityKey];
XCTAssert([[[OWSIdentityManager sharedManager] identityKeyPair].publicKey length] == 32);
}

View File

@ -11,17 +11,20 @@
@implementation TSStoragePreKeyStoreTests
- (void)setUp {
- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown {
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testGeneratingAndStoringPreKeys {
- (void)testGeneratingAndStoringPreKeys
{
NSArray *generatedKeys = [[OWSPrimaryStorage sharedManager] generatePreKeyRecords];
@ -29,7 +32,7 @@
[[OWSPrimaryStorage sharedManager] storePreKeyRecords:generatedKeys];
PreKeyRecord *lastPreKeyRecord = [generatedKeys lastObject];
PreKeyRecord *lastPreKeyRecord = [generatedKeys lastObject];
PreKeyRecord *firstPreKeyRecord = [generatedKeys firstObject];
XCTAssert([[[OWSPrimaryStorage sharedManager] loadPreKey:lastPreKeyRecord.Id].keyPair.publicKey
@ -40,14 +43,15 @@
}
- (void)testRemovingPreKeys {
- (void)testRemovingPreKeys
{
NSArray *generatedKeys = [[OWSPrimaryStorage sharedManager] generatePreKeyRecords];
XCTAssert([generatedKeys count] == 100, @"Not hundred keys generated");
[[OWSPrimaryStorage sharedManager] storePreKeyRecords:generatedKeys];
PreKeyRecord *lastPreKeyRecord = [generatedKeys lastObject];
PreKeyRecord *lastPreKeyRecord = [generatedKeys lastObject];
PreKeyRecord *firstPreKeyRecord = [generatedKeys firstObject];
[[OWSPrimaryStorage sharedManager] removePreKey:lastPreKeyRecord.Id];

View File

@ -10,12 +10,14 @@
@implementation TSStorageSignedPreKeyStore
- (void)setUp {
- (void)setUp
{
[super setUp];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown {
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

View File

@ -3,7 +3,6 @@
//
#import "SignalRecipient.h"
#import "MockSSKEnvironment.h"
#import "OWSPrimaryStorage.h"
#import "SSKBaseTest.h"
#import "TSAccountManager.h"

View File

@ -7,7 +7,6 @@
#import "OWSDisappearingMessagesConfiguration.h"
#import "OWSError.h"
#import "OWSFakeContactsManager.h"
#import "OWSFakeContactsUpdater.h"
#import "OWSFakeNetworkManager.h"
#import "OWSPrimaryStorage.h"
#import "OWSUploadOperation.h"
@ -218,7 +217,6 @@ NS_ASSUME_NONNULL_BEGIN
OWSPrimaryStorage *storageManager = [OWSPrimaryStorage sharedManager];
OWSFakeContactsManager *contactsManager = [OWSFakeContactsManager new];
OWSFakeContactsUpdater *contactsUpdater = [OWSFakeContactsUpdater new];
// Successful Sending
TSNetworkManager *successfulNetworkManager = [[OWSMessageSenderFakeNetworkManager alloc] initWithSuccess:YES];

View File

@ -7,15 +7,14 @@
#import "Cryptography.h"
#import "OWSFakeCallMessageHandler.h"
#import "OWSFakeContactsManager.h"
#import "OWSFakeContactsUpdater.h"
#import "OWSFakeMessageSender.h"
#import "OWSFakeNetworkManager.h"
#import "OWSIdentityManager.h"
#import "OWSMessageSender.h"
#import "OWSPrimaryStorage.h"
#import "OWSSignalServiceProtos.pb.h"
#import "OWSUnitTestEnvironment.h"
#import "SSKBaseTest.h"
#import "SSKProto.pb.h"
#import "TSGroupThread.h"
#import "TSNetworkManager.h"
@ -34,11 +33,9 @@ NS_ASSUME_NONNULL_BEGIN
messageSender:(OWSMessageSender *)messageSender;
// private method we are testing
- (void)handleIncomingEnvelope:(OWSSignalServiceProtosEnvelope *)messageEnvelope
withSyncMessage:(OWSSignalServiceProtosSyncMessage *)syncMessage;
- (void)handleIncomingEnvelope:(SSKProtoEnvelope *)messageEnvelope withSyncMessage:(SSKProtoSyncMessage *)syncMessage;
- (void)handleIncomingEnvelope:(OWSSignalServiceProtosEnvelope *)messageEnvelope
withDataMessage:(OWSSignalServiceProtosDataMessage *)dataMessage;
- (void)handleIncomingEnvelope:(SSKProtoEnvelope *)messageEnvelope withDataMessage:(SSKProtoDataMessage *)dataMessage;
@end
@ -54,7 +51,6 @@ NS_ASSUME_NONNULL_BEGIN
storageManager:[OWSPrimaryStorage sharedManager]
callMessageHandler:[OWSFakeCallMessageHandler new]
contactsManager:[OWSFakeContactsManager new]
contactsUpdater:[OWSFakeContactsUpdater new]
identityManager:[OWSIdentityManager sharedManager]
messageSender:messageSender];
}
@ -72,11 +68,10 @@ NS_ASSUME_NONNULL_BEGIN
TSMessagesManager *messagesManager =
[self messagesManagerWithSender:[[OWSFakeMessageSender alloc] initWithExpectation:messageWasSent]];
OWSSignalServiceProtosEnvelopeBuilder *envelopeBuilder = [OWSSignalServiceProtosEnvelopeBuilder new];
OWSSignalServiceProtosSyncMessageBuilder *messageBuilder = [OWSSignalServiceProtosSyncMessageBuilder new];
OWSSignalServiceProtosSyncMessageRequestBuilder *requestBuilder =
[OWSSignalServiceProtosSyncMessageRequestBuilder new];
[requestBuilder setType:OWSSignalServiceProtosSyncMessageRequestTypeGroups];
SSKProtoEnvelopeBuilder *envelopeBuilder = [SSKProtoEnvelopeBuilder new];
SSKProtoSyncMessageBuilder *messageBuilder = [SSKProtoSyncMessageBuilder new];
SSKProtoSyncMessageRequestBuilder *requestBuilder = [SSKProtoSyncMessageRequestBuilder new];
[requestBuilder setType:SSKProtoSyncMessageRequestTypeGroups];
[messageBuilder setRequest:[requestBuilder build]];
[messagesManager handleIncomingEnvelope:[envelopeBuilder build] withSyncMessage:[messageBuilder build]];
@ -96,14 +91,14 @@ NS_ASSUME_NONNULL_BEGIN
TSMessagesManager *messagesManager = [self messagesManagerWithSender:[OWSFakeMessageSender new]];
OWSSignalServiceProtosEnvelopeBuilder *envelopeBuilder = [OWSSignalServiceProtosEnvelopeBuilder new];
SSKProtoEnvelopeBuilder *envelopeBuilder = [SSKProtoEnvelopeBuilder new];
OWSSignalServiceProtosGroupContextBuilder *groupContextBuilder = [OWSSignalServiceProtosGroupContextBuilder new];
SSKProtoGroupContextBuilder *groupContextBuilder = [SSKProtoGroupContextBuilder new];
groupContextBuilder.name = @"Newly created Group Name";
groupContextBuilder.id = groupIdData;
groupContextBuilder.type = OWSSignalServiceProtosGroupContextTypeUpdate;
groupContextBuilder.type = SSKProtoGroupContextTypeUpdate;
OWSSignalServiceProtosDataMessageBuilder *messageBuilder = [OWSSignalServiceProtosDataMessageBuilder new];
SSKProtoDataMessageBuilder *messageBuilder = [SSKProtoDataMessageBuilder new];
messageBuilder.group = [groupContextBuilder build];
[messagesManager handleIncomingEnvelope:[envelopeBuilder build] withDataMessage:[messageBuilder build]];
@ -123,22 +118,21 @@ NS_ASSUME_NONNULL_BEGIN
TSMessagesManager *messagesManager = [self messagesManagerWithSender:[OWSFakeMessageSender new]];
OWSSignalServiceProtosEnvelopeBuilder *envelopeBuilder = [OWSSignalServiceProtosEnvelopeBuilder new];
SSKProtoEnvelopeBuilder *envelopeBuilder = [SSKProtoEnvelopeBuilder new];
OWSSignalServiceProtosGroupContextBuilder *groupContextBuilder = [OWSSignalServiceProtosGroupContextBuilder new];
SSKProtoGroupContextBuilder *groupContextBuilder = [SSKProtoGroupContextBuilder new];
groupContextBuilder.name = @"Newly created Group with Avatar Name";
groupContextBuilder.id = groupIdData;
groupContextBuilder.type = OWSSignalServiceProtosGroupContextTypeUpdate;
groupContextBuilder.type = SSKProtoGroupContextTypeUpdate;
OWSSignalServiceProtosAttachmentPointerBuilder *attachmentBuilder =
[OWSSignalServiceProtosAttachmentPointerBuilder new];
SSKProtoAttachmentPointerBuilder *attachmentBuilder = [SSKProtoAttachmentPointerBuilder new];
attachmentBuilder.id = 1234;
attachmentBuilder.contentType = @"image/png";
attachmentBuilder.key = [NSData new];
attachmentBuilder.size = 123;
groupContextBuilder.avatar = [attachmentBuilder build];
OWSSignalServiceProtosDataMessageBuilder *messageBuilder = [OWSSignalServiceProtosDataMessageBuilder new];
SSKProtoDataMessageBuilder *messageBuilder = [SSKProtoDataMessageBuilder new];
messageBuilder.group = [groupContextBuilder build];
[messagesManager handleIncomingEnvelope:[envelopeBuilder build] withDataMessage:[messageBuilder build]];
@ -158,16 +152,16 @@ NS_ASSUME_NONNULL_BEGIN
TSMessagesManager *messagesManager = [self messagesManagerWithSender:[OWSFakeMessageSender new]];
OWSSignalServiceProtosEnvelopeBuilder *envelopeBuilder = [OWSSignalServiceProtosEnvelopeBuilder new];
SSKProtoEnvelopeBuilder *envelopeBuilder = [SSKProtoEnvelopeBuilder new];
OWSSignalServiceProtosGroupContextBuilder *groupContextBuilder = [OWSSignalServiceProtosGroupContextBuilder new];
SSKProtoGroupContextBuilder *groupContextBuilder = [SSKProtoGroupContextBuilder new];
groupContextBuilder.name = @"Newly created Group with Avatar Name";
groupContextBuilder.id = groupIdData;
// e.g. some future feature sent from another device that we don't yet support.
groupContextBuilder.type = 666;
OWSSignalServiceProtosDataMessageBuilder *messageBuilder = [OWSSignalServiceProtosDataMessageBuilder new];
SSKProtoDataMessageBuilder *messageBuilder = [SSKProtoDataMessageBuilder new];
messageBuilder.group = [groupContextBuilder build];
[messagesManager handleIncomingEnvelope:[envelopeBuilder build] withDataMessage:[messageBuilder build]];

View File

@ -8,20 +8,14 @@
NS_ASSUME_NONNULL_BEGIN
@interface Cryptography (TestingPrivateMethods)
+ (nullable NSData *)decryptAESGCMWithInitializationVector:(NSData *)initializationVector
ciphertext:(NSData *)ciphertext
authTag:(NSData *)authTagFromEncrypt
key:(OWSAES256Key *)key;
@end
@interface CryptographyTests : SSKBaseTest
@end
#pragma mark -
@interface Cryptography (Test)
+ (NSData *)truncatedSHA256HMAC:(NSData *)dataToHMAC withHMACKey:(NSData *)HMACKey truncation:(int)bytes;
+ (NSData *)encryptCBCMode:(NSData *)dataToEncrypt
withKey:(NSData *)key
@ -38,13 +32,13 @@ NS_ASSUME_NONNULL_BEGIN
HMACKey:(NSData *)hmacKey
HMACType:(TSMACType)hmacType
matchingHMAC:(NSData *)hmac;
@end
@implementation CryptographyTests
- (void)testEncryptAttachmentData
{
NSString *plainText = @"SGF3YWlpIGlzIEF3ZXNvbWUh";
NSData *plainTextData = [NSData dataFromBase64String:plainText];
@ -57,12 +51,11 @@ NS_ASSUME_NONNULL_BEGIN
NSData *cipherText =
[Cryptography encryptAttachmentData:plainTextData outKey:&generatedKey outDigest:&generatedDigest];
NSError *error;
NSData *decryptedData = [Cryptography decryptAttachment:cipherText
withKey:generatedKey
digest:generatedDigest
unpaddedSize:(UInt32)cipherText.length
unpaddedSize:(UInt32)plainTextData.length
error:&error];
XCTAssertNil(error);
@ -112,13 +105,11 @@ NS_ASSUME_NONNULL_BEGIN
NSData *badKey = [Cryptography generateRandomBytes:64];
NSError *error;
NSData *decryptedData = [Cryptography decryptAttachment:cipherText
withKey:badKey
digest:generatedDigest
unpaddedSize:(UInt32)cipherText.length + 1
error:&error];
XCTAssertNil(decryptedData);
XCTAssertThrows([Cryptography decryptAttachment:cipherText
withKey:badKey
digest:generatedDigest
unpaddedSize:(UInt32)plainTextData.length
error:&error]);
}
- (void)testDecryptAttachmentWithBadDigest
@ -138,13 +129,11 @@ NS_ASSUME_NONNULL_BEGIN
NSData *badDigest = [Cryptography generateRandomBytes:32];
NSError *error;
NSData *decryptedData = [Cryptography decryptAttachment:cipherText
withKey:generatedKey
digest:badDigest
unpaddedSize:(UInt32)cipherText.length + 1
error:&error];
XCTAssertNil(decryptedData);
XCTAssertThrows([Cryptography decryptAttachment:cipherText
withKey:generatedKey
digest:badDigest
unpaddedSize:(UInt32)plainTextData.length
error:&error]);
}
- (void)testComputeSHA256Digest
@ -179,14 +168,14 @@ NS_ASSUME_NONNULL_BEGIN
XCTAssertEqual(39, plainTextData.length);
OWSAES256Key *key = [OWSAES256Key new];
NSData *_Nullable encryptedData = [Cryptography encryptAESGCMWithData:plainTextData key:key];
NSData *_Nullable encryptedData = [Cryptography encryptAESGCMWithProfileData:plainTextData key:key];
const NSUInteger ivLength = 12;
const NSUInteger tagLength = 16;
XCTAssertEqual(ivLength + plainTextData.length + tagLength, encryptedData.length);
NSData *_Nullable decryptedData = [Cryptography decryptAESGCMWithData:encryptedData key:key];
NSData *_Nullable decryptedData = [Cryptography decryptAESGCMWithProfileData:encryptedData key:key];
XCTAssert(decryptedData != nil);
XCTAssertEqual(39, decryptedData.length);
XCTAssertEqualObjects(plainTextData, decryptedData);
@ -200,7 +189,7 @@ NS_ASSUME_NONNULL_BEGIN
XCTAssertEqual(39, plainTextData.length);
OWSAES256Key *key = [OWSAES256Key new];
NSData *_Nullable encryptedData = [Cryptography encryptAESGCMWithData:plainTextData key:key];
NSData *_Nullable encryptedData = [Cryptography encryptAESGCMWithProfileData:plainTextData key:key];
const NSUInteger ivLength = 12;
const NSUInteger tagLength = 16;
@ -218,6 +207,7 @@ NS_ASSUME_NONNULL_BEGIN
NSData *_Nullable decryptedData = [Cryptography decryptAESGCMWithInitializationVector:initializationVector
ciphertext:cipherText
additionalAuthenticatedData:nil
authTag:authTag
key:key];
@ -238,6 +228,7 @@ NS_ASSUME_NONNULL_BEGIN
decryptedData = [Cryptography decryptAESGCMWithInitializationVector:initializationVector
ciphertext:cipherText
additionalAuthenticatedData:nil
authTag:bogusAuthTag
key:key];