Skip to content

Commit aee52c6

Browse files
Add unit test for keychain handler, network handler, mobile provision, user defaults
1 parent 464e1f9 commit aee52c6

12 files changed

Lines changed: 681 additions & 291 deletions

File tree

AppBox.xcodeproj/project.pbxproj

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
0D4C02332FC22A63EFF72F8D /* NSStringTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 30509E5843B9CCEA2AFB2874 /* NSStringTests.m */; };
11-
407C8032774422D6217359B9 /* NSExceptionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B386EED60B876CEE11BBF89B /* NSExceptionTests.m */; };
1210
4410D18E26FF76A20046E5F9 /* DBAccountManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 4410D18D26FF76A20046E5F9 /* DBAccountManager.m */; };
1311
4410D19C26FF851D0046E5F9 /* CoreDataMigration3to4.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = 4410D19B26FF851D0046E5F9 /* CoreDataMigration3to4.xcmappingmodel */; };
1412
449BD6B8282111B0008EFB2B /* AppBoxService+CoreDataProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = 449BD6B4282111B0008EFB2B /* AppBoxService+CoreDataProperties.m */; };
1513
449BD6B9282111B0008EFB2B /* AppBoxService+CoreDataClass.m in Sources */ = {isa = PBXBuildFile; fileRef = 449BD6B5282111B0008EFB2B /* AppBoxService+CoreDataClass.m */; };
1614
4D3E492303A5E78B0417E17F /* ObjectiveDropboxOfficial.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 656E98171CB7E85AA663AFE8 /* ObjectiveDropboxOfficial.xcframework */; };
1715
5D20E6B57EA90CA7D6EA21F7 /* IPAUploadInfoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E65C0AF09D32F39F4259167 /* IPAUploadInfoTests.m */; };
1816
6968AADC9DEB5554A06F19BD /* CocoaLumberjack in Frameworks */ = {isa = PBXBuildFile; productRef = 33146DD70AA7C380685E53AA /* CocoaLumberjack */; };
19-
7288A761B4712E54C04CE3CA /* NSURLTests.m in Sources */ = {isa = PBXBuildFile; fileRef = BA16F2A781DF1BAB101AACAE /* NSURLTests.m */; };
2017
771E1F8D4D831C50C1178A75 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 09E11F809EFA1C7844F25D6B /* Cocoa.framework */; };
2118
AC4CF046F7F2B76CF56BF8E4 /* ObjectiveDropboxOfficial.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 656E98171CB7E85AA663AFE8 /* ObjectiveDropboxOfficial.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2219
D9E5B24A6827FC5AD68D29D0 /* CommonTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 544B2D28AEC66102492FA05E /* CommonTests.m */; };
@@ -97,8 +94,11 @@
9794
E1D12EEC1EC31AC80065E59A /* AccountPreferencesViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E1D12EEB1EC31AC80065E59A /* AccountPreferencesViewController.xib */; };
9895
E1D12EEE1EC320760065E59A /* HelpPreferencesViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E1D12EED1EC320760065E59A /* HelpPreferencesViewController.xib */; };
9996
E1DC26001ECDBCA8001EF106 /* MBProgressHUD+ProgressHud.m in Sources */ = {isa = PBXBuildFile; fileRef = E1DC25FF1ECDBCA8001EF106 /* MBProgressHUD+ProgressHud.m */; };
100-
E6BF0C7BDA3380B61FA14F6C /* NSDateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E5177E6B8643457D0035658 /* NSDateTests.m */; };
10197
F6AEC01BE879A2BB998E829D /* ZipArchive in Frameworks */ = {isa = PBXBuildFile; productRef = EFE5EA7464F3539F2562A787 /* ZipArchive */; };
98+
AA11BB22CC33DD44EE550011 /* NetworkHandlerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AA11BB22CC33DD44EE550001 /* NetworkHandlerTests.m */; };
99+
AA11BB22CC33DD44EE550012 /* MobileProvisionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AA11BB22CC33DD44EE550002 /* MobileProvisionTests.m */; };
100+
AA11BB22CC33DD44EE550013 /* KeychainHandlerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AA11BB22CC33DD44EE550003 /* KeychainHandlerTests.m */; };
101+
AA11BB22CC33DD44EE550014 /* UserDataTests.m in Sources */ = {isa = PBXBuildFile; fileRef = AA11BB22CC33DD44EE550004 /* UserDataTests.m */; };
102102
/* End PBXBuildFile section */
103103

