@@ -3197,6 +3197,43 @@ def test_event_galaxy(self) -> None:
3197
3197
self .admin_misp_connector .delete_event (event )
3198
3198
self .admin_misp_connector .toggle_global_pythonify ()
3199
3199
3200
+ def test_attach_galaxy_cluster (self ) -> None :
3201
+ event = self .create_simple_event ()
3202
+ event = self .admin_misp_connector .add_event (event , pythonify = True )
3203
+ try :
3204
+ galaxies : list [MISPGalaxy ] = self .admin_misp_connector .galaxies (pythonify = True )
3205
+ galaxy : MISPGalaxy = galaxies [0 ]
3206
+ if gid := galaxy .id :
3207
+ galaxy = self .admin_misp_connector .get_galaxy (gid , withCluster = True , pythonify = True )
3208
+ else :
3209
+ raise Exception ("No galaxy found" )
3210
+ galaxy_cluster : MISPGalaxyCluster = galaxy .clusters [0 ]
3211
+ self .admin_misp_connector .attach_galaxy_cluster (event , galaxy_cluster )
3212
+ event = self .admin_misp_connector .get_event (event .id , pythonify = True )
3213
+
3214
+ self .assertEqual (len (event .galaxies ), 1 )
3215
+ event_galaxy = event .galaxies [0 ]
3216
+ # The galaxy ID should equal the galaxy from which the cluster came from
3217
+ self .assertEqual (event_galaxy .id , galaxy .id )
3218
+ # The galaxy cluster should equal the cluster added
3219
+ self .assertEqual (event_galaxy .clusters [0 ].id , galaxy_cluster .id )
3220
+
3221
+ galaxy_cluster : MISPGalaxyCluster = galaxy .clusters [1 ]
3222
+
3223
+ # Test on attribute
3224
+ attribute = event .Attribute [0 ]
3225
+ event = self .admin_misp_connector .get_event (event .id , pythonify = True )
3226
+ attribute = event .Attribute [0 ]
3227
+ self .assertEqual (len (attribute .galaxies ), 1 )
3228
+ attribute_galaxy = attribute .galaxies [0 ]
3229
+ # The galaxy ID should equal the galaxy from which the cluster came from
3230
+ self .assertEqual (attribute_galaxy .id , galaxy .id )
3231
+ # The galaxy cluster should equal the cluster added
3232
+ self .assertEqual (attribute_galaxy .clusters [0 ].id , galaxy_cluster .id )
3233
+ finally :
3234
+ self .admin_misp_connector .delete_event (event )
3235
+ self .admin_misp_connector .toggle_global_pythonify ()
3236
+
3200
3237
@unittest .skip ("Internal use only" )
3201
3238
def missing_methods (self ) -> None :
3202
3239
skip = [
0 commit comments