Merge branch 'mkirk/fix-tests'

pull/1/head
Michael Kirk 8 years ago
commit d6c5497f64

1
.gitignore vendored

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

@ -1,17 +1,17 @@
language: objective-c
osx_image: xcode8
osx_image: xcode8.3
env:
-EARLY_START_SIMULATOR=1 # early starting simulator reduces false negatives due to test timeouts
before_install:
- brew update
- gem install cocoapods xcpretty --no-ri --no-rdoc
- pod repo update --silent
- bundle
- bundle exec pod repo update --silent
after_failure:
- sleep 10 # This prevents the occasional output truncation that happens when piping to xcpretty.
script: make
script: make scan_test

@ -11,3 +11,18 @@ target 'TSKitiOSTestApp' do
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.to_s == "SignalServiceKit"
puts "--[!] Disabling singleton enforcement for SSK."
target.build_configurations.each do |config|
existing_definitions = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
if existing_definitions == nil || existing.length == 0
existing_definitions = "$(inheritied)"
end
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = "#{existing_definitions} SSK_BUILDING_FOR_TESTS=1"
end
end
end
end

@ -17,6 +17,7 @@ PODS:
- AFNetworking/NSURLSession
- AxolotlKit (0.8.1):
- 25519 (~> 2.0.1)
- CocoaLumberjack
- HKDFKit (~> 0.0.3)
- ProtocolBuffers (~> 1.9.8)
- CocoaLumberjack (2.4.0):
@ -28,12 +29,11 @@ PODS:
- CocoaLumberjack/Extensions (2.4.0):
- CocoaLumberjack/Default
- HKDFKit (0.0.3)
- libPhoneNumber-iOS (0.9.4)
- libPhoneNumber-iOS (0.9.10)
- Mantle (2.1.0):
- Mantle/extobjc (= 2.1.0)
- Mantle/extobjc (2.1.0)
- ProtocolBuffers (1.9.11)
- Reachability (3.2)
- SAMKeychain (1.5.2)
- SignalServiceKit (0.9.0):
- '25519'
@ -45,7 +45,7 @@ PODS:
- SAMKeychain
- SocketRocket
- TwistedOakCollapsingFutures
- YapDatabase/SQLCipher
- YapDatabase/SQLCipher (~> 2.9.3)
- SocketRocket (0.5.1)
- SQLCipher/common (3.4.1)
- SQLCipher/fts (3.4.1):
@ -53,54 +53,53 @@ PODS:
- TwistedOakCollapsingFutures (1.0.0):
- UnionFind (~> 1.0)
- UnionFind (1.0.1)
- YapDatabase/SQLCipher (2.9.2):
- YapDatabase/SQLCipher/Core (= 2.9.2)
- YapDatabase/SQLCipher/Extensions (= 2.9.2)
- YapDatabase/SQLCipher/Core (2.9.2):
- YapDatabase/SQLCipher (2.9.3):
- YapDatabase/SQLCipher/Core (= 2.9.3)
- YapDatabase/SQLCipher/Extensions (= 2.9.3)
- YapDatabase/SQLCipher/Core (2.9.3):
- CocoaLumberjack (~> 2)
- SQLCipher/fts
- YapDatabase/SQLCipher/Extensions (2.9.2):
- YapDatabase/SQLCipher/Extensions (2.9.3):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/ActionManager (= 2.9.2)
- YapDatabase/SQLCipher/Extensions/CloudKit (= 2.9.2)
- YapDatabase/SQLCipher/Extensions/ConnectionProxy (= 2.9.2)
- YapDatabase/SQLCipher/Extensions/CrossProcessNotification (= 2.9.2)
- YapDatabase/SQLCipher/Extensions/FilteredViews (= 2.9.2)
- YapDatabase/SQLCipher/Extensions/FullTextSearch (= 2.9.2)
- YapDatabase/SQLCipher/Extensions/Hooks (= 2.9.2)
- YapDatabase/SQLCipher/Extensions/Relationships (= 2.9.2)
- YapDatabase/SQLCipher/Extensions/RTreeIndex (= 2.9.2)
- YapDatabase/SQLCipher/Extensions/SearchResults (= 2.9.2)
- YapDatabase/SQLCipher/Extensions/SecondaryIndex (= 2.9.2)
- YapDatabase/SQLCipher/Extensions/Views (= 2.9.2)
- YapDatabase/SQLCipher/Extensions/ActionManager (2.9.2):
- Reachability (~> 3)
- YapDatabase/SQLCipher/Extensions/ActionManager (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/CloudKit (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/ConnectionProxy (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/CrossProcessNotification (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/FilteredViews (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/FullTextSearch (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/Hooks (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/Relationships (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/RTreeIndex (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/SearchResults (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/SecondaryIndex (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/Views (= 2.9.3)
- YapDatabase/SQLCipher/Extensions/ActionManager (2.9.3):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/Views
- YapDatabase/SQLCipher/Extensions/CloudKit (2.9.2):
- YapDatabase/SQLCipher/Extensions/CloudKit (2.9.3):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/ConnectionProxy (2.9.2):
- YapDatabase/SQLCipher/Extensions/ConnectionProxy (2.9.3):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/CrossProcessNotification (2.9.2):
- YapDatabase/SQLCipher/Extensions/CrossProcessNotification (2.9.3):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/FilteredViews (2.9.2):
- YapDatabase/SQLCipher/Extensions/FilteredViews (2.9.3):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/Views
- YapDatabase/SQLCipher/Extensions/FullTextSearch (2.9.2):
- YapDatabase/SQLCipher/Extensions/FullTextSearch (2.9.3):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/Hooks (2.9.2):
- YapDatabase/SQLCipher/Extensions/Hooks (2.9.3):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/Relationships (2.9.2):
- YapDatabase/SQLCipher/Extensions/Relationships (2.9.3):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/RTreeIndex (2.9.2):
- YapDatabase/SQLCipher/Extensions/RTreeIndex (2.9.3):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/SearchResults (2.9.2):
- YapDatabase/SQLCipher/Extensions/SearchResults (2.9.3):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/FullTextSearch
- YapDatabase/SQLCipher/Extensions/Views
- YapDatabase/SQLCipher/Extensions/SecondaryIndex (2.9.2):
- YapDatabase/SQLCipher/Extensions/SecondaryIndex (2.9.3):
- YapDatabase/SQLCipher/Core
- YapDatabase/SQLCipher/Extensions/Views (2.9.2):
- YapDatabase/SQLCipher/Extensions/Views (2.9.3):
- YapDatabase/SQLCipher/Core
DEPENDENCIES:
@ -118,7 +117,7 @@ EXTERNAL SOURCES:
CHECKOUT OPTIONS:
AxolotlKit:
:commit: a3c843cc8a423c5924c663490978f81dba34d04e
:commit: 28afe5c1dbcfdea73d147e464c53d191d1e3ea50
:git: https://github.com/WhisperSystems/SignalProtocolKit.git
SocketRocket:
:commit: 877ac7438be3ad0b45ef5ca3969574e4b97112bf
@ -127,21 +126,20 @@ CHECKOUT OPTIONS:
SPEC CHECKSUMS:
'25519': dc4bad7e2dbcbf1efa121068a705a44cd98c80fc
AFNetworking: 5e0e199f73d8626b11e79750991f5d173d1f8b67
AxolotlKit: 240c7d761e4b1be9c6de78ebec498aaeedc978f4
AxolotlKit: a9530d6835baae0f204b1f6b9dd79b7901176f0d
CocoaLumberjack: aa9dcab71bdf9eaf2a63bbd9ddc87863efe45457
HKDFKit: c058305d6f64b84f28c50bd7aa89574625bcb62a
libPhoneNumber-iOS: 63bab980d1fc9783d82d955800ac9d7c1d81fde3
libPhoneNumber-iOS: f721ae4d5854bce60934f9fb9b0b28e8e68913cb
Mantle: 2fa750afa478cd625a94230fbf1c13462f29395b
ProtocolBuffers: d509225eb2ea43d9582a59e94348fcf86e2abd65
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
SAMKeychain: 1865333198217411f35327e8da61b43de79b635b
SignalServiceKit: 59a79a51b89b963ba94db30cc99ed5212da0bb9f
SignalServiceKit: 2ad8d86da055e24ac3ea0354ec1d4b13251af28f
SocketRocket: dbb1554b8fc288ef8ef370d6285aeca7361be31e
SQLCipher: 43d12c0eb9c57fb438749618fc3ce0065509a559
TwistedOakCollapsingFutures: f359b90f203e9ab13dfb92c9ff41842a7fe1cd0c
UnionFind: c33be5adb12983981d6e827ea94fc7f9e370f52d
YapDatabase: b1e43555a34a5298e23a045be96817a5ef0da58f
YapDatabase: cd911121580ff16675f65ad742a9eb0ab4d9e266
PODFILE CHECKSUM: 1a7633963dbcaa43f298949d83c42c1cd1dce940
PODFILE CHECKSUM: 124c05542083fefccb75f4b7afbdd839e27ff5ab
COCOAPODS: 1.2.0
COCOAPODS: 1.2.1

@ -457,7 +457,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 +532,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 */

@ -0,0 +1,5 @@
source 'https://rubygems.org'
gem 'fastlane'
gem 'cocoapods'

@ -0,0 +1,187 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (2.3.5)
activesupport (4.2.8)
i18n (~> 0.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
babosa (1.0.2)
claide (1.0.1)
cocoapods (1.2.1)
activesupport (>= 4.0.2, < 5)
claide (>= 1.0.1, < 2.0)
cocoapods-core (= 1.2.1)
cocoapods-deintegrate (>= 1.0.1, < 2.0)
cocoapods-downloader (>= 1.1.3, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-stats (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.2.0, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (~> 2.0.1)
gh_inspector (~> 1.0)
molinillo (~> 0.5.7)
nap (~> 1.0)
ruby-macho (~> 1.1)
xcodeproj (>= 1.4.4, < 2.0)
cocoapods-core (1.2.1)
activesupport (>= 4.0.2, < 5)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
cocoapods-deintegrate (1.0.1)
cocoapods-downloader (1.1.3)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.0)
cocoapods-stats (1.0.0)
cocoapods-trunk (1.2.0)
nap (>= 0.8, < 2.0)
netrc (= 0.7.8)
cocoapods-try (1.1.0)
colored (1.2)
colored2 (3.1.2)
commander-fastlane (4.4.4)
highline (~> 1.7.2)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.2.0)
escape (0.0.4)
excon (0.55.0)
faraday (0.12.0.1)
multipart-post (>= 1.2, < 3)
faraday-cookie_jar (0.0.6)
faraday (>= 0.7.4)
http-cookie (~> 1.0.0)
faraday_middleware (0.11.0.1)
faraday (>= 0.7.4, < 1.0)
fastimage (2.1.0)
fastlane (2.27.0)
addressable (>= 2.3, < 3.0.0)
babosa (>= 1.0.2, < 2.0.0)
bundler (>= 1.12.0, < 2.0.0)
colored
commander-fastlane (>= 4.4.0, < 5.0.0)
dotenv (>= 2.1.1, < 3.0.0)
excon (>= 0.45.0, < 1.0.0)
faraday (~> 0.9)
faraday-cookie_jar (~> 0.0.6)
faraday_middleware (~> 0.9)
fastimage (>= 1.6)
gh_inspector (>= 1.0.1, < 2.0.0)
google-api-client (~> 0.9.2)
highline (>= 1.7.2, < 2.0.0)
json (< 3.0.0)
mini_magick (~> 4.5.1)
multi_json
multi_xml (~> 0.5)
multipart-post (~> 2.0.0)
plist (>= 3.1.0, < 4.0.0)
rubyzip (>= 1.1.0, < 2.0.0)
security (= 0.1.3)
slack-notifier (>= 1.3, < 2.0.0)
terminal-notifier (>= 1.6.2, < 2.0.0)
terminal-table (>= 1.4.5, < 2.0.0)
tty-screen (~> 0.5.0)
word_wrap (~> 1.0.0)
xcodeproj (>= 1.4.4, < 2.0.0)
xcpretty (>= 0.2.4, < 1.0.0)
xcpretty-travis-formatter (>= 0.0.3)
fourflusher (2.0.1)
fuzzy_match (2.0.4)
gh_inspector (1.0.3)
google-api-client (0.9.28)
addressable (~> 2.3)
googleauth (~> 0.5)
httpclient (~> 2.7)
hurley (~> 0.1)
memoist (~> 0.11)
mime-types (>= 1.6)
representable (~> 2.3.0)
retriable (~> 2.0)
googleauth (0.5.1)
faraday (~> 0.9)
jwt (~> 1.4)
logging (~> 2.0)
memoist (~> 0.12)
multi_json (~> 1.11)
os (~> 0.9)
signet (~> 0.7)
highline (1.7.8)
http-cookie (1.0.3)
domain_name (~> 0.5)
httpclient (2.8.3)
hurley (0.2)
i18n (0.8.1)
json (2.0.4)
jwt (1.5.6)
little-plugger (1.1.4)
logging (2.2.2)
little-plugger (~> 1.1)
multi_json (~> 1.10)
memoist (0.15.0)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_magick (4.5.1)
minitest (5.10.1)
molinillo (0.5.7)
multi_json (1.12.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
nanaimo (0.2.3)
nap (1.1.0)
netrc (0.7.8)
os (0.9.6)
plist (3.2.0)
public_suffix (2.0.5)
representable (2.3.0)
uber (~> 0.0.7)
retriable (2.1.0)
rouge (1.11.1)
ruby-macho (1.1.0)
rubyzip (1.2.1)
security (0.1.3)
signet (0.7.3)
addressable (~> 2.3)
faraday (~> 0.9)
jwt (~> 1.5)
multi_json (~> 1.10)
slack-notifier (1.5.1)
terminal-notifier (1.7.1)
terminal-table (1.7.3)
unicode-display_width (~> 1.1.1)
thread_safe (0.3.6)
tty-screen (0.5.0)
tzinfo (1.2.3)
thread_safe (~> 0.1)
uber (0.0.15)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.3)
unicode-display_width (1.1.3)
word_wrap (1.0.0)
xcodeproj (1.4.4)
CFPropertyList (~> 2.3.3)
claide (>= 1.0.1, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.2.3)
xcpretty (0.2.6)
rouge (~> 1.8)
xcpretty-travis-formatter (0.0.4)
xcpretty (~> 0.2, >= 0.0.7)
PLATFORMS
ruby
DEPENDENCIES
cocoapods
fastlane
BUNDLED WITH
1.14.6

@ -14,9 +14,11 @@ default: test
test: pod_install retest
scan_test: pod_install scan
pod_install:
cd $(WORKING_DIR) && \
pod install
bundle exec pod install
build: pod_install
cd $(WORKING_DIR) && \
@ -28,6 +30,9 @@ retest: optional_early_start_simulator
-destination '${BUILD_DESTINATION}' \
test | xcpretty
scan:
bundle exec fastlane scan
clean:
cd $(WORKING_DIR) && \
$(XCODE_BUILD) \

@ -0,0 +1 @@
test_output

@ -0,0 +1,8 @@
# For more information about this configuration visit
# https://github.com/fastlane/fastlane/tree/master/scan#scanfile
workspace "Example/TSKitiOSTestApp/TSKitiOSTestApp.xcworkspace"
scheme "TSKitiOSTestApp"
devices ["iPhone SE"]

@ -294,10 +294,28 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)deleteAttachments
{
NSError *error;
[[NSFileManager defaultManager] removeItemAtPath:[self attachmentsFolder] error:&error];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *fileURL = [NSURL fileURLWithPath:self.attachmentsFolder];
NSArray<NSURL *> *contents =
[fileManager contentsOfDirectoryAtURL:fileURL includingPropertiesForKeys:nil options:0 error:&error];
if (error) {
DDLogError(@"Failed to delete attachment folder with error: %@", error.debugDescription);
OWSFail(@"failed to get contents of attachments folder: %@ with error: %@", self.attachmentsFolder, error);
return;
}
for (NSURL *url in contents) {
NSError *deletionError;
[fileManager removeItemAtURL:url error:&deletionError];
if (deletionError) {
OWSFail(@"failed to remove item at path: %@ with error: %@", filePath, deletionError);
// continue to try to delete remaining items.
}
}
return;
}
- (CGSize)calculateImageSize

@ -70,8 +70,17 @@
//
// 1. Use OWSSingletonAssertFlag() outside the class definition.
// 2. Use OWSSingletonAssertInit() in each initializer.
#ifndef SSK_BUILDING_FOR_TESTS
#ifdef DEBUG
#define ENFORCE_SINGLETONS
#endif
#endif
#ifdef ENFORCE_SINGLETONS
#define OWSSingletonAssertFlag() static BOOL _isSingletonCreated = NO;
#define OWSSingletonAssertInit() \

@ -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];

@ -1,8 +1,10 @@
// Created by Michael Kirk on 11/7/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSContactThread.h"
#import "TSStorageManager+identityKeyStore.h"
#import "OWSIdentityManager.h"
#import "OWSUnitTestEnvironment.h"
#import <XCTest/XCTest.h>
NS_ASSUME_NONNULL_BEGIN
@ -17,8 +19,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)setUp
{
[OWSUnitTestEnvironment ensureSetup];
self.contactThread = [TSContactThread getOrCreateThreadWithContactId:@"fake-contact-id"];
[self.contactThread.storageManager removeIdentityKeyForRecipient:self.contactThread.contactIdentifier];
[OWSRecipientIdentity removeAllObjectsInCollection];
}
- (void)testHasSafetyNumbersWithoutRemoteIdentity
@ -28,8 +31,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)testHasSafetyNumbersWithRemoteIdentity
{
[self.contactThread.storageManager saveRemoteIdentity:[NSData new]
recipientId:self.contactThread.contactIdentifier];
[[OWSIdentityManager sharedManager] saveRemoteIdentity:[NSData new]
recipientId:self.contactThread.contactIdentifier];
XCTAssert(self.contactThread.hasSafetyNumbers);
}

@ -21,7 +21,7 @@
[super setUp];
// Register views, etc.
[[TSStorageManager sharedManager] setupDatabase];
[[TSStorageManager sharedManager] setupDatabaseWithSafeBlockingMigrations:^{}];
}
- (void)tearDown
@ -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
@ -100,10 +102,9 @@ NS_ASSUME_NONNULL_BEGIN
XCTAssertEqualObjects(@"📽 ATTACHMENT", actualDescription);
}
- (void)testDescriptionWithAudioAttachmentId
{
TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"audio/mp3"];
TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"audio/mp3" sourceFilename:@"some-file.mp3"];
[attachment save];
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
@ -114,9 +115,22 @@ NS_ASSUME_NONNULL_BEGIN
XCTAssertEqualObjects(@"📻 ATTACHMENT", actualDescription);
}
- (void)testDescriptionWithVoiceMessageAttachmentId
{
TSAttachment *attachment = [[TSAttachmentStream alloc] initWithContentType:@"audio/mp3" sourceFilename:nil];
[attachment save];
TSMessage *message = [[TSMessage alloc] initWithTimestamp:1
inThread:self.thread
messageBody:@"My message body"
attachmentIds:@[ attachment.uniqueId ]];
NSString *actualDescription = [message description];
XCTAssertEqualObjects(@"🎤 ATTACHMENT_TYPE_VOICE_MESSAGE", actualDescription);
}
- (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 "OWSDisappearingMessagesFinder.h"
@ -12,16 +13,18 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWSDisappearingMessagesFinder (Testing)
- (NSArray<TSMessage *> *)fetchExpiredMessages;
- (NSArray<TSMessage *> *)fetchUnstartedExpiringMessagesInThread:(TSThread *)thread;
- (NSArray<TSMessage *> *)fetchExpiredMessagesWithTransaction:(YapDatabaseReadTransaction *)transaction;
- (NSArray<TSMessage *> *)fetchUnstartedExpiringMessagesInThread:(TSThread *)thread
transaction:(YapDatabaseReadTransaction *)transaction;
@end
@interface OWSDisappearingMessageFinderTest : XCTestCase
@property TSStorageManager *storageManager;
@property YapDatabaseConnection *dbConnection;
@property OWSDisappearingMessagesFinder *finder;
@property TSStorageManager *storageManager;
@property TSThread *thread;
@property uint64_t now;
@ -35,13 +38,14 @@ NS_ASSUME_NONNULL_BEGIN
[TSMessage removeAllObjectsInCollection];
self.storageManager = [TSStorageManager sharedManager];
self.dbConnection = self.storageManager.newDatabaseConnection;
self.thread = [TSThread new];
[self.thread save];
self.now = [NSDate ows_millisecondTimeStamp];
// Test subject
self.finder = [[OWSDisappearingMessagesFinder alloc] initWithStorageManager:self.storageManager];
[self.finder blockingRegisterDatabaseExtensions];
self.finder = [OWSDisappearingMessagesFinder new];
[OWSDisappearingMessagesFinder blockingRegisterDatabaseExtensions:self.storageManager];
}
- (void)testExpiredMessages
@ -90,7 +94,11 @@ NS_ASSUME_NONNULL_BEGIN
[[TSMessage alloc] initWithTimestamp:1 inThread:self.thread messageBody:@"unexpiringMessage2"];
[unExpiringMessage2 save];
NSArray<TSMessage *> *actualMessages = [self.finder fetchExpiredMessages];
__block NSArray<TSMessage *> *actualMessages;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction * _Nonnull transaction) {
actualMessages = [self.finder fetchExpiredMessagesWithTransaction:transaction];
}];
NSArray<TSMessage *> *expectedMessages = @[ expiredMessage1, expiredMessage2 ];
XCTAssertEqualObjects(expectedMessages, actualMessages);
}
@ -133,15 +141,33 @@ NS_ASSUME_NONNULL_BEGIN
[[TSMessage alloc] initWithTimestamp:1 inThread:self.thread messageBody:@"unexpiringMessage2"];
[unExpiringMessage2 save];
NSArray<TSMessage *> *actualMessages = [self.finder fetchUnstartedExpiringMessagesInThread:self.thread];
__block NSArray<TSMessage *> *actualMessages;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction * _Nonnull transaction) {
actualMessages = [self.finder fetchUnstartedExpiringMessagesInThread:self.thread
transaction:transaction];
}];
NSArray<TSMessage *> *expectedMessages = @[ unreadExpiringMessage ];
XCTAssertEqualObjects(expectedMessages, actualMessages);
}
- (NSNumber *)nextExpirationTimestamp
{
__block NSNumber *nextExpirationTimestamp;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction * _Nonnull transaction) {
XCTAssertNotNil(self.finder);
nextExpirationTimestamp = [self.finder nextExpirationTimestampWithTransaction:transaction];
}];
return nextExpirationTimestamp;
}
- (void)testNextExpirationTimestampNilWhenNoExpiringMessages
{
// Sanity check.
XCTAssertNil(self.finder.nextExpirationTimestamp);
XCTAssertNil(self.nextExpirationTimestamp);
TSMessage *unExpiringMessage = [[TSMessage alloc] initWithTimestamp:1
inThread:self.thread
@ -150,7 +176,7 @@ NS_ASSUME_NONNULL_BEGIN
expiresInSeconds:0
expireStartedAt:0];
[unExpiringMessage save];
XCTAssertNil(self.finder.nextExpirationTimestamp);
XCTAssertNil(self.nextExpirationTimestamp);
}
- (void)testNextExpirationTimestampNotNilWithUpcomingExpiringMessages
@ -163,8 +189,8 @@ NS_ASSUME_NONNULL_BEGIN
expireStartedAt:self.now - 9000];
[soonToExpireMessage save];
XCTAssertNotNil(self.finder.nextExpirationTimestamp);
XCTAssertEqual(self.now + 1000, [self.finder.nextExpirationTimestamp unsignedLongLongValue]);
XCTAssertNotNil(self.nextExpirationTimestamp);
XCTAssertEqual(self.now + 1000, [self.nextExpirationTimestamp unsignedLongLongValue]);
// expired message should take precedence
TSMessage *expiredMessage = [[TSMessage alloc] initWithTimestamp:1
@ -175,8 +201,10 @@ NS_ASSUME_NONNULL_BEGIN
expireStartedAt:self.now - 11000];
[expiredMessage save];
XCTAssertNotNil(self.finder.nextExpirationTimestamp);
XCTAssertEqual(self.now - 1000, [self.finder.nextExpirationTimestamp unsignedLongLongValue]);
//FIXME remove sleep hack in favor of expiringMessage completion handler
// sleep(2);
XCTAssertNotNil(self.nextExpirationTimestamp);
XCTAssertEqual(self.now - 1000, [self.nextExpirationTimestamp unsignedLongLongValue]);
}
@end