104104
/* Begin PBXContainerItemProxy section */
@@ -147,8 +147,7 @@
147147

148148
/* Begin PBXFileReference section */
149149
09E11F809EFA1C7844F25D6B /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk/System/Library/Frameworks/Cocoa.framework; sourceTree = DEVELOPER_DIR; };
150-
30509E5843B9CCEA2AFB2874 /* NSStringTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = NSStringTests.m; sourceTree = "<group>"; };
151-
3E65C0AF09D32F39F4259167 /* IPAUploadInfoTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = IPAUploadInfoTests.m; sourceTree = "<group>"; };
150+
3E65C0AF09D32F39F4259167 /* IPAUploadInfoTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = IPAUploadInfoTests.m; path = Model/IPAUploadInfoTests.m; sourceTree = "<group>"; };
152151
4410D18C26FF76A20046E5F9 /* DBAccountManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DBAccountManager.h; sourceTree = "<group>"; };
153152
4410D18D26FF76A20046E5F9 /* DBAccountManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DBAccountManager.m; sourceTree = "<group>"; };
154153
4410D19B26FF851D0046E5F9 /* CoreDataMigration3to4.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; path = CoreDataMigration3to4.xcmappingmodel; sourceTree = "<group>"; };
@@ -157,11 +156,8 @@
157156
449BD6B6282111B0008EFB2B /* AppBoxService+CoreDataProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AppBoxService+CoreDataProperties.h"; sourceTree = "<group>"; };
158157
449BD6B7282111B0008EFB2B /* AppBoxService+CoreDataClass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AppBoxService+CoreDataClass.h"; sourceTree = "<group>"; };
159158
44DCC66B25EEA1910074AB1E /* AppBox4.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = AppBox4.xcdatamodel; sourceTree = "<group>"; };
160-
544B2D28AEC66102492FA05E /* CommonTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = CommonTests.m; sourceTree = "<group>"; };
159+
544B2D28AEC66102492FA05E /* CommonTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = CommonTests.m; path = Common/CommonTests.m; sourceTree = "<group>"; };
161160
656E98171CB7E85AA663AFE8 /* ObjectiveDropboxOfficial.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = ObjectiveDropboxOfficial.xcframework; path = Frameworks/ObjectiveDropboxOfficial.xcframework; sourceTree = "<group>"; };
162-
7E5177E6B8643457D0035658 /* NSDateTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = NSDateTests.m; sourceTree = "<group>"; };
163-
B386EED60B876CEE11BBF89B /* NSExceptionTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = NSExceptionTests.m; sourceTree = "<group>"; };
164-
BA16F2A781DF1BAB101AACAE /* NSURLTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = NSURLTests.m; sourceTree = "<group>"; };
165161
DB0435832E696255005F0173 /* appboxcli */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = appboxcli; sourceTree = BUILT_PRODUCTS_DIR; };
166162
DB04358F2E6962EA005F0173 /* CLISupportHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CLISupportHelper.h; sourceTree = "<group>"; };
167163
DB0435902E6962EA005F0173 /* CLISupportHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CLISupportHelper.m; sourceTree = "<group>"; };
@@ -300,6 +296,10 @@
300296
E1DC25FE1ECDBCA8001EF106 /* MBProgressHUD+ProgressHud.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MBProgressHUD+ProgressHud.h"; sourceTree = "<group>"; };
301297
E1DC25FF1ECDBCA8001EF106 /* MBProgressHUD+ProgressHud.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MBProgressHUD+ProgressHud.m"; sourceTree = "<group>"; };
302298
E1FECA821E83EE5000C4E9AE /* HTTPStatusCode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTTPStatusCode.h; sourceTree = "<group>"; };
299+
AA11BB22CC33DD44EE550001 /* NetworkHandlerTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = NetworkHandlerTests.m; path = Common/NetworkHandler/NetworkHandlerTests.m; sourceTree = "<group>"; };
300+
AA11BB22CC33DD44EE550002 /* MobileProvisionTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = MobileProvisionTests.m; path = Common/MobileProvision/MobileProvisionTests.m; sourceTree = "<group>"; };
301+
AA11BB22CC33DD44EE550003 /* KeychainHandlerTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = KeychainHandlerTests.m; path = Common/KeychainHandler/KeychainHandlerTests.m; sourceTree = "<group>"; };
302+
AA11BB22CC33DD44EE550004 /* UserDataTests.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = UserDataTests.m; path = Common/UserManager/UserDataTests.m; sourceTree = "<group>"; };
303303
/* End PBXFileReference section */
304304

