Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support filesystem monitoring config embedded in main Santa config #1054

Merged
merged 2 commits into from
Mar 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add some tests
  • Loading branch information
mlw committed Mar 20, 2023
commit 5bf74c18d0d95ed24565cafefc5ff045f799c9f3
33 changes: 29 additions & 4 deletions Source/santad/DataLayer/WatchItemsTest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ extern bool ParseConfigSingleWatchItem(NSString *name, NSDictionary *watch_item,
NSDictionary *watch_item, NSError **err);
class WatchItemsPeer : public WatchItems {
public:
using WatchItems::ReloadConfig;
using WatchItems::WatchItems;

using WatchItems::ReloadConfig;
using WatchItems::SetConfig;
using WatchItems::SetConfigPath;

using WatchItems::config_path_;
using WatchItems::embedded_config_;
};

} // namespace santa::santad::data_layer
Expand Down Expand Up @@ -191,7 +197,7 @@ - (void)testReloadScenarios {
// Changes in config dictionary will update policy info even if the
// filesystem didn't change.
{
WatchItemsPeer watchItems((NSString*)nil, NULL, NULL);
WatchItemsPeer watchItems((NSString *)nil, NULL, NULL);
[self pushd:@"a"];
watchItems.ReloadConfig(configAllFilesOriginal);

Expand All @@ -212,7 +218,7 @@ - (void)testReloadScenarios {

// Changes to fileystem structure are reflected when a config is reloaded
{
WatchItemsPeer watchItems((NSString*)nil, NULL, NULL);
WatchItemsPeer watchItems((NSString *)nil, NULL, NULL);
[self pushd:@"a"];
watchItems.ReloadConfig(configAllFilesOriginal);
[self popd];
Expand Down Expand Up @@ -313,7 +319,7 @@ - (void)testPolicyLookup {
}
});

WatchItemsPeer watchItems((NSString*)nil, NULL, NULL);
WatchItemsPeer watchItems((NSString *)nil, NULL, NULL);
WatchItems::VersionAndPolicies policies;

// Resultant vector is same size as input vector
Expand Down Expand Up @@ -842,4 +848,23 @@ - (void)testState {
XCTAssertGreaterThanOrEqual(state.last_config_load_epoch, startTime);
}

- (void)testSetConfigAndSetConfigPath {
// Test internal state when switching back and forth between path-based and
// dictionary-based config options.
WatchItemsPeer watchItems(@{}, NULL, NULL);

XCTAssertNil(watchItems.config_path_);
XCTAssertNotNil(watchItems.embedded_config_);

watchItems.SetConfigPath(@"/path/to/a/nonexistent/file/so/nothing/is/opened");

XCTAssertNotNil(watchItems.config_path_);
XCTAssertNil(watchItems.embedded_config_);

watchItems.SetConfig(@{});

XCTAssertNil(watchItems.config_path_);
XCTAssertNotNil(watchItems.embedded_config_);
}

@end