@@ -2235,6 +2235,51 @@ def test_sharing_group(self):
22352235 finally :
22362236 self .admin_misp_connector .delete_sharing_group (sharing_group .id )
22372237
2238+ def test_sharing_group_search (self ):
2239+ # Add sharing group
2240+ sg = MISPSharingGroup ()
2241+ sg .name = 'Testcases SG'
2242+ sg .releasability = 'Testing'
2243+ sharing_group = self .admin_misp_connector .add_sharing_group (sg , pythonify = True )
2244+ # Add the org to the sharing group
2245+ self .admin_misp_connector .add_org_to_sharing_group (
2246+ sharing_group ,
2247+ self .test_org , extend = True
2248+ )
2249+ # Add event
2250+ event = self .create_simple_event ()
2251+ event .distribution = Distribution .sharing_group
2252+ event .sharing_group_id = sharing_group .id
2253+ # Create two attributes, one specifically for the sharing group,
2254+ # another which inherits the event's SG
2255+ event .add_attribute ('ip-dst' , '8.8.8.8' , distribution = 4 , sharing_group_id = sharing_group .id )
2256+ event .add_attribute ('ip-dst' , '9.9.9.9' )
2257+ event = self .user_misp_connector .add_event (event )
2258+ attribute_ids = {a .id for a in event .attributes }
2259+ try :
2260+ # Try to query for the event
2261+ events = self .user_misp_connector .search (sharinggroup = sharing_group .id , controller = "events" )
2262+ # There should be one event
2263+ self .assertTrue (len (events ) == 1 )
2264+ # This event should be the one we added
2265+ self .assertEqual (events [0 ].id , event .id )
2266+ # Make sure the search isn't just returning everything
2267+ events = self .user_misp_connector .search (sharinggroup = 99999 , controller = "events" )
2268+
2269+ self .assertTrue (len (events ) == 0 )
2270+
2271+ # Try to query for the attributes
2272+ attributes = self .user_misp_connector .search (sharinggroup = sharing_group .id , controller = "attributes" )
2273+ searched_attribute_ids = {a .id for a in attributes }
2274+ # There should be two attributes
2275+ # The extra 1 is the random UUID now created in the event
2276+ self .assertTrue (len (attributes ) == 2 + 1 )
2277+ # We should not be missing any of the attributes
2278+ self .assertFalse (attribute_ids .difference (searched_attribute_ids ))
2279+ finally :
2280+ self .admin_misp_connector .delete_sharing_group (sharing_group .id )
2281+ self .user_misp_connector .delete_event (event .id )
2282+
22382283 def test_feeds (self ):
22392284 # Add
22402285 feed = MISPFeed ()
0 commit comments