305305
/* Begin PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet section */
@@ -369,16 +369,64 @@
369369
name = "OS X";
370370
sourceTree = "<group>";
371371
};
372+
AA11BB22CC33DD44EE550022 /* NetworkHandler */ = {
373+
isa = PBXGroup;
374+
children = (
375+
AA11BB22CC33DD44EE550001 /* NetworkHandlerTests.m */,
376+
);
377+
name = NetworkHandler;
378+
sourceTree = "<group>";
379+
};
380+
AA11BB22CC33DD44EE550023 /* MobileProvision */ = {
381+
isa = PBXGroup;
382+
children = (
383+
AA11BB22CC33DD44EE550002 /* MobileProvisionTests.m */,
384+
);
385+
name = MobileProvision;
386+
sourceTree = "<group>";
387+
};
388+
AA11BB22CC33DD44EE550024 /* KeychainHandler */ = {
389+
isa = PBXGroup;
390+
children = (
391+
AA11BB22CC33DD44EE550003 /* KeychainHandlerTests.m */,
392+
);
393+
name = KeychainHandler;
394+
sourceTree = "<group>";
395+
};
396+
AA11BB22CC33DD44EE550025 /* UserManager */ = {
397+
isa = PBXGroup;
398+
children = (
399+
AA11BB22CC33DD44EE550004 /* UserDataTests.m */,
400+
);
401+
name = UserManager;
402+
sourceTree = "<group>";
403+
};
404+
AA11BB22CC33DD44EE550021 /* Common */ = {
405+
isa = PBXGroup;
406+
children = (
407+
544B2D28AEC66102492FA05E /* CommonTests.m */,
408+
AA11BB22CC33DD44EE550022 /* NetworkHandler */,
409+
AA11BB22CC33DD44EE550023 /* MobileProvision */,
410+
AA11BB22CC33DD44EE550024 /* KeychainHandler */,
411+
AA11BB22CC33DD44EE550025 /* UserManager */,
412+
);
413+
name = Common;
414+
sourceTree = "<group>";
415+
};
416+
AA11BB22CC33DD44EE550026 /* Model */ = {
417+
isa = PBXGroup;
418+
children = (
419+
3E65C0AF09D32F39F4259167 /* IPAUploadInfoTests.m */,
420+
);
421+
name = Model;
422+
sourceTree = "<group>";
423+
};
372424
AECBA8D5D0C166DA17FF6ED0 /* AppBoxTests */ = {
373425
isa = PBXGroup;
374426
children = (
375427
DB5BA12A2FC9C94E00A150BA /* AppBoxTests.xctestplan */,
376-
3E65C0AF09D32F39F4259167 /* IPAUploadInfoTests.m */,
377-
30509E5843B9CCEA2AFB2874 /* NSStringTests.m */,
378-
BA16F2A781DF1BAB101AACAE /* NSURLTests.m */,
379-
7E5177E6B8643457D0035658 /* NSDateTests.m */,
380-
B386EED60B876CEE11BBF89B /* NSExceptionTests.m */,
381-
544B2D28AEC66102492FA05E /* CommonTests.m */,
428+
AA11BB22CC33DD44EE550021 /* Common */,
429+
AA11BB22CC33DD44EE550026 /* Model */,
382430
);
383431
path = AppBoxTests;
384432
sourceTree = "<group>";
@@ -1090,11 +1138,11 @@
10901138
buildActionMask = 2147483647;
10911139
files = (
10921140
5D20E6B57EA90CA7D6EA21F7 /* IPAUploadInfoTests.m in Sources */,
1093-
0D4C02332FC22A63EFF72F8D /* NSStringTests.m in Sources */,
1094-
7288A761B4712E54C04CE3CA /* NSURLTests.m in Sources */,
1095-
E6BF0C7BDA3380B61FA14F6C /* NSDateTests.m in Sources */,
1096-
407C8032774422D6217359B9 /* NSExceptionTests.m in Sources */,
10971141
D9E5B24A6827FC5AD68D29D0 /* CommonTests.m in Sources */,
1142+
AA11BB22CC33DD44EE550011 /* NetworkHandlerTests.m in Sources */,
1143+
AA11BB22CC33DD44EE550012 /* MobileProvisionTests.m in Sources */,
1144+
AA11BB22CC33DD44EE550013 /* KeychainHandlerTests.m in Sources */,
1145+
AA11BB22CC33DD44EE550014 /* UserDataTests.m in Sources */,
10981146
);
10991147
runOnlyForDeploymentPostprocessing = 0;
11001148
};

