Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Fix ES Mock Client Subscription issues #801

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
5 changes: 5 additions & 0 deletions Source/santad/EventProviders/EndpointSecurityTestUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ API_UNAVAILABLE(ios, tvos, watchos)
es_new_client_result_t es_new_client(es_client_t *_Nullable *_Nonnull client,
es_handler_block_t _Nonnull handler);

API_AVAILABLE(macos(12.0))
API_UNAVAILABLE(ios, tvos, watchos)
es_return_t es_muted_paths_events(es_client_t * _Nonnull client,
es_muted_paths_t * _Nonnull * _Nullable muted_paths);

API_AVAILABLE(macos(10.15))
API_UNAVAILABLE(ios, tvos, watchos)
es_respond_result_t es_respond_auth_result(es_client_t *_Nonnull client,
Expand Down
41 changes: 40 additions & 1 deletion Source/santad/EventProviders/EndpointSecurityTestUtil.mm
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,24 @@ - (void)newClient:(es_client_t *_Nullable *_Nonnull)client
[self.clients addObject:mockClient];
}

- (BOOL)removeClient:(es_client_t *_Nonnull) client {
MockESClient *clientToRemove = nil;
for (MockESClient *c in self.clients) {
if (client == (__bridge es_client_t *)c) {
clientToRemove = c;
break;
}
}

if (!clientToRemove) {
NSLog(@"Attempted to remove unknown mock es client.");
return NO;
}

[self.clients removeObject: clientToRemove];
return YES;
}

- (void)triggerHandler:(es_message_t *_Nonnull)msg {
for (MockESClient *client in self.clients) {
if (client.subscriptions[msg->event_type]) {
Expand Down Expand Up @@ -281,9 +299,30 @@ es_new_client_result_t es_new_client(es_client_t *_Nullable *_Nonnull client,
return ES_NEW_CLIENT_RESULT_SUCCESS;
};

API_AVAILABLE(macos(12.0))
API_UNAVAILABLE(ios, tvos, watchos)
es_return_t es_muted_paths_events(es_client_t * _Nonnull client,
es_muted_paths_t * _Nonnull * _Nullable muted_paths) {

es_muted_paths_t *tmp = (es_muted_paths_t *)malloc(sizeof(es_muted_paths_t));

tmp->count = 0;
*muted_paths = (es_muted_paths_t * _Nullable)tmp;

return ES_RETURN_SUCCESS;
};

API_AVAILABLE(macos(12.0))
API_UNAVAILABLE(ios, tvos, watchos)
void es_release_muted_paths(es_muted_paths_t * _Nonnull muted_paths) {
free(muted_paths);
}

API_AVAILABLE(macos(10.15))
API_UNAVAILABLE(ios, tvos, watchos) es_return_t es_delete_client(es_client_t *_Nullable client) {
[[MockEndpointSecurity mockEndpointSecurity] reset];
if (![[MockEndpointSecurity mockEndpointSecurity] removeClient: client]) {
return ES_RETURN_ERROR;
}
return ES_RETURN_SUCCESS;
};

Expand Down