@ -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"
@ -13,6 +14,14 @@
NS_ASSUME_NONNULL_BEGIN
@interface OWSDisappearingMessagesJob (Testing)
- (void)run;
- (void)becomeConsistentWithConfigurationForMessage:(TSMessage *)message
contactsManager:(id<ContactsManagerProtocol>)contactsManager;
@end
@interface OWSDisappearingMessagesJobTest : XCTestCase
@end
@ -61,12 +70,15 @@ 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];
//FIXME remove sleep hack in favor of expiringMessage completion handler
sleep(4);
XCTAssertEqual(2, [TSMessage numberOfKeysInCollection]);
}
@ -75,9 +87,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,7 +101,6 @@ NS_ASSUME_NONNULL_BEGIN
expireStartedAt:0];
[expiringMessage save];
[job becomeConsistentWithConfigurationForMessage:expiringMessage contactsManager:[OWSFakeContactsManager new]];
configuration = [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId];
@ -104,14 +114,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 +125,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]);
}

@ -94,7 +94,10 @@ NS_ASSUME_NONNULL_BEGIN
if (self.shouldSucceed) {
successHandler();
} else {
failureHandler(OWSErrorMakeFailedToSendOutgoingMessageError());
NSError *error = OWSErrorMakeFailedToSendOutgoingMessageError();
[error setIsRetryable:NO];
failureHandler(error);
}
}
@ -130,7 +133,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 +144,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithSuccess:(BOOL)shouldSucceed
{
self = [super init];
self = [self init];
if (!self) {
return self;
}
@ -240,6 +243,8 @@ NS_ASSUME_NONNULL_BEGIN
XCTestExpectation *messageStartedExpiration = [self expectationWithDescription:@"messageStartedExpiration"];
[messageSender sendMessage:self.expiringMessage
success:^() {
//FIXME remove sleep hack in favor of expiringMessage completion handler
sleep(2);
if (self.expiringMessage.expiresAt > 0) {
[messageStartedExpiration fulfill];
} else {
@ -316,7 +321,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 +346,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 +400,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 +429,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 +452,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 +469,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 +485,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;

@ -17,7 +17,9 @@
#import "TSGroupThread.h"
#import "TSMessagesManager.h"
#import "TSNetworkManager.h"
#import "OWSIdentityManager.h"
#import "TSStorageManager.h"
#import "OWSUnitTestEnvironment.h"
NS_ASSUME_NONNULL_BEGIN
@ -30,6 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
callMessageHandler:(id<OWSCallMessageHandler>)callMessageHandler
contactsManager:(id<ContactsManagerProtocol>)contactsManager
contactsUpdater:(ContactsUpdater *)contactsUpdater
identityManager:(OWSIdentityManager *)identityManager
messageSender:(OWSMessageSender *)messageSender;
// private method we are testing
@ -54,9 +57,17 @@ NS_ASSUME_NONNULL_BEGIN
callMessageHandler:[OWSFakeCallMessageHandler new]
contactsManager:[OWSFakeContactsManager new]
contactsUpdater:[OWSFakeContactsUpdater new]
identityManager:[OWSIdentityManager sharedManager]
messageSender:messageSender];
}
- (void)setUp
{
[super setUp];
[OWSUnitTestEnvironment ensureSetup];
}
- (void)testIncomingSyncContactMessage
{
XCTestExpectation *messageWasSent = [self expectationWithDescription:@"message was sent"];

@ -20,7 +20,7 @@
{
[super setUp];
// Register views, etc.
[[TSStorageManager sharedManager] setupDatabase];
[[TSStorageManager sharedManager] setupDatabaseWithSafeBlockingMigrations:^{}];
// Set up initial conditions & Sanity check
[TSAttachmentStream deleteAttachments];
@ -76,8 +76,11 @@
- (void)testFilesWithoutInteractionsAreDeleted
{
// sanity check
XCTAssertEqual(0, [TSAttachmentStream numberOfItemsInAttachmentsFolder]);
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 +100,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,11 +128,10 @@
- (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.
NSString *orphanedFilePath = [attachmentStream filePath];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:orphanedFilePath];
XCTAssert(fileExists);

@ -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,8 +7,8 @@
#import "OWSUnitTestEnvironment.h"
#import "SecurityUtils.h"
#import "TSPrivacyPreferences.h"
#import "TSStorageManager+IdentityKeyStore.h"
#import "OWSIdentityManager.h"
#import "OWSRecipientIdentity.h"
#import "TSStorageManager.h"
#import "TextSecureKitEnv.h"
@ -24,8 +20,9 @@
- (void)setUp {
[super setUp];
[[TSStorageManager sharedManager] purgeCollection:@"TSStorageManagerTrustedKeysCollection"];
// Put setup code here. This method is called before the invocation of each test method in the class.
[OWSRecipientIdentity removeAllObjectsInCollection];
}
- (void)tearDown {
@ -37,61 +34,42 @@
NSData *newKey = [SecurityUtils generateRandomBytes:32];
NSString *recipientId = @"test@gmail.com";
XCTAssert([[TSStorageManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
}
- (void)testAlreadyRegisteredKey {
NSData *newKey = [SecurityUtils generateRandomBytes:32];
NSString *recipientId = @"test@gmail.com";
[[TSStorageManager sharedManager] saveRemoteIdentity:newKey recipientId:recipientId];
[[OWSIdentityManager sharedManager] saveRemoteIdentity:newKey recipientId:recipientId];
XCTAssert([[TSStorageManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
}
- (void)testChangedKeyWithBlockingIdentityChanges
- (void)testChangedKey
{
TSPrivacyPreferences *preferences = [TSPrivacyPreferences sharedInstance];
preferences.shouldBlockOnIdentityChange = YES;
[preferences save];
NSData *newKey = [SecurityUtils generateRandomBytes:32];
NSString *recipientId = @"test@gmail.com";
NSData *originalKey = [SecurityUtils generateRandomBytes:32];
NSString *recipientId = @"test@protonmail.com";
[[TSStorageManager sharedManager] saveRemoteIdentity:newKey recipientId:recipientId];
[[OWSIdentityManager sharedManager] saveRemoteIdentity:originalKey recipientId:recipientId];
XCTAssert([[TSStorageManager sharedManager] isTrustedIdentityKey:newKey recipientId:recipientId]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:originalKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
XCTAssert([[OWSIdentityManager sharedManager] isTrustedIdentityKey:originalKey recipientId:recipientId direction:TSMessageDirectionIncoming]);
NSData *otherKey = [SecurityUtils generateRandomBytes:32];
XCTAssertFalse([[TSStorageManager sharedManager] isTrustedIdentityKey:otherKey recipientId:recipientId]);
XCTAssertFalse([[OWSIdentityManager sharedManager] isTrustedIdentityKey:otherKey recipientId:recipientId direction:TSMessageDirectionOutgoing]);
XCTAssert([[OWSIdentityManager 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];
[[OWSIdentityManager sharedManager] generateNewIdentityKey];
XCTAssert([[[TSStorageManager sharedManager] identityKeyPair].publicKey length] == 32);
XCTAssert([[[OWSIdentityManager sharedManager] identityKeyPair].publicKey length] == 32);
}
@end

@ -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 "OWSFakeContactsManager.h"
@ -14,7 +15,12 @@ NS_ASSUME_NONNULL_BEGIN
return @"Fake name";
}
- (NSArray<Contact *> * _Nonnull)signalContacts
- (NSArray<Contact *> *)signalContacts
{
return @[];
}
- (NSArray<SignalAccount *> *)signalAccounts
{
return @[];
}

@ -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;

@ -1,5 +1,6 @@
// Created by Michael Kirk on 12/18/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSFakeNotificationsManager.h"
@ -8,8 +9,8 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSFakeNotificationsManager
- (void)notifyUserForIncomingMessage:(TSIncomingMessage *)incomingMessage
from:(NSString *)name
inThread:(TSThread *)thread
contactsManager:(id<ContactsManagerProtocol>)contactsManager
{
NSLog(@"%s", __PRETTY_FUNCTION__);
}

@ -1,5 +1,6 @@
// Created by Michael Kirk on 12/18/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TextSecureKitEnv.h"
@ -7,6 +8,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWSUnitTestEnvironment : TextSecureKitEnv
+ (void)ensureSetup;
- (instancetype)initDefault;
@end

@ -12,7 +12,15 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSUnitTestEnvironment
- (instancetype)init
+ (void)ensureSetup
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
[self setSharedEnv:[[self alloc] initDefault]];
});
}
- (instancetype)initDefault
{
return [super initWithCallMessageHandler:[OWSFakeCallMessageHandler new]
contactsManager:[OWSFakeContactsManager new]

Loading…
Cancel
Save