AppBoxTests/AppBoxTests.xctestplan

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
}
1010
],
1111
"defaultOptions" : {
12-
"performanceAntipatternCheckerEnabled" : true
12+
"performanceAntipatternCheckerEnabled" : true,
13+
"uiTestingScreenshotsLifetime" : "keepNever"
1314
},
1415
"testTargets" : [
1516
{
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//
2+
// KeychainHandlerTests.m
3+
// AppBoxTests
4+
//
5+
// Created by AppBox on 29/05/26.
6+
// Copyright © 2026 Developer Insider. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "KeychainHandler.h"
11+
12+
@interface KeychainHandlerTests : XCTestCase
13+
@end
14+
15+
@implementation KeychainHandlerTests
16+
17+
#pragma mark - errorMessageForStatus Tests
18+
19+
- (void)testErrorMessageForStatus_Success_ReturnsNoError {
20+
NSString *message = [KeychainHandler errorMessageForStatus:errSecSuccess];
21+
XCTAssertNotNil(message);
22+
// errSecSuccess (0) should not produce an error-style message
23+
XCTAssertGreaterThan(message.length, 0);
24+
}
25+
26+
- (void)testErrorMessageForStatus_ItemNotFound_ReturnsMessage {
27+
NSString *message = [KeychainHandler errorMessageForStatus:errSecItemNotFound];
28+
XCTAssertNotNil(message);
29+
XCTAssertGreaterThan(message.length, 0);
30+
}
31+
32+
- (void)testErrorMessageForStatus_AuthFailed_ReturnsMessage {
33+
NSString *message = [KeychainHandler errorMessageForStatus:errSecAuthFailed];
34+
XCTAssertNotNil(message);
35+
XCTAssertGreaterThan(message.length, 0);
36+
}
37+
38+
- (void)testErrorMessageForStatus_DuplicateItem_ReturnsMessage {
39+
NSString *message = [KeychainHandler errorMessageForStatus:errSecDuplicateItem];
40+
XCTAssertNotNil(message);
41+
XCTAssertGreaterThan(message.length, 0);
42+
}
43+
44+
- (void)testErrorMessageForStatus_DifferentStatusesDifferentMessages {
45+
NSString *notFound = [KeychainHandler errorMessageForStatus:errSecItemNotFound];
46+
NSString *duplicate = [KeychainHandler errorMessageForStatus:errSecDuplicateItem];
47+
XCTAssertNotEqualObjects(notFound, duplicate);
48+
}
49+
50+
#pragma mark - Constants Tests
51+
52+
- (void)testKeychainAccountKey_HasExpectedValue {
53+
XCTAssertEqualObjects(kSAMKeychainAccountKey, @"acct");
54+
}
55+
56+
- (void)testKeychainLabelKey_HasExpectedValue {
57+
XCTAssertEqualObjects(kSAMKeychainLabelKey, @"labl");
58+
}
59+
60+
#pragma mark - accountsForService Tests
61+
62+
- (void)testAccountsForService_WithNonExistentService_ReturnsEmptyArray {
63+
NSArray *accounts = [KeychainHandler accountsForService:@"com.appbox.test.nonexistent.service.12345"];
64+
XCTAssertNotNil(accounts);
65+
XCTAssertEqual(accounts.count, 0);
66+
}
67+
68+
@end

0 commit comments

Comments
 (0)