@@ -215,6 +215,51 @@ def test_neighbors_strongly_typed(self):
215
215
self .assertEqual (neighbor ["query_type" ], "opensearch" )
216
216
self .assertEqual (neighbor ["target_systems" ], ["system1" ])
217
217
218
+ def test_neighbors_target_types (self ):
219
+ self .entity1 .link_to (self .observable1 , "uses" , "asd" )
220
+ self .entity1 .link_to (self .observable2 , "uses" , "asd" )
221
+ response = client .post (
222
+ "/api/v2/graph/search" ,
223
+ json = {
224
+ "source" : self .entity1 .extended_id ,
225
+ "hops" : 1 ,
226
+ "graph" : "links" ,
227
+ "direction" : "any" ,
228
+ "target_types" : ["hostname" ],
229
+ "include_original" : False ,
230
+ },
231
+ )
232
+ data = response .json ()
233
+ self .assertEqual (response .status_code , 200 , data )
234
+ self .assertEqual (len (data ["vertices" ]), 1 )
235
+ self .assertEqual (
236
+ data ["vertices" ][self .observable1 .extended_id ]["value" ], "tomchop.me"
237
+ )
238
+
239
+ def test_neighbors_target_types_root_type (self ):
240
+ self .entity1 .link_to (self .observable1 , "uses" , "asd" )
241
+ self .entity1 .link_to (self .observable2 , "uses" , "asd" )
242
+ response = client .post (
243
+ "/api/v2/graph/search" ,
244
+ json = {
245
+ "source" : self .entity1 .extended_id ,
246
+ "hops" : 1 ,
247
+ "graph" : "links" ,
248
+ "direction" : "any" ,
249
+ "target_types" : ["observable" ],
250
+ "include_original" : False ,
251
+ },
252
+ )
253
+ data = response .json ()
254
+ self .assertEqual (response .status_code , 200 , data )
255
+ self .assertEqual (len (data ["vertices" ]), 2 )
256
+ self .assertEqual (
257
+ data ["vertices" ][self .observable1 .extended_id ]["value" ], "tomchop.me"
258
+ )
259
+ self .assertEqual (
260
+ data ["vertices" ][self .observable2 .extended_id ]["value" ], "127.0.0.1"
261
+ )
262
+
218
263
def test_add_link (self ):
219
264
response = client .post (
220
265
"/api/v2/graph/add" ,
0 commit comments