-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP Clean syncs now leave non-transitive rules by default * WIP Get existing tests compiling and passing * Remove clean all sync server key. Basic tests. * Add SNTConfiguratorTest, test deprecated key migration * Revert changes to santactl status output * Add new preflight response sync type key, lots of tests * Rework configurator flow a bit so calls cannot be made out of order * Comment clean sync states. Test all permutations. * Update docs for new sync keys * Doc updates as requested in PR
- Loading branch information
Showing
39 changed files
with
629 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/// Copyright 2024 Google LLC | ||
/// | ||
/// Licensed under the Apache License, Version 2.0 (the "License"); | ||
/// you may not use this file except in compliance with the License. | ||
/// You may obtain a copy of the License at | ||
/// | ||
/// https://www.apache.org/licenses/LICENSE-2.0 | ||
/// | ||
/// Unless required by applicable law or agreed to in writing, software | ||
/// distributed under the License is distributed on an "AS IS" BASIS, | ||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
/// See the License for the specific language governing permissions and | ||
/// limitations under the License. | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <XCTest/XCTest.h> | ||
|
||
#import "Source/common/SNTCommonEnums.h" | ||
#import "Source/common/SNTConfigurator.h" | ||
|
||
@interface SNTConfigurator (Testing) | ||
- (instancetype)initWithSyncStateFile:(NSString *)syncStateFilePath | ||
syncStateAccessAuthorizer:(BOOL (^)(void))syncStateAccessAuthorizer; | ||
|
||
@property NSDictionary *syncState; | ||
@end | ||
|
||
@interface SNTConfiguratorTest : XCTestCase | ||
@property NSFileManager *fileMgr; | ||
@property NSString *testDir; | ||
@end | ||
|
||
@implementation SNTConfiguratorTest | ||
|
||
- (void)setUp { | ||
self.fileMgr = [NSFileManager defaultManager]; | ||
self.testDir = | ||
[NSString stringWithFormat:@"%@santa-configurator-%d", NSTemporaryDirectory(), getpid()]; | ||
|
||
XCTAssertTrue([self.fileMgr createDirectoryAtPath:self.testDir | ||
withIntermediateDirectories:YES | ||
attributes:nil | ||
error:nil]); | ||
} | ||
|
||
- (void)tearDown { | ||
XCTAssertTrue([self.fileMgr removeItemAtPath:self.testDir error:nil]); | ||
} | ||
|
||
- (void)runMigrationTestsWithSyncState:(NSDictionary *)syncStatePlist | ||
verifier:(void (^)(SNTConfigurator *))verifierBlock { | ||
NSString *syncStatePlistPath = | ||
[NSString stringWithFormat:@"%@/test-sync-state.plist", self.testDir]; | ||
|
||
XCTAssertTrue([syncStatePlist writeToFile:syncStatePlistPath atomically:YES]); | ||
|
||
SNTConfigurator *cfg = [[SNTConfigurator alloc] initWithSyncStateFile:syncStatePlistPath | ||
syncStateAccessAuthorizer:^{ | ||
// Allow all access to the test plist | ||
return YES; | ||
}]; | ||
|
||
NSLog(@"sync state: %@", cfg.syncState); | ||
|
||
verifierBlock(cfg); | ||
|
||
XCTAssertTrue([self.fileMgr removeItemAtPath:syncStatePlistPath error:nil]); | ||
} | ||
|
||
- (void)testInitMigratesSyncStateKeys { | ||
// SyncCleanRequired = YES | ||
[self runMigrationTestsWithSyncState:@{@"SyncCleanRequired" : [NSNumber numberWithBool:YES]} | ||
verifier:^(SNTConfigurator *cfg) { | ||
XCTAssertEqual(cfg.syncState.count, 1); | ||
XCTAssertNil(cfg.syncState[@"SyncCleanRequired"]); | ||
XCTAssertNotNil(cfg.syncState[@"SyncTypeRequired"]); | ||
XCTAssertEqual([cfg.syncState[@"SyncTypeRequired"] integerValue], | ||
SNTSyncTypeClean); | ||
XCTAssertEqual(cfg.syncState.count, 1); | ||
}]; | ||
|
||
// SyncCleanRequired = NO | ||
[self runMigrationTestsWithSyncState:@{@"SyncCleanRequired" : [NSNumber numberWithBool:NO]} | ||
verifier:^(SNTConfigurator *cfg) { | ||
XCTAssertEqual(cfg.syncState.count, 1); | ||
XCTAssertNil(cfg.syncState[@"SyncCleanRequired"]); | ||
XCTAssertNotNil(cfg.syncState[@"SyncTypeRequired"]); | ||
XCTAssertEqual([cfg.syncState[@"SyncTypeRequired"] integerValue], | ||
SNTSyncTypeNormal); | ||
XCTAssertEqual(cfg.syncState.count, 1); | ||
}]; | ||
|
||
// Empty state | ||
[self runMigrationTestsWithSyncState:@{} | ||
verifier:^(SNTConfigurator *cfg) { | ||
XCTAssertEqual(cfg.syncState.count, 0); | ||
XCTAssertNil(cfg.syncState[@"SyncCleanRequired"]); | ||
XCTAssertNil(cfg.syncState[@"SyncTypeRequired"]); | ||
}]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.