Commit Graph

9633 Commits

Author SHA1 Message Date
Mike Salvatore a6c24af622 Common: Prevent topic collision between types and tags
If an event tag happened to be the same as an event type, subscribers
could receive event types that they were not prepared to handle,
resulting in difficult-to-diagnose bugs. Prevent tags and types from
being sent to the wrong subscribers by appending unique strings to the
topics.
2022-08-10 11:32:09 -04:00
Mike Salvatore 3384c049a4 UT: Use new Publisher for each test instead of default `pub`
Using the default publisher provided by pypubsub causes state to be
carried over between tests. Unit tests should not depend on eachother or
the order in which they're run.
2022-08-10 11:10:22 -04:00
Mike Salvatore 68dafbfb9d UT: Add event_queue() fixture 2022-08-10 11:09:51 -04:00
Mike Salvatore 2bdc16c286 UT: Refactor test_pypubsub_event_queue.py 2022-08-10 11:07:36 -04:00
Mike Salvatore d6bb56536d UT: Test with instances of AbstractEvent, not classes 2022-08-10 09:37:10 -04:00
Mike Salvatore 4da0cefa7d Common: Publish message to event's class name 2022-08-10 09:34:09 -04:00
Mike Salvatore a461226fec Common: Fix type hint for PyPubSubEventQueue.subscribe_type() 2022-08-10 09:21:54 -04:00
Mike Salvatore c0a9a8cf4d Common: Rename _publish_to_tags_topic{,s}() 2022-08-10 09:18:25 -04:00
Mike Salvatore c26c7403a6 Common: Make INTERNAL_ALL_EVENT_TYPES_TOPIC private to the module 2022-08-10 09:17:14 -04:00
Mike Salvatore 43e45e14ad Common: Remove subscribe_all_event_types()
https://github.com/guardicore/monkey/pull/2182#discussion_r942427831
2022-08-10 09:17:14 -04:00
Mike Salvatore 87cbdd9fb8 Common: Rename subscribe_all() -> subscribe_all_events() 2022-08-10 09:17:13 -04:00
Mike Salvatore 8553cd834c Common: Improve readability of PyPubSubEventQueue.publish() 2022-08-10 08:59:49 -04:00
Mike Salvatore 1d7b498290 Common: Improve readability in PyPubSubEventQueue 2022-08-10 08:59:49 -04:00
Mike Salvatore 7bbecc4d3f Common: Only send event to `subscribe_all()` subscribers once 2022-08-10 08:59:49 -04:00
Shreya Malviya 49a28b9161 UT: Add test for subscribing to all event types in PyPubSubEventQueue 2022-08-10 17:24:12 +05:30
Mike Salvatore d09f743100 Island: Register pypubsub Publisher in the DIContainer 2022-08-10 07:31:43 -04:00
Mike Salvatore 416cb30577 Common: Add type hint ty PyPubSubEventQueue constructor 2022-08-10 07:29:13 -04:00
Shreya Malviya 6ecb2f4d49 UT: Simplify logic in test_pypubsub_event_queue.test_subscribe_types() 2022-08-10 15:45:39 +05:30
Shreya Malviya e905f6eddf UT: Define functions instead of lambda expressions in PyPubSubEventQueue tests since flake8 complains 2022-08-10 15:41:03 +05:30
Shreya Malviya edad0d8cf2 UT: Simplify test logic with fixtures in PyPubSubEventQueue 2022-08-10 15:39:14 +05:30
Shreya Malviya 3aff182d47 UT: Simplify PyPubSubEventQueue's tests 2022-08-10 14:53:46 +05:30
Shreya Malviya 2fd66bc9e2 Common: Add comment about subscribing to all topics in PyPubSubEventQueue 2022-08-10 14:49:31 +05:30
Shreya Malviya f26beb6464 Common: Pass event_data to subscribers when publishing in PyPubSubEventQueue 2022-08-10 14:02:53 +05:30
Shreya Malviya 32efa0f0f2 Common: Don't pass 'data' argument when publishing in PyPubSubEventQueue 2022-08-10 13:27:55 +05:30
Shreya Malviya d154a7989c Common: Don't pass 'data' argument to IEventQueue's publish() 2022-08-10 13:26:01 +05:30
Shreya Malviya 3938e2f377 Project: Add subscribe_all_event_types to Vulture allowlist 2022-08-09 19:00:05 +05:30
Shreya Malviya 8da3abbb5b Common: Add internal all event types topic to PyPubSubEventQueue 2022-08-09 18:54:17 +05:30
Shreya Malviya 7a77fd82df Project: Add event queue's entries to Vulture allowlist 2022-08-09 17:12:48 +05:30
Shreya Malviya 585b1ca408 Common: Modify IEventQueue to not have any static methods 2022-08-09 15:21:59 +05:30
Shreya Malviya 390757f9cb UT: Modify PyPubSubEventQueuetests as per latest changes 2022-08-09 15:21:54 +05:30
Shreya Malviya 2d248151b3 Island: Register IEventQueue instance in DI container 2022-08-09 14:32:33 +05:30
Shreya Malviya d190f220f7 Common: Modify PyPubSubEventQueue to pass publisher in constructor 2022-08-09 14:31:44 +05:30
Shreya Malviya 00b62dc1a9 UT: Modify PyPubSubEventQueue's tests based on changes 2022-08-09 11:56:15 +05:30
Shreya Malviya 3cef54c09c Common: Change IEventQueue and PyPubSubEventQueue's subscribe_types() -> subscribe_type() 2022-08-09 11:53:03 +05:30
Shreya Malviya ae666d3dd3 Common: Change IEventQueue and PyPubSubEventQueue's subscribe_tags() -> subscribe_tag() 2022-08-09 11:50:31 +05:30
Shreya Malviya e92d67bfe8 Common: Fix type hints in IEventQueue and PyPubSubEventQueue 2022-08-09 11:46:19 +05:30
Shreya Malviya 9210023876 UT: Replace EventQueue with PyPubSubEventQueue 2022-08-09 11:43:37 +05:30
Shreya Malviya d346e63a26 Common: Rename EventQueue -> PyPubSubEventQueue 2022-08-09 11:42:57 +05:30
Shreya Malviya ae2ba0e068 UT: Remove event queue's unsubscribing tests 2022-08-09 11:39:43 +05:30
Shreya Malviya f3ef99db64 Common: Remove unsubscribing methods from IEventQueue and EventQueue 2022-08-09 11:37:21 +05:30
Shreya Malviya 77ea3e554d UT: Replace PypubsubEventQueue -> EventQueue and test_pypubsub_event_queue.py -> test_event_queue.py 2022-08-09 00:06:24 +05:30
Shreya Malviya 23d3f179a2 Common: Rename PypubsubEventQueue -> EventQueue and pypubsub_event_queue.py -> event_queue.py 2022-08-09 00:05:07 +05:30
Shreya Malviya 1a2a4d165a Common: Add tests for PypubsubEventQueue
All the unsubscribing tests fails for some reason right now. The
subscriber is unsubscribed from the specified topics but the subscriber
is still called when an event with that topic is published.
2022-08-08 23:57:15 +05:30
Shreya Malviya b1017e2222 Common: Fix import in common/events/__init__.py 2022-08-08 23:54:29 +05:30
Shreya Malviya 9c5bbfe35c Common: Fix some logic in PypubsubEventQueue 2022-08-08 23:54:01 +05:30
Shreya Malviya b78282ef20 Common: Implement unsubscribing functions in PypubsubEventQueue 2022-08-08 13:42:55 +05:30
Shreya Malviya 0578a6fcc8 Common: Add unsubscribing functions to IEventQueue 2022-08-08 13:38:27 +05:30
Shreya Malviya 84c800b815 Common: Remove MRO logic from PypubsubEventQueue
This isn't needed. The Agent's responsibility is to just declare what it
did in the form of events.

For example, although CredentialsStolenEvent is a type of SecurityEvent
technically, the Agent doesn't care about this. The Island does, which
is why this should be handled on the pub/sub implementation on the
Island side. The Agent merely conveys the information that it stole
credentials. Whatever is to be done or however that information is to be
handled after that is the Island's responsibility.

I don't see a use case in the Agent where a concrete event is derived
from another concrete event. So, the MRO logic is removed in this
commit.
2022-08-08 13:33:52 +05:30
Shreya Malviya d773bac8c1 Common: Simplify logic in PypubsubEventQueue 2022-08-08 13:11:07 +05:30
Shreya Malviya 8ae451f240 Common: Implement publish() in PypubsubEventQueue 2022-08-08 12:49:21 +05:30