|
25 | 25 | #import "FirebaseDatabase/Sources/Snapshot/FSnapshotUtilities.h" |
26 | 26 | #import "FirebaseDatabase/Tests/Helpers/FTestHelpers.h" |
27 | 27 |
|
28 | | -@interface FLevelDBStorageEngineTests : XCTestCase |
| 28 | +@interface FLevelDBStorageEngine (Tests) |
| 29 | ++ (void)ensureDir:(NSString *)path markAsDoNotBackup:(BOOL)markAsDoNotBackup; |
| 30 | +@end |
29 | 31 |
|
| 32 | +@interface FLevelDBStorageEngineTests : XCTestCase |
30 | 33 | @end |
31 | 34 |
|
32 | 35 | @implementation FLevelDBStorageEngineTests |
@@ -685,4 +688,36 @@ - (void)testRemoveTrackedQueryRemovesTrackedQueryKeys { |
685 | 688 | ([NSSet setWithArray:@[ @"b", @"c" ]])); |
686 | 689 | } |
687 | 690 |
|
| 691 | +- (void)testEnsureDirSetsCorrectFileProtection { |
| 692 | + NSString *testDirName = |
| 693 | + [NSString stringWithFormat:@"fdb_persistence_test_%lu", (unsigned long)arc4random()]; |
| 694 | + NSString *testPath = [NSTemporaryDirectory() stringByAppendingPathComponent:testDirName]; |
| 695 | + |
| 696 | + // Ensure the directory doesn't exist before the test |
| 697 | + [[NSFileManager defaultManager] removeItemAtPath:testPath error:nil]; |
| 698 | + |
| 699 | + // Call the method to create the directory |
| 700 | + [FLevelDBStorageEngine ensureDir:testPath markAsDoNotBackup:NO]; |
| 701 | + |
| 702 | + // Get the attributes of the created directory |
| 703 | + NSError *error = nil; |
| 704 | + NSDictionary<NSFileAttributeKey, id> *attributes = |
| 705 | + [[NSFileManager defaultManager] attributesOfItemAtPath:testPath error:&error]; |
| 706 | + |
| 707 | + // Assert that the file protection attribute is correct |
| 708 | + XCTAssertNil(error, @"Failed to get attributes of directory: %@", error); |
| 709 | + |
| 710 | +#if TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR |
| 711 | + // On a physical iOS device, file protection should be set. |
| 712 | + XCTAssertEqualObjects(attributes[NSFileProtectionKey], |
| 713 | + NSFileProtectionCompleteUntilFirstUserAuthentication); |
| 714 | +#else |
| 715 | + // In the simulator or on other platforms, file protection is not supported, so the key |
| 716 | + // should be nil. |
| 717 | + XCTAssertNil(attributes[NSFileProtectionKey]); |
| 718 | +#endif |
| 719 | + |
| 720 | + // Clean up |
| 721 | + [[NSFileManager defaultManager] removeItemAtPath:testPath error:nil]; |
| 722 | +} |
688 | 723 | @end |
0 commit comments