MdmSetupTests.m 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2019-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import <XCTest/XCTest.h>
  21. #import <OCMockito/OCMockito.h>
  22. #import <OCHamcrest/OCHamcrest.h>
  23. #import <ThreemaFramework/MDMSetup.h>
  24. #import "MyIdentityStore.h"
  25. #import "LicenseStore.h"
  26. #import "UserSettings.h"
  27. #define MOCKITO_SHORTHAND
  28. @interface MdmSetupTests : XCTestCase
  29. @end
  30. @implementation MdmSetupTests {
  31. __strong Class _mockMyIdentityStoreClass;
  32. MyIdentityStore* _mockMyIdentityStore;
  33. __strong Class _mockUserSettingsClass;
  34. UserSettings* _mockUserSettings;
  35. __strong Class _mockLicenseStoreClass;
  36. LicenseStore* _mockLicenseStore;
  37. NSNumber *_yes;
  38. NSNumber *_no;
  39. }
  40. - (void)setUp {
  41. [super setUp];
  42. _mockUserSettingsClass = mockClass([UserSettings class]);
  43. _mockUserSettings = mock([UserSettings class]);
  44. stubSingleton(_mockUserSettingsClass, sharedUserSettings);
  45. [given([UserSettings sharedUserSettings]) willReturn:_mockUserSettings];
  46. _mockLicenseStoreClass = mockClass([LicenseStore class]);
  47. _mockLicenseStore = mock([LicenseStore class]);
  48. stubSingleton(_mockLicenseStoreClass, sharedLicenseStore);
  49. [given([LicenseStore sharedLicenseStore]) willReturn:_mockLicenseStore];
  50. _mockMyIdentityStoreClass = mockClass([MyIdentityStore class]);
  51. _mockMyIdentityStore = mock([MyIdentityStore class]);
  52. stubSingleton(_mockMyIdentityStoreClass, sharedMyIdentityStore);
  53. [given([MyIdentityStore sharedMyIdentityStore]) willReturn:_mockMyIdentityStore];
  54. [self delMdm];
  55. _yes = [[NSNumber alloc] initWithUnsignedInt:1];
  56. _no = [[NSNumber alloc] initWithUnsignedInt:0];
  57. }
  58. - (void)tearDown {
  59. stopMocking(_mockUserSettings);
  60. stopMocking(_mockUserSettingsClass);
  61. _mockUserSettings = nil;
  62. _mockUserSettingsClass = nil;
  63. stopMocking(_mockLicenseStore);
  64. stopMocking(_mockLicenseStoreClass);
  65. _mockLicenseStore = nil;
  66. _mockLicenseStoreClass = nil;
  67. stopMocking(_mockMyIdentityStore);
  68. stopMocking(_mockMyIdentityStoreClass);
  69. _mockMyIdentityStore = nil;
  70. _mockMyIdentityStoreClass = nil;
  71. [self delMdm];
  72. [super tearDown];
  73. }
  74. - (void)delMdm {
  75. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  76. [defaults removeObjectForKey:MDM_CONFIGURATION_KEY];
  77. [defaults removeObjectForKey:MDM_THREEMA_CONFIGURATION_KEY];
  78. [defaults synchronize];
  79. [MDMSetup clearMdmCache];
  80. }
  81. - (void)setMdm:(NSDictionary*)companyMdm threemaMdm:(NSDictionary*)threemaMdm {
  82. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  83. if (companyMdm != nil) {
  84. [defaults setObject:companyMdm forKey:MDM_CONFIGURATION_KEY];
  85. }
  86. if (threemaMdm != nil) {
  87. [defaults setObject:threemaMdm forKey:MDM_THREEMA_CONFIGURATION_KEY];
  88. }
  89. [defaults synchronize];
  90. }
  91. - (void)testIsManaged {
  92. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  93. id keys[] = { @"test"};
  94. id objects[] = { @"test"};
  95. NSUInteger count = sizeof(objects) / sizeof(id);
  96. NSDictionary* companyMdm = [NSDictionary dictionaryWithObjects:objects forKeys:keys count:count];
  97. [self setMdm:companyMdm threemaMdm:nil];
  98. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:NO];
  99. XCTAssertTrue(mdmSetup.isManaged);
  100. }
  101. - (void)testIsManagedWithoutMdm {
  102. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  103. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:NO];
  104. XCTAssertFalse(mdmSetup.isManaged);
  105. }
  106. - (void)testLoadLicenseInfo {
  107. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  108. id keys[] = { MDM_KEY_LICENSE_USERNAME, MDM_KEY_LICENSE_PASSWORD };
  109. id objects[] = { @"tester", @"testi123"};
  110. NSUInteger count = sizeof(objects) / sizeof(id);
  111. NSDictionary* companyMdm = [NSDictionary dictionaryWithObjects:objects forKeys:keys count:count];
  112. [self setMdm:companyMdm threemaMdm:nil];
  113. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:NO];
  114. [mdmSetup loadLicenseInfo];
  115. [verify(_mockLicenseStore) setLicenseUsername:@"tester"];
  116. [verify(_mockLicenseStore) setLicensePassword:@"testi123"];
  117. }
  118. - (void)testLoadRenewableValues {
  119. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  120. // Company-MDM
  121. [self setMdm:[self getAllMdmParameters:NO] threemaMdm:nil];
  122. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:NO];
  123. [mdmSetup loadRenewableValues];
  124. [verify(_mockLicenseStore) setLicenseUsername:@"tester"];
  125. [verify(_mockLicenseStore) setLicensePassword:@"test1234"];
  126. [verifyCount(_mockMyIdentityStore, times(0)) setPushFromName:anything()];
  127. [verifyCount(_mockMyIdentityStore, times(0)) setFirstName:anything()];
  128. [verifyCount(_mockMyIdentityStore, times(0)) setLastName:anything()];
  129. [verifyCount(_mockMyIdentityStore, times(0)) setCsi:anything()];
  130. [verifyCount(_mockMyIdentityStore, times(0)) setCategory:anything()];
  131. [verifyCount(_mockMyIdentityStore, times(0)) setCreateIDEmail:anything()];
  132. [verifyCount(_mockMyIdentityStore, times(0)) setCreateIDPhone:anything()];
  133. XCTAssertTrue([mdmSetup readonlyProfile]);
  134. [verifyCount(_mockUserSettings, times(1)) setBlockUnknown:YES];
  135. [verifyCount(_mockUserSettings, times(1)) setSyncContacts:YES];
  136. XCTAssertTrue([mdmSetup disableSaveToGallery]);
  137. XCTAssertTrue([mdmSetup disableAddContact]);
  138. XCTAssertTrue([mdmSetup disableExport]);
  139. XCTAssertTrue([mdmSetup disableBackups]);
  140. XCTAssertTrue([mdmSetup disableIdExport]);
  141. XCTAssertTrue([mdmSetup disableSystemBackups]);
  142. XCTAssertTrue([mdmSetup disableMessagePreview]);
  143. XCTAssertTrue([mdmSetup disableSendProfilePicture]);
  144. XCTAssertTrue([mdmSetup disableCalls]);
  145. XCTAssertTrue([mdmSetup disableVideoCalls]);
  146. XCTAssertTrue([mdmSetup disableCreateGroup]);
  147. XCTAssertTrue([mdmSetup disableWeb]);
  148. XCTAssertTrue([mdmSetup skipWizard]);
  149. XCTAssertTrue([mdmSetup safeEnable]);
  150. XCTAssertEqual(@"87654321", [mdmSetup safePassword]);
  151. XCTAssertEqual(@"http://test.com", [mdmSetup safeServerUrl]);
  152. XCTAssertEqual(@"server-user", [mdmSetup safeServerUsername]);
  153. XCTAssertEqual(@"server-password", [mdmSetup safeServerPassword]);
  154. XCTAssertFalse([mdmSetup safeRestoreEnable]);
  155. XCTAssertEqual(@"ECHOECHO", [mdmSetup safeRestoreId]);
  156. XCTAssertEqual(@"^[0-9]{1,15}$", [mdmSetup safePasswordPattern]);
  157. XCTAssertEqual(@"Wrong-password-pattern", [mdmSetup safePasswordMessage]);
  158. XCTAssertEqual(@"threema.ch", [mdmSetup webHosts]);
  159. }
  160. - (void)testLoadIDCreationValues {
  161. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  162. // Company-MDM
  163. [self setMdm:[self getAllMdmParameters:NO] threemaMdm:nil];
  164. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:NO];
  165. [mdmSetup loadIDCreationValues];
  166. [verifyCount(_mockLicenseStore, times(0)) setLicenseUsername:anything()];
  167. [verifyCount(_mockLicenseStore, times(0)) setLicensePassword:anything()];
  168. [verifyCount(_mockMyIdentityStore, times(1)) setPushFromName:@"Eieri"];
  169. [verifyCount(_mockMyIdentityStore, times(1)) setFirstName:@"Heiri"];
  170. [verifyCount(_mockMyIdentityStore, times(1)) setLastName:@"Heirassa"];
  171. [verifyCount(_mockMyIdentityStore, times(1)) setCsi:@"customer-id"];
  172. [verifyCount(_mockMyIdentityStore, times(1)) setCategory:@"category"];
  173. [verifyCount(_mockMyIdentityStore, times(1)) setCreateIDEmail:@"linked@email.com"];
  174. [verifyCount(_mockMyIdentityStore, times(1)) setCreateIDPhone:@"111"];
  175. XCTAssertTrue([mdmSetup readonlyProfile]);
  176. [verifyCount(_mockUserSettings, times(0)) setBlockUnknown:anything()];
  177. [verifyCount(_mockUserSettings, times(1)) setSyncContacts:anything()];
  178. XCTAssertTrue([mdmSetup disableSaveToGallery]);
  179. XCTAssertTrue([mdmSetup disableAddContact]);
  180. XCTAssertTrue([mdmSetup disableExport]);
  181. XCTAssertTrue([mdmSetup disableBackups]);
  182. XCTAssertTrue([mdmSetup disableIdExport]);
  183. XCTAssertTrue([mdmSetup disableSystemBackups]);
  184. XCTAssertTrue([mdmSetup disableMessagePreview]);
  185. XCTAssertTrue([mdmSetup disableSendProfilePicture]);
  186. XCTAssertTrue([mdmSetup disableCalls]);
  187. XCTAssertTrue([mdmSetup disableVideoCalls]);
  188. XCTAssertTrue([mdmSetup disableCreateGroup]);
  189. XCTAssertTrue([mdmSetup disableWeb]);
  190. XCTAssertTrue([mdmSetup skipWizard]);
  191. XCTAssertEqual(_yes, [mdmSetup safeEnable]);
  192. XCTAssertEqual(@"87654321", [mdmSetup safePassword]);
  193. XCTAssertEqual(@"http://test.com", [mdmSetup safeServerUrl]);
  194. XCTAssertEqual(@"server-user", [mdmSetup safeServerUsername]);
  195. XCTAssertEqual(@"server-password", [mdmSetup safeServerPassword]);
  196. XCTAssertFalse([mdmSetup safeRestoreEnable]);
  197. XCTAssertEqual(@"ECHOECHO", [mdmSetup safeRestoreId]);
  198. XCTAssertEqual(@"^[0-9]{1,15}$", [mdmSetup safePasswordPattern]);
  199. XCTAssertEqual(@"Wrong-password-pattern", [mdmSetup safePasswordMessage]);
  200. XCTAssertEqual(@"threema.ch", [mdmSetup webHosts]);
  201. }
  202. - (void)testHasIDBackup {
  203. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  204. id keys[] = { MDM_KEY_ID_BACKUP };
  205. id objects[] = { @"XXXX-XXXX-..." };
  206. NSUInteger count = sizeof(objects) / sizeof(id);
  207. NSDictionary *companyMdm = [NSDictionary dictionaryWithObjects:objects forKeys:keys count:count];
  208. [self setMdm:companyMdm threemaMdm:nil];
  209. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:YES];
  210. BOOL result = [mdmSetup hasIDBackup];
  211. XCTAssertTrue(result);
  212. XCTAssertEqual(@"XXXX-XXXX-...", mdmSetup.idBackup);
  213. XCTAssertNil(mdmSetup.idBackupPassword);
  214. }
  215. /// Bestehende Firmen/Threema MDM-Parameter werden von renewable Threema MDM Parameter überschrieben (kein "setup" sync)
  216. - (void)testApplyThreemaMdmWithCompanyMdmAndThreemaMdmDoOverrideSetupNo {
  217. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  218. // Company-MDM and "old" Threema-MDM are equal
  219. NSDictionary *oldWorkData = @{MDM_KEY_THREEMA_OVERRIDE:@true,MDM_KEY_THREEMA_PARAMS:[self getAllMdmParameters:YES]};
  220. [self setMdm:[self getAllMdmParameters:NO] threemaMdm:oldWorkData];
  221. // new Threema-MDM (override)
  222. id keysThreemaMdm[] = { MDM_KEY_LICENSE_USERNAME, MDM_KEY_LICENSE_PASSWORD, MDM_KEY_NICKNAME, MDM_KEY_FIRST_NAME, MDM_KEY_LAST_NAME, MDM_KEY_CSI, MDM_KEY_CATEGORY, MDM_KEY_LINKED_EMAIL, MDM_KEY_LINKED_PHONE, MDM_KEY_CONTACT_SYNC, MDM_KEY_READONLY_PROFILE, MDM_KEY_BLOCK_UNKNOWN, MDM_KEY_HIDE_INACTIVE_IDS, MDM_KEY_DISABLE_SAVE_TO_GALLERY, MDM_KEY_DISABLE_ADD_CONTACT, MDM_KEY_DISABLE_EXPORT, MDM_KEY_DISABLE_BACKUPS, MDM_KEY_DISABLE_ID_EXPORT, MDM_KEY_DISABLE_SYSTEM_BACKUPS, MDM_KEY_DISABLE_MESSAGE_PREVIEW, MDM_KEY_DISABLE_SEND_PROFILE_PICTURE, MDM_KEY_DISABLE_CALLS, MDM_KEY_DISABLE_VIDEO_CALLS, MDM_KEY_SKIP_WIZARD, MDM_KEY_DISABLE_CREATE_GROUP, MDM_KEY_DISABLE_WEB, MDM_KEY_SAFE_ENABLE, MDM_KEY_SAFE_SERVER_URL, MDM_KEY_SAFE_SERVER_USERNAME, MDM_KEY_SAFE_SERVER_PASSWORD, MDM_KEY_SAFE_RESTORE_ENABLE, MDM_KEY_SAFE_RESTORE_ID, MDM_KEY_SAFE_PASSWORD_PATTERN, MDM_KEY_SAFE_PASSWORD_MESSAGE, MDM_KEY_WEB_HOSTS, MDM_KEY_DISABLE_SHARE_MEDIA};
  223. id objectsThreemaMdm[] = { @"new-tester", @"new-test1234", @"New-Eieri", @"New-Heiri", @"New-Heirassa", @"new-customer-id", @"new-category", @"new-linked@email.com", @"222", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", _no, @"http://new-test.com", @"new-server-user", @"new-server-password", @"1", @"EINSZWEI", @"new-^[0-9]{1,15}$", @"New-Wrong-password-pattern", @"new.threema.ch", @"0"};
  224. NSUInteger countThreemaMdm = sizeof(objectsThreemaMdm) / sizeof(id);
  225. NSDictionary *threemaMdm = [NSDictionary dictionaryWithObjects:objectsThreemaMdm forKeys:keysThreemaMdm count:countThreemaMdm];
  226. NSDictionary *workData = @{MDM_KEY_THREEMA_CONFIGURATION: @{MDM_KEY_THREEMA_OVERRIDE:@true,MDM_KEY_THREEMA_PARAMS:threemaMdm}};
  227. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:NO];
  228. [mdmSetup applyThreemaMdm:workData];
  229. [verify(_mockLicenseStore) setLicenseUsername:@"new-tester"];
  230. [verify(_mockLicenseStore) setLicensePassword:@"new-test1234"];
  231. [verifyCount(_mockMyIdentityStore, times(1)) setPushFromName:@"New-Eieri"];
  232. [verifyCount(_mockMyIdentityStore, times(1)) setFirstName:@"New-Heiri"];
  233. [verifyCount(_mockMyIdentityStore, times(1)) setLastName:@"New-Heirassa"];
  234. [verifyCount(_mockMyIdentityStore, times(1)) setCsi:@"new-customer-id"];
  235. [verifyCount(_mockMyIdentityStore, times(1)) setCategory:@"new-category"];
  236. [verifyCount(_mockMyIdentityStore, times(1)) setCreateIDEmail:@"linked@email.com"]; // not renewable
  237. [verifyCount(_mockMyIdentityStore, times(1)) setCreateIDPhone:@"111"]; // not renewable
  238. XCTAssertFalse([mdmSetup readonlyProfile]);
  239. [verifyCount(_mockUserSettings, times(1)) setBlockUnknown:NO];
  240. [verifyCount(_mockUserSettings, times(1)) setHideStaleContacts:NO];
  241. [verifyCount(_mockUserSettings, times(2)) setSyncContacts:NO];
  242. XCTAssertFalse([mdmSetup disableSaveToGallery]);
  243. XCTAssertFalse([mdmSetup disableAddContact]);
  244. XCTAssertFalse([mdmSetup disableExport]);
  245. XCTAssertFalse([mdmSetup disableBackups]);
  246. XCTAssertFalse([mdmSetup disableIdExport]);
  247. XCTAssertFalse([mdmSetup disableSystemBackups]);
  248. XCTAssertFalse([mdmSetup disableMessagePreview]);
  249. XCTAssertFalse([mdmSetup disableSendProfilePicture]);
  250. XCTAssertFalse([mdmSetup disableCalls]);
  251. XCTAssertFalse([mdmSetup disableVideoCalls]);
  252. XCTAssertFalse([mdmSetup disableCreateGroup]);
  253. XCTAssertFalse([mdmSetup disableWeb]);
  254. XCTAssertFalse([mdmSetup disableShareMedia]);
  255. XCTAssertTrue([mdmSetup skipWizard]); // not renewable
  256. XCTAssertEqual(_no, [mdmSetup safeEnable]);
  257. XCTAssertEqual(@"87654321", [mdmSetup safePassword]);
  258. XCTAssertEqual(@"http://new-test.com", [mdmSetup safeServerUrl]);
  259. XCTAssertEqual(@"new-server-user", [mdmSetup safeServerUsername]);
  260. XCTAssertEqual(@"new-server-password", [mdmSetup safeServerPassword]);
  261. XCTAssertFalse([mdmSetup safeRestoreEnable]); // not renewable
  262. XCTAssertEqual(@"ECHOECHO", [mdmSetup safeRestoreId]); // not renewable
  263. XCTAssertEqual(@"new-^[0-9]{1,15}$", [mdmSetup safePasswordPattern]);
  264. XCTAssertEqual(@"New-Wrong-password-pattern", [mdmSetup safePasswordMessage]);
  265. XCTAssertEqual(@"new.threema.ch", [mdmSetup webHosts]);
  266. }
  267. /// Bestehende Firmen MDM-Parameter werden von renewable Threema MDM-Parameter überschrieben (kein "setup" sync)
  268. - (void)testApplyThreemaMdmWithCompanyMdmAndNoThreemaMdmDoOverrideSetupNo {
  269. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  270. // Company-MDM and NO "old" Threema-MDM
  271. [self setMdm:[self getAllMdmParameters:NO] threemaMdm:nil];
  272. // "new" Threema-MDM (override)
  273. id keysThreemaMdm[] = { MDM_KEY_LICENSE_USERNAME, MDM_KEY_LICENSE_PASSWORD, MDM_KEY_NICKNAME, MDM_KEY_FIRST_NAME, MDM_KEY_LAST_NAME, MDM_KEY_CSI, MDM_KEY_CATEGORY, MDM_KEY_LINKED_EMAIL, MDM_KEY_LINKED_PHONE, MDM_KEY_CONTACT_SYNC, MDM_KEY_READONLY_PROFILE, MDM_KEY_BLOCK_UNKNOWN, MDM_KEY_HIDE_INACTIVE_IDS, MDM_KEY_DISABLE_SAVE_TO_GALLERY, MDM_KEY_DISABLE_ADD_CONTACT, MDM_KEY_DISABLE_EXPORT, MDM_KEY_DISABLE_BACKUPS, MDM_KEY_DISABLE_ID_EXPORT, MDM_KEY_DISABLE_SYSTEM_BACKUPS, MDM_KEY_DISABLE_MESSAGE_PREVIEW, MDM_KEY_DISABLE_SEND_PROFILE_PICTURE, MDM_KEY_DISABLE_CALLS, MDM_KEY_DISABLE_VIDEO_CALLS, MDM_KEY_SKIP_WIZARD, MDM_KEY_DISABLE_CREATE_GROUP, MDM_KEY_DISABLE_WEB, MDM_KEY_SAFE_ENABLE, MDM_KEY_SAFE_SERVER_URL, MDM_KEY_SAFE_SERVER_USERNAME, MDM_KEY_SAFE_SERVER_PASSWORD, MDM_KEY_SAFE_RESTORE_ENABLE, MDM_KEY_SAFE_RESTORE_ID, MDM_KEY_SAFE_PASSWORD_PATTERN, MDM_KEY_SAFE_PASSWORD_MESSAGE, MDM_KEY_WEB_HOSTS, MDM_KEY_DISABLE_SHARE_MEDIA};
  274. id objectsThreemaMdm[] = { @"new-tester", @"new-test1234", @"New-Eieri", @"New-Heiri", @"New-Heirassa", @"new-customer-id", @"new-category", @"new-linked@email.com", @"222", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", _no, @"http://new-test.com", @"new-server-user", @"new-server-password", @"1", @"EINSZWEI", @"new-^[0-9]{1,15}$", @"New-Wrong-password-pattern", @"new.threema.ch", @"0" };
  275. NSUInteger countThreemaMdm = sizeof(objectsThreemaMdm) / sizeof(id);
  276. NSDictionary *threemaMdm = [NSDictionary dictionaryWithObjects:objectsThreemaMdm forKeys:keysThreemaMdm count:countThreemaMdm];
  277. NSDictionary *workData = @{MDM_KEY_THREEMA_CONFIGURATION: @{MDM_KEY_THREEMA_OVERRIDE:@true,MDM_KEY_THREEMA_PARAMS:threemaMdm}};
  278. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:NO];
  279. [mdmSetup applyThreemaMdm:workData];
  280. [verify(_mockLicenseStore) setLicenseUsername:@"new-tester"];
  281. [verify(_mockLicenseStore) setLicensePassword:@"new-test1234"];
  282. [verifyCount(_mockMyIdentityStore, times(1)) setPushFromName:@"New-Eieri"];
  283. [verifyCount(_mockMyIdentityStore, times(1)) setFirstName:@"New-Heiri"];
  284. [verifyCount(_mockMyIdentityStore, times(1)) setLastName:@"New-Heirassa"];
  285. [verifyCount(_mockMyIdentityStore, times(1)) setCsi:@"new-customer-id"];
  286. [verifyCount(_mockMyIdentityStore, times(1)) setCategory:@"new-category"];
  287. [verifyCount(_mockMyIdentityStore, times(1)) setCreateIDEmail:@"linked@email.com"]; // not renewable
  288. [verifyCount(_mockMyIdentityStore, times(1)) setCreateIDPhone:@"111"]; // not renewable
  289. XCTAssertFalse([mdmSetup readonlyProfile]);
  290. [verifyCount(_mockUserSettings, times(1)) setBlockUnknown:NO];
  291. [verifyCount(_mockUserSettings, times(2)) setSyncContacts:NO];
  292. [verifyCount(_mockUserSettings, times(1)) setHideStaleContacts:NO];
  293. XCTAssertFalse([mdmSetup disableSaveToGallery]);
  294. XCTAssertFalse([mdmSetup disableAddContact]);
  295. XCTAssertFalse([mdmSetup disableExport]);
  296. XCTAssertFalse([mdmSetup disableBackups]);
  297. XCTAssertFalse([mdmSetup disableIdExport]);
  298. XCTAssertFalse([mdmSetup disableSystemBackups]);
  299. XCTAssertFalse([mdmSetup disableMessagePreview]);
  300. XCTAssertFalse([mdmSetup disableSendProfilePicture]);
  301. XCTAssertFalse([mdmSetup disableCalls]);
  302. XCTAssertFalse([mdmSetup disableVideoCalls]);
  303. XCTAssertFalse([mdmSetup disableCreateGroup]);
  304. XCTAssertFalse([mdmSetup disableWeb]);
  305. XCTAssertFalse([mdmSetup disableShareMedia]);
  306. XCTAssertTrue([mdmSetup skipWizard]); // not renewable
  307. XCTAssertEqual(_no, [mdmSetup safeEnable]);
  308. XCTAssertEqual(@"87654321", [mdmSetup safePassword]);
  309. XCTAssertEqual(@"http://new-test.com", [mdmSetup safeServerUrl]);
  310. XCTAssertEqual(@"new-server-user", [mdmSetup safeServerUsername]);
  311. XCTAssertEqual(@"new-server-password", [mdmSetup safeServerPassword]);
  312. XCTAssertFalse([mdmSetup safeRestoreEnable]); // not renewable
  313. XCTAssertEqual(@"ECHOECHO", [mdmSetup safeRestoreId]); // not renewable
  314. XCTAssertEqual(@"new-^[0-9]{1,15}$", [mdmSetup safePasswordPattern]);
  315. XCTAssertEqual(@"New-Wrong-password-pattern", [mdmSetup safePasswordMessage]);
  316. XCTAssertEqual(@"new.threema.ch", [mdmSetup webHosts]);
  317. }
  318. /// Keine bestehende MDM-Parameter, alle renewable Threema MDM-Parameter werden übernommen (kein "setup" sync)
  319. - (void)testApplyThreemaMdmWithNoCompanyMdmAndNoThreemaMdmDoOverrideSetupNo {
  320. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  321. // No Company-MDM and no "old" Threema-MDM are equal
  322. // new Threema-MDM (override)
  323. id keysThreemaMdm[] = { MDM_KEY_LICENSE_USERNAME, MDM_KEY_LICENSE_PASSWORD, MDM_KEY_NICKNAME, MDM_KEY_FIRST_NAME, MDM_KEY_LAST_NAME, MDM_KEY_CSI, MDM_KEY_CATEGORY, MDM_KEY_LINKED_EMAIL, MDM_KEY_LINKED_PHONE, MDM_KEY_CONTACT_SYNC, MDM_KEY_READONLY_PROFILE, MDM_KEY_BLOCK_UNKNOWN, MDM_KEY_HIDE_INACTIVE_IDS, MDM_KEY_DISABLE_SAVE_TO_GALLERY, MDM_KEY_DISABLE_ADD_CONTACT, MDM_KEY_DISABLE_EXPORT, MDM_KEY_DISABLE_BACKUPS, MDM_KEY_DISABLE_ID_EXPORT, MDM_KEY_DISABLE_SYSTEM_BACKUPS, MDM_KEY_DISABLE_MESSAGE_PREVIEW, MDM_KEY_DISABLE_SEND_PROFILE_PICTURE, MDM_KEY_DISABLE_CALLS, MDM_KEY_DISABLE_VIDEO_CALLS, MDM_KEY_SKIP_WIZARD, MDM_KEY_DISABLE_CREATE_GROUP, MDM_KEY_DISABLE_WEB, MDM_KEY_SAFE_ENABLE, MDM_KEY_SAFE_SERVER_URL, MDM_KEY_SAFE_SERVER_USERNAME, MDM_KEY_SAFE_SERVER_PASSWORD, MDM_KEY_SAFE_RESTORE_ENABLE, MDM_KEY_SAFE_RESTORE_ID, MDM_KEY_SAFE_PASSWORD_PATTERN, MDM_KEY_SAFE_PASSWORD_MESSAGE, MDM_KEY_WEB_HOSTS, MDM_KEY_DISABLE_SHARE_MEDIA};
  324. id objectsThreemaMdm[] = { @"new-tester", @"new-test1234", @"New-Eieri", @"New-Heiri", @"New-Heirassa", @"new-customer-id", @"new-category", @"new-linked@email.com", @"222", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", _no, @"http://new-test.com", @"new-server-user", @"new-server-password", @"1", @"EINSZWEI", @"new-^[0-9]{1,15}$", @"New-Wrong-password-pattern", @"new.threema.ch", @"0" };
  325. NSUInteger countThreemaMdm = sizeof(objectsThreemaMdm) / sizeof(id);
  326. NSDictionary *threemaMdm = [NSDictionary dictionaryWithObjects:objectsThreemaMdm forKeys:keysThreemaMdm count:countThreemaMdm];
  327. NSDictionary *workData = @{MDM_KEY_THREEMA_CONFIGURATION: @{MDM_KEY_THREEMA_OVERRIDE:@true,MDM_KEY_THREEMA_PARAMS:threemaMdm}};
  328. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:NO];
  329. [mdmSetup applyThreemaMdm:workData];
  330. [verify(_mockLicenseStore) setLicenseUsername:@"new-tester"];
  331. [verify(_mockLicenseStore) setLicensePassword:@"new-test1234"];
  332. [verifyCount(_mockMyIdentityStore, times(0)) setPushFromName:@"New-Heiri"];
  333. [verifyCount(_mockMyIdentityStore, times(1)) setFirstName:@"New-Heiri"];
  334. [verifyCount(_mockMyIdentityStore, times(1)) setLastName:@"New-Heirassa"];
  335. [verifyCount(_mockMyIdentityStore, times(1)) setCsi:@"new-customer-id"];
  336. [verifyCount(_mockMyIdentityStore, times(1)) setCategory:@"new-category"];
  337. [verifyCount(_mockMyIdentityStore, times(0)) setCreateIDEmail:anything()]; // not renewable
  338. [verifyCount(_mockMyIdentityStore, times(0)) setCreateIDPhone:anything()]; // not renewable
  339. XCTAssertFalse([mdmSetup readonlyProfile]);
  340. [verifyCount(_mockUserSettings, times(1)) setBlockUnknown:NO];
  341. XCTAssertTrue([mdmSetup existsMdmKey:MDM_KEY_BLOCK_UNKNOWN]);
  342. [verifyCount(_mockUserSettings, times(2)) setSyncContacts:NO];
  343. XCTAssertTrue([mdmSetup existsMdmKey:MDM_KEY_CONTACT_SYNC]);
  344. [verifyCount(_mockUserSettings, times(1)) setHideStaleContacts:NO];
  345. XCTAssertTrue([mdmSetup existsMdmKey:MDM_KEY_HIDE_INACTIVE_IDS]);
  346. XCTAssertFalse([mdmSetup disableSaveToGallery]);
  347. XCTAssertFalse([mdmSetup disableAddContact]);
  348. XCTAssertFalse([mdmSetup disableExport]);
  349. XCTAssertFalse([mdmSetup disableBackups]);
  350. XCTAssertFalse([mdmSetup disableIdExport]);
  351. XCTAssertFalse([mdmSetup disableSystemBackups]);
  352. XCTAssertFalse([mdmSetup disableMessagePreview]);
  353. XCTAssertFalse([mdmSetup disableSendProfilePicture]);
  354. XCTAssertFalse([mdmSetup disableCalls]);
  355. XCTAssertFalse([mdmSetup disableVideoCalls]);
  356. XCTAssertFalse([mdmSetup disableCreateGroup]);
  357. XCTAssertFalse([mdmSetup disableWeb]);
  358. XCTAssertFalse([mdmSetup disableShareMedia]);
  359. XCTAssertFalse([mdmSetup skipWizard]); // not renewable
  360. XCTAssertEqual(_no, [mdmSetup safeEnable]);
  361. XCTAssertNil([mdmSetup safePassword]);
  362. XCTAssertEqual(@"http://new-test.com", [mdmSetup safeServerUrl]);
  363. XCTAssertEqual(@"new-server-user", [mdmSetup safeServerUsername]);
  364. XCTAssertEqual(@"new-server-password", [mdmSetup safeServerPassword]);
  365. XCTAssertTrue([mdmSetup safeRestoreEnable]); // not renewable
  366. XCTAssertNil([mdmSetup safeRestoreId]); // not renewable
  367. XCTAssertEqual(@"new-^[0-9]{1,15}$", [mdmSetup safePasswordPattern]);
  368. XCTAssertEqual(@"New-Wrong-password-pattern", [mdmSetup safePasswordMessage]);
  369. XCTAssertEqual(@"new.threema.ch", [mdmSetup webHosts]);
  370. }
  371. /// Bestehende Threema MDM-Parameter weden entfernt
  372. - (void)testApplyThreemaMdmMissingParametersDoOverrideSetupNo {
  373. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  374. // "old" Threema-MDM
  375. NSDictionary *oldWorkData = @{MDM_KEY_THREEMA_OVERRIDE:@true,MDM_KEY_THREEMA_PARAMS:[self getAllMdmParameters:YES]};
  376. [self setMdm:nil threemaMdm:oldWorkData];
  377. // "new" Threema-MDM (+)
  378. id keysThreemaMdm[] = { MDM_KEY_LICENSE_USERNAME, MDM_KEY_LICENSE_PASSWORD, MDM_KEY_LINKED_EMAIL, MDM_KEY_LINKED_PHONE, MDM_KEY_SKIP_WIZARD, };
  379. id objectsThreemaMdm[] = { @"new-tester", @"new-test1234", @"new-linked@email.com", @"222", @"0" };
  380. NSUInteger countThreemaMdm = sizeof(objectsThreemaMdm) / sizeof(id);
  381. NSDictionary *threemaMdm = [NSDictionary dictionaryWithObjects:objectsThreemaMdm forKeys:keysThreemaMdm count:countThreemaMdm];
  382. NSDictionary *workData = @{MDM_KEY_THREEMA_CONFIGURATION: @{MDM_KEY_THREEMA_OVERRIDE:@true,MDM_KEY_THREEMA_PARAMS:threemaMdm}};
  383. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:NO];
  384. [mdmSetup applyThreemaMdm:workData];
  385. [verify(_mockLicenseStore) setLicenseUsername:@"new-tester"];
  386. [verify(_mockLicenseStore) setLicensePassword:@"new-test1234"];
  387. [verifyCount(_mockMyIdentityStore, times(0)) setPushFromName:anything()];
  388. [verifyCount(_mockMyIdentityStore, times(0)) setFirstName:anything()];
  389. [verifyCount(_mockMyIdentityStore, times(0)) setLastName:anything()];
  390. [verifyCount(_mockMyIdentityStore, times(0)) setCsi:anything()];
  391. [verifyCount(_mockMyIdentityStore, times(0)) setCategory:anything()];
  392. [verifyCount(_mockMyIdentityStore, times(0)) setCreateIDEmail:anything()]; // not renewable
  393. [verifyCount(_mockMyIdentityStore, times(0)) setCreateIDPhone:anything()]; // not renewable
  394. XCTAssertFalse([mdmSetup readonlyProfile]);
  395. [verifyCount(_mockUserSettings, times(0)) setBlockUnknown:anything()];
  396. XCTAssertFalse([mdmSetup existsMdmKey:MDM_KEY_BLOCK_UNKNOWN]);
  397. [verifyCount(_mockUserSettings, times(0)) setSyncContacts:anything()];
  398. XCTAssertFalse([mdmSetup existsMdmKey:MDM_KEY_CONTACT_SYNC]);
  399. [verifyCount(_mockUserSettings, times(0)) setHideStaleContacts:anything()];
  400. XCTAssertFalse([mdmSetup existsMdmKey:MDM_KEY_HIDE_INACTIVE_IDS]);
  401. XCTAssertFalse([mdmSetup disableSaveToGallery]);
  402. XCTAssertFalse([mdmSetup disableAddContact]);
  403. XCTAssertFalse([mdmSetup disableExport]);
  404. XCTAssertFalse([mdmSetup disableBackups]);
  405. XCTAssertFalse([mdmSetup disableIdExport]);
  406. XCTAssertFalse([mdmSetup disableSystemBackups]);
  407. XCTAssertFalse([mdmSetup disableMessagePreview]);
  408. XCTAssertFalse([mdmSetup disableSendProfilePicture]);
  409. XCTAssertFalse([mdmSetup disableCalls]);
  410. XCTAssertFalse([mdmSetup disableVideoCalls]);
  411. XCTAssertFalse([mdmSetup disableCreateGroup]);
  412. XCTAssertFalse([mdmSetup disableWeb]);
  413. XCTAssertFalse([mdmSetup skipWizard]); // not renewable
  414. XCTAssertNil([mdmSetup safeEnable]);
  415. XCTAssertNil([mdmSetup safePassword]);
  416. XCTAssertNil([mdmSetup safeServerUrl]);
  417. XCTAssertNil([mdmSetup safeServerUsername]);
  418. XCTAssertNil([mdmSetup safeServerPassword]);
  419. XCTAssertTrue([mdmSetup safeRestoreEnable]);
  420. XCTAssertNil([mdmSetup safeRestoreId]);
  421. XCTAssertNil([mdmSetup safePasswordPattern]);
  422. XCTAssertNil([mdmSetup safePasswordMessage]);
  423. XCTAssertNil([mdmSetup webHosts]);
  424. }
  425. /// Bestehendes Threema MDM wird deaktiviert
  426. - (void)testApplyThreemaMdmWithNoThreemaMdmDoOverrideSetupNo {
  427. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  428. // "old" Threema-MDM
  429. NSDictionary *oldWorkData = @{MDM_KEY_THREEMA_OVERRIDE:@true,MDM_KEY_THREEMA_PARAMS:[self getAllMdmParameters:YES]};
  430. [self setMdm:nil threemaMdm:oldWorkData];
  431. // NO "new" Threema-MDM
  432. NSDictionary *workData = @{};
  433. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:NO];
  434. [mdmSetup applyThreemaMdm:workData];
  435. [verifyCount(_mockLicenseStore, times(0)) setLicenseUsername:anything()];
  436. [verifyCount(_mockLicenseStore, times(0)) setLicensePassword:anything()];
  437. [verifyCount(_mockMyIdentityStore, times(0)) setPushFromName:anything()];
  438. [verifyCount(_mockMyIdentityStore, times(0)) setFirstName:anything()];
  439. [verifyCount(_mockMyIdentityStore, times(0)) setLastName:anything()];
  440. [verifyCount(_mockMyIdentityStore, times(0)) setCsi:anything()];
  441. [verifyCount(_mockMyIdentityStore, times(0)) setCategory:anything()];
  442. [verifyCount(_mockMyIdentityStore, times(0)) setCreateIDEmail:anything()];
  443. [verifyCount(_mockMyIdentityStore, times(0)) setCreateIDPhone:anything()];
  444. XCTAssertFalse([mdmSetup readonlyProfile]);
  445. [verifyCount(_mockUserSettings, times(0)) setBlockUnknown:anything()];
  446. XCTAssertFalse([mdmSetup existsMdmKey:MDM_KEY_BLOCK_UNKNOWN]);
  447. [verifyCount(_mockUserSettings, times(0)) setSyncContacts:anything()];
  448. XCTAssertFalse([mdmSetup existsMdmKey:MDM_KEY_CONTACT_SYNC]);
  449. [verifyCount(_mockUserSettings, times(0)) setHideStaleContacts:anything()];
  450. XCTAssertFalse([mdmSetup existsMdmKey:MDM_KEY_HIDE_INACTIVE_IDS]);
  451. XCTAssertFalse([mdmSetup disableSaveToGallery]);
  452. XCTAssertFalse([mdmSetup disableAddContact]);
  453. XCTAssertFalse([mdmSetup disableExport]);
  454. XCTAssertFalse([mdmSetup disableBackups]);
  455. XCTAssertFalse([mdmSetup disableIdExport]);
  456. XCTAssertFalse([mdmSetup disableSystemBackups]);
  457. XCTAssertFalse([mdmSetup disableMessagePreview]);
  458. XCTAssertFalse([mdmSetup disableSendProfilePicture]);
  459. XCTAssertFalse([mdmSetup disableCalls]);
  460. XCTAssertFalse([mdmSetup disableVideoCalls]);
  461. XCTAssertFalse([mdmSetup disableCreateGroup]);
  462. XCTAssertFalse([mdmSetup disableWeb]);
  463. XCTAssertFalse([mdmSetup skipWizard]);
  464. XCTAssertNil([mdmSetup safeEnable]);
  465. XCTAssertNil([mdmSetup safePassword]);
  466. XCTAssertNil([mdmSetup safeServerUrl]);
  467. XCTAssertNil([mdmSetup safeServerUsername]);
  468. XCTAssertNil([mdmSetup safeServerPassword]);
  469. XCTAssertTrue([mdmSetup safeRestoreEnable]);
  470. XCTAssertNil([mdmSetup safeRestoreId]);
  471. XCTAssertNil([mdmSetup safePasswordPattern]);
  472. XCTAssertNil([mdmSetup safePasswordMessage]);
  473. XCTAssertNil([mdmSetup webHosts]);
  474. }
  475. /// Bestehendes Firmen MDM wird mit Threema MDM aktulisiert ("normaler" sync: NICHT renewable Parameter werden NICHT übernommen)
  476. - (void)testApplyThreemaMdmWithCompanyMdmAddingThreemaMdmDoOverrideSetupNo {
  477. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  478. // Company-MDM and NO "old" Threema-MDM
  479. id keysCompanyMdm[] = { MDM_KEY_LICENSE_USERNAME, MDM_KEY_LICENSE_PASSWORD, MDM_KEY_LINKED_EMAIL, MDM_KEY_LINKED_PHONE, MDM_KEY_SKIP_WIZARD, MDM_KEY_SAFE_PASSWORD, };
  480. id objectsCompanyMdm[] = { @"company-tester", @"company-test1234", @"company-linked@email.com", @"555", @"0", @"12345678" };
  481. NSUInteger countCompanyMdm = sizeof(objectsCompanyMdm) / sizeof(id);
  482. NSDictionary *companyMdm = [NSDictionary dictionaryWithObjects:objectsCompanyMdm forKeys:keysCompanyMdm count:countCompanyMdm];
  483. [self setMdm:companyMdm threemaMdm:nil];
  484. // "new" Threema-MDM (override)
  485. id keysMdm[] = { MDM_KEY_NICKNAME, MDM_KEY_FIRST_NAME, MDM_KEY_LAST_NAME, MDM_KEY_CSI, MDM_KEY_CATEGORY, MDM_KEY_CONTACT_SYNC, MDM_KEY_READONLY_PROFILE, MDM_KEY_BLOCK_UNKNOWN, MDM_KEY_HIDE_INACTIVE_IDS, MDM_KEY_DISABLE_SAVE_TO_GALLERY, MDM_KEY_DISABLE_ADD_CONTACT, MDM_KEY_DISABLE_EXPORT, MDM_KEY_DISABLE_BACKUPS, MDM_KEY_DISABLE_ID_EXPORT, MDM_KEY_DISABLE_SYSTEM_BACKUPS, MDM_KEY_DISABLE_MESSAGE_PREVIEW, MDM_KEY_DISABLE_SEND_PROFILE_PICTURE, MDM_KEY_DISABLE_CALLS, MDM_KEY_DISABLE_VIDEO_CALLS, MDM_KEY_SKIP_WIZARD, MDM_KEY_DISABLE_CREATE_GROUP, MDM_KEY_DISABLE_WEB, MDM_KEY_SAFE_ENABLE, MDM_KEY_SAFE_SERVER_URL, MDM_KEY_SAFE_SERVER_USERNAME, MDM_KEY_SAFE_SERVER_PASSWORD, MDM_KEY_SAFE_RESTORE_ENABLE, MDM_KEY_SAFE_RESTORE_ID, MDM_KEY_SAFE_PASSWORD_PATTERN, MDM_KEY_SAFE_PASSWORD_MESSAGE, MDM_KEY_WEB_HOSTS, MDM_KEY_DISABLE_SHARE_MEDIA };
  486. id objectsMdm[] = { @"Eieri", @"Heiri", @"Heirassa", @"customer-id", @"category" ,@"1" ,@"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", _yes, @"http://test.com", @"server-user", @"server-password", @"0", @"ECHOECHO", @"^[0-9]{1,15}$", @"Wrong-password-pattern", @"new.threema.ch", @"1" };
  487. NSUInteger countMdm = sizeof(objectsMdm) / sizeof(id);
  488. NSDictionary *mdm = [NSDictionary dictionaryWithObjects:objectsMdm forKeys:keysMdm count:countMdm];
  489. NSDictionary *workData = @{MDM_KEY_THREEMA_CONFIGURATION: @{MDM_KEY_THREEMA_OVERRIDE:@true,MDM_KEY_THREEMA_PARAMS:mdm}};
  490. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:NO];
  491. [mdmSetup applyThreemaMdm:workData];
  492. [verify(_mockLicenseStore) setLicenseUsername:@"company-tester"];
  493. [verify(_mockLicenseStore) setLicensePassword:@"company-test1234"];
  494. [verifyCount(_mockMyIdentityStore, times(1)) setPushFromName:@"Eieri"];
  495. [verifyCount(_mockMyIdentityStore, times(1)) setFirstName:@"Heiri"];
  496. [verifyCount(_mockMyIdentityStore, times(1)) setLastName:@"Heirassa"];
  497. [verifyCount(_mockMyIdentityStore, times(1)) setCsi:@"customer-id"];
  498. [verifyCount(_mockMyIdentityStore, times(1)) setCategory:@"category"];
  499. [verifyCount(_mockMyIdentityStore, times(1)) setCreateIDEmail:@"company-linked@email.com"]; // not renewable
  500. [verifyCount(_mockMyIdentityStore, times(1)) setCreateIDPhone:@"555"]; // not renewable
  501. XCTAssertTrue([mdmSetup readonlyProfile]);
  502. [verifyCount(_mockUserSettings, times(1)) setBlockUnknown:YES];
  503. XCTAssertTrue([mdmSetup existsMdmKey:MDM_KEY_BLOCK_UNKNOWN]);
  504. [verifyCount(_mockUserSettings, times(2)) setSyncContacts:YES];
  505. XCTAssertTrue([mdmSetup existsMdmKey:MDM_KEY_CONTACT_SYNC]);
  506. [verifyCount(_mockUserSettings, times(1)) setHideStaleContacts:YES];
  507. XCTAssertTrue([mdmSetup existsMdmKey:MDM_KEY_HIDE_INACTIVE_IDS]);
  508. XCTAssertTrue([mdmSetup disableSaveToGallery]);
  509. XCTAssertTrue([mdmSetup disableAddContact]);
  510. XCTAssertTrue([mdmSetup disableExport]);
  511. XCTAssertTrue([mdmSetup disableBackups]);
  512. XCTAssertTrue([mdmSetup disableIdExport]);
  513. XCTAssertTrue([mdmSetup disableSystemBackups]);
  514. XCTAssertTrue([mdmSetup disableMessagePreview]);
  515. XCTAssertTrue([mdmSetup disableSendProfilePicture]);
  516. XCTAssertTrue([mdmSetup disableCalls]);
  517. XCTAssertTrue([mdmSetup disableVideoCalls]);
  518. XCTAssertTrue([mdmSetup disableCreateGroup]);
  519. XCTAssertTrue([mdmSetup disableWeb]);
  520. XCTAssertTrue([mdmSetup disableShareMedia]);
  521. XCTAssertFalse([mdmSetup skipWizard]); // not renewable
  522. XCTAssertTrue([mdmSetup safeEnable]);
  523. XCTAssertEqual(@"12345678", [mdmSetup safePassword]);
  524. XCTAssertEqual(@"http://test.com", [mdmSetup safeServerUrl]);
  525. XCTAssertEqual(@"server-user", [mdmSetup safeServerUsername]);
  526. XCTAssertEqual(@"server-password", [mdmSetup safeServerPassword]);
  527. XCTAssertTrue([mdmSetup safeRestoreEnable]); // not renewable
  528. XCTAssertNil([mdmSetup safeRestoreId]); // not renewable
  529. XCTAssertEqual(@"^[0-9]{1,15}$", [mdmSetup safePasswordPattern]);
  530. XCTAssertEqual(@"Wrong-password-pattern", [mdmSetup safePasswordMessage]);
  531. XCTAssertEqual(@"new.threema.ch", [mdmSetup webHosts]);
  532. }
  533. /// Bestehendes Firmen MDM wird mit Threema MDM aktulisiert ("setup" sync: NICHT renewable Parameter werden übernommen)
  534. - (void)testApplyThreemaMdmWithCompanyMdmAddingThreemaMdmDoOverrideSetupYes {
  535. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  536. // Company-MDM and NO "old" Threema-MDM
  537. id keysCompanyMdm[] = { MDM_KEY_LICENSE_USERNAME, MDM_KEY_LICENSE_PASSWORD, MDM_KEY_LINKED_EMAIL, MDM_KEY_LINKED_PHONE, MDM_KEY_SKIP_WIZARD, MDM_KEY_SAFE_PASSWORD, };
  538. id objectsCompanyMdm[] = { @"company-tester", @"company-test1234", @"company-linked@email.com", @"555", @"0", @"12345678" };
  539. NSUInteger countCompanyMdm = sizeof(objectsCompanyMdm) / sizeof(id);
  540. NSDictionary *companyMdm = [NSDictionary dictionaryWithObjects:objectsCompanyMdm forKeys:keysCompanyMdm count:countCompanyMdm];
  541. [self setMdm:companyMdm threemaMdm:nil];
  542. // "new" Threema-MDM (override)
  543. id keysMdm[] = { MDM_KEY_NICKNAME, MDM_KEY_FIRST_NAME, MDM_KEY_LAST_NAME, MDM_KEY_CSI, MDM_KEY_CATEGORY, MDM_KEY_CONTACT_SYNC, MDM_KEY_READONLY_PROFILE, MDM_KEY_BLOCK_UNKNOWN, MDM_KEY_HIDE_INACTIVE_IDS, MDM_KEY_DISABLE_SAVE_TO_GALLERY, MDM_KEY_DISABLE_ADD_CONTACT, MDM_KEY_DISABLE_EXPORT, MDM_KEY_DISABLE_BACKUPS, MDM_KEY_DISABLE_ID_EXPORT, MDM_KEY_DISABLE_SYSTEM_BACKUPS, MDM_KEY_DISABLE_MESSAGE_PREVIEW, MDM_KEY_DISABLE_SEND_PROFILE_PICTURE, MDM_KEY_DISABLE_CALLS, MDM_KEY_DISABLE_VIDEO_CALLS, MDM_KEY_SKIP_WIZARD, MDM_KEY_DISABLE_CREATE_GROUP, MDM_KEY_DISABLE_WEB, MDM_KEY_SAFE_ENABLE, MDM_KEY_SAFE_SERVER_URL, MDM_KEY_SAFE_SERVER_USERNAME, MDM_KEY_SAFE_SERVER_PASSWORD, MDM_KEY_SAFE_RESTORE_ENABLE, MDM_KEY_SAFE_RESTORE_ID, MDM_KEY_SAFE_PASSWORD_PATTERN, MDM_KEY_SAFE_PASSWORD_MESSAGE, MDM_KEY_WEB_HOSTS, MDM_KEY_DISABLE_SHARE_MEDIA };
  544. id objectsMdm[] = { @"Eieri", @"Heiri", @"Heirassa", @"customer-id", @"category" ,@"1" ,@"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", _yes, @"http://test.com", @"server-user", @"server-password", @"0", @"ECHOECHO", @"^[0-9]{1,15}$", @"Wrong-password-pattern", @"new.threema.ch", @"1" };
  545. NSUInteger countMdm = sizeof(objectsMdm) / sizeof(id);
  546. NSDictionary *mdm = [NSDictionary dictionaryWithObjects:objectsMdm forKeys:keysMdm count:countMdm];
  547. NSDictionary *workData = @{MDM_KEY_THREEMA_CONFIGURATION: @{MDM_KEY_THREEMA_OVERRIDE:@true,MDM_KEY_THREEMA_PARAMS:mdm}};
  548. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:YES];
  549. [mdmSetup applyThreemaMdm:workData];
  550. [verify(_mockLicenseStore) setLicenseUsername:@"company-tester"];
  551. [verify(_mockLicenseStore) setLicensePassword:@"company-test1234"];
  552. [verifyCount(_mockMyIdentityStore, times(1)) setPushFromName:@"Eieri"]; // not renewable
  553. [verifyCount(_mockMyIdentityStore, times(1)) setFirstName:@"Heiri"];
  554. [verifyCount(_mockMyIdentityStore, times(1)) setLastName:@"Heirassa"];
  555. [verifyCount(_mockMyIdentityStore, times(1)) setCsi:@"customer-id"];
  556. [verifyCount(_mockMyIdentityStore, times(1)) setCategory:@"category"];
  557. [verifyCount(_mockMyIdentityStore, times(1)) setCreateIDEmail:@"company-linked@email.com"]; // not renewable
  558. [verifyCount(_mockMyIdentityStore, times(1)) setCreateIDPhone:@"555"]; // not renewable
  559. XCTAssertTrue([mdmSetup readonlyProfile]);
  560. [verifyCount(_mockUserSettings, times(1)) setBlockUnknown:YES];
  561. XCTAssertTrue([mdmSetup existsMdmKey:MDM_KEY_BLOCK_UNKNOWN]);
  562. [verifyCount(_mockUserSettings, times(2)) setSyncContacts:YES];
  563. XCTAssertTrue([mdmSetup existsMdmKey:MDM_KEY_CONTACT_SYNC]);
  564. [verifyCount(_mockUserSettings, times(1)) setHideStaleContacts:YES];
  565. XCTAssertTrue([mdmSetup existsMdmKey:MDM_KEY_HIDE_INACTIVE_IDS]);
  566. XCTAssertTrue([mdmSetup disableSaveToGallery]);
  567. XCTAssertTrue([mdmSetup disableAddContact]);
  568. XCTAssertTrue([mdmSetup disableExport]);
  569. XCTAssertTrue([mdmSetup disableBackups]);
  570. XCTAssertTrue([mdmSetup disableIdExport]);
  571. XCTAssertTrue([mdmSetup disableSystemBackups]);
  572. XCTAssertTrue([mdmSetup disableMessagePreview]);
  573. XCTAssertTrue([mdmSetup disableSendProfilePicture]);
  574. XCTAssertTrue([mdmSetup disableCalls]);
  575. XCTAssertTrue([mdmSetup disableVideoCalls]);
  576. XCTAssertTrue([mdmSetup disableCreateGroup]);
  577. XCTAssertTrue([mdmSetup disableWeb]);
  578. XCTAssertTrue([mdmSetup disableShareMedia]);
  579. XCTAssertTrue([mdmSetup skipWizard]); // not renewable
  580. XCTAssertTrue([mdmSetup safeEnable]);
  581. XCTAssertEqual(@"12345678", [mdmSetup safePassword]);
  582. XCTAssertEqual(@"http://test.com", [mdmSetup safeServerUrl]);
  583. XCTAssertEqual(@"server-user", [mdmSetup safeServerUsername]);
  584. XCTAssertEqual(@"server-password", [mdmSetup safeServerPassword]);
  585. XCTAssertFalse([mdmSetup safeRestoreEnable]); // not renewable
  586. XCTAssertEqual(@"ECHOECHO", [mdmSetup safeRestoreId]); // not renewable
  587. XCTAssertEqual(@"^[0-9]{1,15}$", [mdmSetup safePasswordPattern]);
  588. XCTAssertEqual(@"Wrong-password-pattern", [mdmSetup safePasswordMessage]);
  589. XCTAssertEqual(@"new.threema.ch", [mdmSetup webHosts]);
  590. }
  591. /// Work-Lizenz nicht gültig, gewisse renewable "MDM" Settings werden zurückgesetzt
  592. - (void)testNoLicenseRequired {
  593. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:NO];
  594. // "old" Threema-MDM
  595. NSDictionary *oldWorkData = @{MDM_KEY_THREEMA_OVERRIDE:@true,MDM_KEY_THREEMA_PARAMS:[self getAllMdmParameters:YES]};
  596. [self setMdm:nil threemaMdm:oldWorkData];
  597. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:NO];
  598. XCTAssertFalse(mdmSetup.isManaged);
  599. [verifyCount(_mockLicenseStore, times(0)) setLicenseUsername:anything()]; // not reset
  600. [verifyCount(_mockLicenseStore, times(0)) setLicensePassword:anything()]; // not reset
  601. [verifyCount(_mockMyIdentityStore, times(0)) setPushFromName:anything()]; // not reset
  602. [verifyCount(_mockMyIdentityStore, times(0)) setFirstName:anything()]; // not reset
  603. [verifyCount(_mockMyIdentityStore, times(0)) setLastName:anything()]; // not reset
  604. [verifyCount(_mockMyIdentityStore, times(0)) setCsi:anything()]; // not reset
  605. [verifyCount(_mockMyIdentityStore, times(0)) setCategory:anything()]; // not reset
  606. [verifyCount(_mockMyIdentityStore, times(0)) setCreateIDEmail:anything()]; // not reset
  607. [verifyCount(_mockMyIdentityStore, times(0)) setCreateIDPhone:anything()]; // not reset
  608. XCTAssertFalse([mdmSetup readonlyProfile]);
  609. [verifyCount(_mockUserSettings, times(0)) setBlockUnknown:anything()]; // not reset
  610. XCTAssertFalse([mdmSetup existsMdmKey:MDM_KEY_BLOCK_UNKNOWN]);
  611. [verifyCount(_mockUserSettings, times(0)) setSyncContacts:anything()];
  612. XCTAssertFalse([mdmSetup existsMdmKey:MDM_KEY_CONTACT_SYNC]);
  613. [verifyCount(_mockUserSettings, times(0)) setHideStaleContacts:anything()]; // not reset
  614. XCTAssertFalse([mdmSetup existsMdmKey:MDM_KEY_HIDE_INACTIVE_IDS]);
  615. XCTAssertFalse([mdmSetup disableSaveToGallery]);
  616. XCTAssertFalse([mdmSetup disableAddContact]);
  617. XCTAssertFalse([mdmSetup disableExport]);
  618. XCTAssertFalse([mdmSetup disableBackups]);
  619. XCTAssertFalse([mdmSetup disableIdExport]);
  620. XCTAssertFalse([mdmSetup disableSystemBackups]);
  621. XCTAssertFalse([mdmSetup disableMessagePreview]);
  622. XCTAssertFalse([mdmSetup disableSendProfilePicture]);
  623. XCTAssertFalse([mdmSetup disableCalls]);
  624. XCTAssertFalse([mdmSetup disableVideoCalls]);
  625. XCTAssertFalse([mdmSetup disableCreateGroup]);
  626. XCTAssertFalse([mdmSetup disableWeb]);
  627. XCTAssertFalse([mdmSetup skipWizard]);
  628. XCTAssertNil([mdmSetup safeEnable]);
  629. XCTAssertNil([mdmSetup safePassword]);
  630. XCTAssertNil([mdmSetup safeServerUrl]);
  631. XCTAssertNil([mdmSetup safeServerUsername]);
  632. XCTAssertNil([mdmSetup safeServerPassword]);
  633. XCTAssertTrue([mdmSetup safeRestoreEnable]);
  634. XCTAssertNil([mdmSetup safeRestoreId]);
  635. XCTAssertNil([mdmSetup safePasswordPattern]);
  636. XCTAssertNil([mdmSetup safePasswordMessage]);
  637. XCTAssertNil([mdmSetup webHosts]);
  638. }
  639. - (void)testSafeBackupDisable {
  640. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  641. // Company-MDM
  642. id keysCompanyMdm[] = { MDM_KEY_DISABLE_BACKUPS };
  643. id objectsCompanyMdm[] = { @"1" };
  644. NSUInteger countCompanyMdm = sizeof(objectsCompanyMdm) / sizeof(id);
  645. NSDictionary *companyMdm = [NSDictionary dictionaryWithObjects:objectsCompanyMdm forKeys:keysCompanyMdm count:countCompanyMdm];
  646. [self setMdm:companyMdm threemaMdm:nil];
  647. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:YES];
  648. XCTAssertTrue([mdmSetup isSafeBackupDisable]);
  649. XCTAssertFalse([mdmSetup isSafeBackupForce]);
  650. XCTAssertFalse([mdmSetup isSafeBackupPasswordPreset]);
  651. XCTAssertFalse([mdmSetup isSafeBackupServerPreset]);
  652. XCTAssertTrue([mdmSetup isSafeRestoreDisable]);
  653. XCTAssertFalse([mdmSetup isSafeRestoreForce]);
  654. XCTAssertFalse([mdmSetup isSafeRestorePasswordPreset]);
  655. XCTAssertFalse([mdmSetup isSafeRestoreServerPreset]);
  656. }
  657. - (void)testSafeBackupEnable {
  658. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  659. // Company-MDM
  660. id keysCompanyMdm[] = { MDM_KEY_DISABLE_BACKUPS };
  661. id objectsCompanyMdm[] = { @"0" };
  662. NSUInteger countCompanyMdm = sizeof(objectsCompanyMdm) / sizeof(id);
  663. NSDictionary *companyMdm = [NSDictionary dictionaryWithObjects:objectsCompanyMdm forKeys:keysCompanyMdm count:countCompanyMdm];
  664. [self setMdm:companyMdm threemaMdm:nil];
  665. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:YES];
  666. XCTAssertFalse([mdmSetup isSafeBackupDisable]);
  667. XCTAssertFalse([mdmSetup isSafeBackupForce]);
  668. XCTAssertFalse([mdmSetup isSafeBackupServerPreset]);
  669. XCTAssertFalse([mdmSetup isSafeBackupPasswordPreset]);
  670. XCTAssertFalse([mdmSetup isSafeRestoreDisable]);
  671. XCTAssertFalse([mdmSetup isSafeRestoreForce]);
  672. XCTAssertFalse([mdmSetup isSafeRestoreServerPreset]);
  673. XCTAssertFalse([mdmSetup isSafeRestorePasswordPreset]);
  674. }
  675. - (void)testBackupForce {
  676. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  677. // Company-MDM
  678. id keysCompanyMdm[] = { MDM_KEY_DISABLE_BACKUPS, MDM_KEY_SAFE_ENABLE };
  679. id objectsCompanyMdm[] = { @"0", [[NSNumber alloc] initWithInt:1] };
  680. NSUInteger countCompanyMdm = sizeof(objectsCompanyMdm) / sizeof(id);
  681. NSDictionary *companyMdm = [NSDictionary dictionaryWithObjects:objectsCompanyMdm forKeys:keysCompanyMdm count:countCompanyMdm];
  682. [self setMdm:companyMdm threemaMdm:nil];
  683. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:YES];
  684. XCTAssertFalse([mdmSetup isSafeBackupDisable]);
  685. XCTAssertTrue([mdmSetup isSafeBackupForce]);
  686. XCTAssertFalse([mdmSetup isSafeBackupServerPreset]);
  687. XCTAssertFalse([mdmSetup isSafeBackupPasswordPreset]);
  688. XCTAssertFalse([mdmSetup isSafeRestoreDisable]);
  689. XCTAssertFalse([mdmSetup isSafeRestoreForce]);
  690. XCTAssertFalse([mdmSetup isSafeRestoreServerPreset]);
  691. XCTAssertFalse([mdmSetup isSafeRestorePasswordPreset]);
  692. }
  693. - (void)testBackupWithServerAndPassword {
  694. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  695. // Company-MDM
  696. id keysCompanyMdm[] = { MDM_KEY_DISABLE_BACKUPS, MDM_KEY_SAFE_SERVER_URL, MDM_KEY_SAFE_PASSWORD };
  697. id objectsCompanyMdm[] = { @"0", @"https://example.com", @"password" };
  698. NSUInteger countCompanyMdm = sizeof(objectsCompanyMdm) / sizeof(id);
  699. NSDictionary *companyMdm = [NSDictionary dictionaryWithObjects:objectsCompanyMdm forKeys:keysCompanyMdm count:countCompanyMdm];
  700. [self setMdm:companyMdm threemaMdm:nil];
  701. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:YES];
  702. XCTAssertFalse([mdmSetup isSafeBackupDisable]);
  703. XCTAssertFalse([mdmSetup isSafeBackupForce]);
  704. XCTAssertTrue([mdmSetup isSafeBackupServerPreset]);
  705. XCTAssertFalse([mdmSetup isSafeBackupPasswordPreset]);
  706. XCTAssertFalse([mdmSetup isSafeRestoreDisable]);
  707. XCTAssertFalse([mdmSetup isSafeRestoreForce]);
  708. XCTAssertTrue([mdmSetup isSafeRestoreServerPreset]);
  709. XCTAssertFalse([mdmSetup isSafeRestorePasswordPreset]);
  710. }
  711. - (void)testBackupForceWithServerAndPassword {
  712. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  713. // Company-MDM
  714. id keysCompanyMdm[] = { MDM_KEY_DISABLE_BACKUPS, MDM_KEY_SAFE_ENABLE, MDM_KEY_SAFE_SERVER_URL, MDM_KEY_SAFE_PASSWORD };
  715. id objectsCompanyMdm[] = { @"0", [[NSNumber alloc] initWithInt:1], @"https://example.com", @"password" };
  716. NSUInteger countCompanyMdm = sizeof(objectsCompanyMdm) / sizeof(id);
  717. NSDictionary *companyMdm = [NSDictionary dictionaryWithObjects:objectsCompanyMdm forKeys:keysCompanyMdm count:countCompanyMdm];
  718. [self setMdm:companyMdm threemaMdm:nil];
  719. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:YES];
  720. XCTAssertFalse([mdmSetup isSafeBackupDisable]);
  721. XCTAssertTrue([mdmSetup isSafeBackupForce]);
  722. XCTAssertTrue([mdmSetup isSafeBackupServerPreset]);
  723. XCTAssertTrue([mdmSetup isSafeBackupPasswordPreset]);
  724. XCTAssertFalse([mdmSetup isSafeRestoreDisable]);
  725. XCTAssertFalse([mdmSetup isSafeRestoreForce]);
  726. XCTAssertTrue([mdmSetup isSafeRestoreServerPreset]);
  727. XCTAssertFalse([mdmSetup isSafeRestorePasswordPreset]);
  728. }
  729. - (void)testRestoreDisable {
  730. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  731. // Company-MDM
  732. id keysCompanyMdm[] = { MDM_KEY_SAFE_RESTORE_ENABLE };
  733. id objectsCompanyMdm[] = { @"0" };
  734. NSUInteger countCompanyMdm = sizeof(objectsCompanyMdm) / sizeof(id);
  735. NSDictionary *companyMdm = [NSDictionary dictionaryWithObjects:objectsCompanyMdm forKeys:keysCompanyMdm count:countCompanyMdm];
  736. [self setMdm:companyMdm threemaMdm:nil];
  737. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:YES];
  738. XCTAssertFalse([mdmSetup isSafeBackupDisable]);
  739. XCTAssertFalse([mdmSetup isSafeBackupForce]);
  740. XCTAssertFalse([mdmSetup isSafeBackupServerPreset]);
  741. XCTAssertFalse([mdmSetup isSafeBackupPasswordPreset]);
  742. XCTAssertTrue([mdmSetup isSafeRestoreDisable]);
  743. XCTAssertFalse([mdmSetup isSafeRestoreForce]);
  744. XCTAssertFalse([mdmSetup isSafeRestoreServerPreset]);
  745. XCTAssertFalse([mdmSetup isSafeRestorePasswordPreset]);
  746. }
  747. - (void)testRestoreEnable {
  748. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  749. // Company-MDM
  750. id keysCompanyMdm[] = { MDM_KEY_SAFE_RESTORE_ENABLE };
  751. id objectsCompanyMdm[] = { @"1" };
  752. NSUInteger countCompanyMdm = sizeof(objectsCompanyMdm) / sizeof(id);
  753. NSDictionary *companyMdm = [NSDictionary dictionaryWithObjects:objectsCompanyMdm forKeys:keysCompanyMdm count:countCompanyMdm];
  754. [self setMdm:companyMdm threemaMdm:nil];
  755. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:YES];
  756. XCTAssertFalse([mdmSetup isSafeBackupDisable]);
  757. XCTAssertFalse([mdmSetup isSafeBackupForce]);
  758. XCTAssertFalse([mdmSetup isSafeBackupServerPreset]);
  759. XCTAssertFalse([mdmSetup isSafeBackupPasswordPreset]);
  760. XCTAssertFalse([mdmSetup isSafeRestoreDisable]);
  761. XCTAssertFalse([mdmSetup isSafeRestoreForce]);
  762. XCTAssertFalse([mdmSetup isSafeRestoreServerPreset]);
  763. XCTAssertFalse([mdmSetup isSafeRestorePasswordPreset]);
  764. }
  765. - (void)testRestoreEnableWithServerAndPassword {
  766. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  767. // Company-MDM
  768. id keysCompanyMdm[] = { MDM_KEY_SAFE_SERVER_URL, MDM_KEY_SAFE_PASSWORD, MDM_KEY_SAFE_RESTORE_ENABLE };
  769. id objectsCompanyMdm[] = { @"https://example.com", @"password", @"1" };
  770. NSUInteger countCompanyMdm = sizeof(objectsCompanyMdm) / sizeof(id);
  771. NSDictionary *companyMdm = [NSDictionary dictionaryWithObjects:objectsCompanyMdm forKeys:keysCompanyMdm count:countCompanyMdm];
  772. [self setMdm:companyMdm threemaMdm:nil];
  773. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:YES];
  774. XCTAssertFalse([mdmSetup isSafeBackupDisable]);
  775. XCTAssertFalse([mdmSetup isSafeBackupForce]);
  776. XCTAssertTrue([mdmSetup isSafeBackupServerPreset]);
  777. XCTAssertFalse([mdmSetup isSafeBackupPasswordPreset]);
  778. XCTAssertFalse([mdmSetup isSafeRestoreDisable]);
  779. XCTAssertFalse([mdmSetup isSafeRestoreForce]);
  780. XCTAssertTrue([mdmSetup isSafeRestoreServerPreset]);
  781. XCTAssertFalse([mdmSetup isSafeRestorePasswordPreset]);
  782. }
  783. - (void)testRestoreForceWithServerAndPassword {
  784. [given([_mockLicenseStore getRequiresLicenseKey]) willReturnBool:YES];
  785. // Company-MDM
  786. id keysCompanyMdm[] = { MDM_KEY_SAFE_SERVER_URL, MDM_KEY_SAFE_PASSWORD, MDM_KEY_SAFE_RESTORE_ENABLE, MDM_KEY_SAFE_RESTORE_ID };
  787. id objectsCompanyMdm[] = { @"https://example.com", @"password", @"1", @"EINSZWEI" };
  788. NSUInteger countCompanyMdm = sizeof(objectsCompanyMdm) / sizeof(id);
  789. NSDictionary *companyMdm = [NSDictionary dictionaryWithObjects:objectsCompanyMdm forKeys:keysCompanyMdm count:countCompanyMdm];
  790. [self setMdm:companyMdm threemaMdm:nil];
  791. MDMSetup *mdmSetup = [[MDMSetup alloc] initWithSetup:YES];
  792. XCTAssertFalse([mdmSetup isSafeBackupDisable]);
  793. XCTAssertFalse([mdmSetup isSafeBackupForce]);
  794. XCTAssertTrue([mdmSetup isSafeBackupServerPreset]);
  795. XCTAssertFalse([mdmSetup isSafeBackupPasswordPreset]);
  796. XCTAssertFalse([mdmSetup isSafeRestoreDisable]);
  797. XCTAssertTrue([mdmSetup isSafeRestoreForce]);
  798. XCTAssertTrue([mdmSetup isSafeRestoreServerPreset]);
  799. XCTAssertTrue([mdmSetup isSafeRestorePasswordPreset]);
  800. }
  801. - (NSDictionary*)getAllMdmParameters:(BOOL)isThreemaMdm {
  802. id keysMdm[] = { MDM_KEY_LICENSE_USERNAME, MDM_KEY_LICENSE_PASSWORD, MDM_KEY_NICKNAME, MDM_KEY_FIRST_NAME, MDM_KEY_LAST_NAME, MDM_KEY_CSI, MDM_KEY_CATEGORY, MDM_KEY_LINKED_EMAIL, MDM_KEY_LINKED_PHONE, MDM_KEY_CONTACT_SYNC, MDM_KEY_READONLY_PROFILE, MDM_KEY_BLOCK_UNKNOWN, MDM_KEY_HIDE_INACTIVE_IDS, MDM_KEY_DISABLE_SAVE_TO_GALLERY, MDM_KEY_DISABLE_ADD_CONTACT, MDM_KEY_DISABLE_EXPORT, MDM_KEY_DISABLE_BACKUPS, MDM_KEY_DISABLE_ID_EXPORT, MDM_KEY_DISABLE_SYSTEM_BACKUPS, MDM_KEY_DISABLE_MESSAGE_PREVIEW, MDM_KEY_DISABLE_SEND_PROFILE_PICTURE, MDM_KEY_DISABLE_CALLS, MDM_KEY_DISABLE_VIDEO_CALLS, MDM_KEY_SKIP_WIZARD, MDM_KEY_DISABLE_CREATE_GROUP, MDM_KEY_DISABLE_WEB, MDM_KEY_SAFE_ENABLE, MDM_KEY_SAFE_SERVER_URL, MDM_KEY_SAFE_SERVER_USERNAME, MDM_KEY_SAFE_SERVER_PASSWORD, MDM_KEY_SAFE_RESTORE_ENABLE, MDM_KEY_SAFE_RESTORE_ID, MDM_KEY_SAFE_PASSWORD_PATTERN, MDM_KEY_SAFE_PASSWORD_MESSAGE, MDM_KEY_WEB_HOSTS, MDM_KEY_DISABLE_SHARE_MEDIA};
  803. id objectsMdm[] = { @"tester", @"test1234", @"Eieri", @"Heiri", @"Heirassa", @"customer-id", @"category", @"linked@email.com", @"111", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", _yes, @"http://test.com", @"server-user", @"server-password", @"0", @"ECHOECHO", @"^[0-9]{1,15}$", @"Wrong-password-pattern", @"threema.ch", @"1"};
  804. NSUInteger countMdm = sizeof(objectsMdm) / sizeof(id);
  805. NSMutableDictionary *mdm = [NSMutableDictionary dictionaryWithObjects:objectsMdm forKeys:keysMdm count:countMdm];
  806. // add parameter if not Threema-MDM
  807. if (!isThreemaMdm) {
  808. NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:@"87654321", MDM_KEY_SAFE_PASSWORD, nil];
  809. [mdm addEntriesFromDictionary:dic];
  810. }
  811. return mdm;
  812. }
  813. /*
  814. - (void)testPerformanceExample {
  815. // This is an example of a performance test case.
  816. [self measureBlock:^{
  817. // Put the code you want to measure the time of here.
  818. }];
  819. }
  820. */
  821. @end