Example #1
0
 def test_create_graph_hide_ids(self):
     hide_ids = ['blue']
     stack = [(0, None, self.mock_edge4, 'edge')]
     response = create_graph(stack, [], [], [], [], hide_ids,
                             self.mock_request)
     self.assertEquals(response['nodes'], [])
     self.assertEquals(response['links'], [])
Example #2
0
 def test_create_graph_with_match_rel_type(self):
     id_matches = ['purple']
     stack = [(0, None, self.mock_matching, 'match')]
     response = create_graph(stack, [], id_matches, [], [], [],
                             self.mock_request)
     self.assertEquals(response['nodes'], [self.matching_node])
     self.assertEquals(response['links'], [])
def iterate_draft(draft_object, bl_ids, id_matches, hide_edge_ids, show_edge_ids, hidden_ids, request):
    def create_draft_observable_id(obs):
        d = create_draft_obs_hash(obs)
        return draft_object['id'].replace('indicator', 'observable') + DRAFT_ID_SEPARATOR + d

    def create_draft_obs_node(obs_id, title):
        summary = {'title': title, 'type': 'obs', 'value': '', '_id': obs_id, 'cv': '', 'tg': '',
                   'data': {'idns': '', 'etlp': '', 'summary': {'title': title},
                            'hash': '', 'api': ''}, 'created_by_organization': ''}
        return EdgeObject(summary)

    def create_draft_ind_node(ind_id, title):
        summary = {'title': title, 'type': 'ind', 'value': '', '_id': ind_id, 'cv': '', 'tg': '',
                   'data': {'idns': '', 'etlp': '', 'summary': {'title': title},
                            'hash': '', 'api': ''}, 'created_by_organization': ''}
        return EdgeObject(summary)

    stack = []
    for i in xrange(len(draft_object['observables'])):
        observable = draft_object['observables'][i]
        obs_id = observable['id'] if 'id' in observable else create_draft_observable_id(observable)
        if obs_id not in hidden_ids:
            if DRAFT_ID_SEPARATOR in obs_id:
                stack.append(
                    (1, 0, create_draft_obs_node(obs_id, observable_to_name(observable, True)), REL_TYPE_DRAFT))
            else:
                try:
                    stack.append((1, 0, EdgeObject.load(obs_id, request.user.filters()), REL_TYPE_EDGE))
                except:
                    stack.append((1, 0, create_external_reference_from_id(obs_id), REL_TYPE_EXT))

    stack.append((0, None, create_draft_ind_node(draft_object['id'], draft_object['title']), REL_TYPE_DRAFT))

    return create_graph(stack, bl_ids, id_matches, hide_edge_ids, show_edge_ids, hidden_ids, request)
Example #4
0
 def test_create_graph_show_edges_ids(self):
     show_edge_ids = ['red']
     stack = [(0, None, self.mock_edge, 'edge')]
     response = create_graph(stack, [], [], [], show_edge_ids, [],
                             self.mock_request)
     self.assertEquals(response['nodes'], [self.edge_node])
     self.assertEquals(response['links'], [])
Example #5
0
def visualiser_get(request, id_):
    try:
        root_edge_object = PublisherEdgeObject.load(id_)
        graph = create_graph([(0, None, root_edge_object, REL_TYPE_EDGE)], [],
                             [], [], [], [], request)
        return JsonResponse(graph, status=200)
    except Exception as e:
        return JsonResponse({'error': e.message}, status=500)
Example #6
0
 def test_create_graph_existing_id(self):
     stack = [(0, None, self.mock_edge2, 'edge')]
     self.mock_edgeobj.load.return_value = self.mock_edge5
     links = [{'source': 0, 'target': 0, 'rel_type': 'edge'}]
     response = create_graph(stack, [], [], [], [], [], self.mock_request)
     self.assertEqual(len(response['nodes']), 1)
     self.assertEqual(response['nodes'], [self.edge_node2])
     self.assertEqual(response['links'], links)
Example #7
0
 def test_create_graph_with_links(self):
     self.mock_edgeobj.load.return_value = self.mock_edge3
     stack = [(0, None, self.mock_edge2, 'edge')]
     response = create_graph(stack, [], [], [], [], [], self.mock_request)
     links = [{'source': 0, 'target': 1, 'rel_type': 'edge'}]
     self.assertDictEqual(response['nodes'][0], self.edge_node2)
     self.assertDictEqual(response['nodes'][1], self.edge_node3)
     self.assertEquals(response['links'], links)
 def test_create_graph_external_ref_link(self, mock_request):
     self.mock_external_ref.fetch.side_effect = EdgeError(
         'purple not found')
     stack = [(0, None, self.mock_edge2, 'edge')]
     response = create_graph(stack, [], [], [], [], [], mock_request)
     links = [{'source': 0, 'target': 1, 'rel_type': 'external_ref'}]
     self.assertEquals(response['nodes'][0], self.edge_node2)
     self.assertEquals(response['nodes'][1], self.external_node2)
     self.assertEquals(response['links'], links)
Example #9
0
 def test_create_graph_with_match_link(self, mock_edge_object):
     id_matches = ['purple']
     self.mock_get_matches.return_value = ['matt']
     mock_edge_object.load.return_value = self.mock_matching2
     stack = [(0, None, self.mock_matching, 'match')]
     response = create_graph(stack, [], id_matches, [], [], [],
                             self.mock_request)
     links = [{'source': 0, 'target': 1, 'rel_type': 'match'}]
     self.assertEqual(response['nodes'][0], self.matching_node)
     self.assertEqual(response['nodes'][1], self.matching_node2)
     self.assertEqual(response['links'], links)
Example #10
0
def visualiser_get_extended(request):
    json_data = json.loads(request.body)
    root_id = json_data['id']
    bl_ids = json_data['id_bls']
    match_ids = json_data['id_matches']
    hide_edge_ids = json_data['hide_edge_ids']
    show_edge_ids = json_data['show_edge_ids']
    hidden_ids = json_data['hidden_ids']
    try:
        root_edge_object = PublisherEdgeObject.load(root_id)
        graph = create_graph([(0, None, root_edge_object, REL_TYPE_EDGE)],
                             bl_ids, match_ids, hide_edge_ids, show_edge_ids,
                             hidden_ids, request)
        return JsonResponse(graph, status=200)
    except Exception as e:
        return JsonResponse({'error': e.message}, status=500)
 def test_create_graph_with_draft_rel_type(self, mock_request):
     stack = [(0, None, self.mock_edge, 'draft')]
     response = create_graph(stack, [], [], [], [], [], mock_request)
     self.assertEquals(response['nodes'], [self.draft_node])
 def test_create_graph_with_external_ref_rel_type(self, mock_request):
     stack = [(0, None, self.mock_edge, 'external_ref')]
     response = create_graph(stack, [], [], [], [], [], mock_request)
     self.assertEquals(response['nodes'], [self.external_node])
     self.assertEquals(response['links'], [])
Example #13
0
 def test_create_graph_backlinks_matches_called(self):
     stack = [(0, None, self.mock_edge, 'edge')]
     create_graph(stack, [], [], [], [], [], self.mock_request)
     self.mock_backlinks_exist.assert_called_with('red')
     self.mock_matches_exist.assert_called_with('red', self.mock_request)
Example #14
0
 def test_create_graph_build_title_called(self):
     stack = [(0, None, self.mock_edge_title_None, 'edge')]
     create_graph(stack, [], [], [], [], [], self.mock_request)
     self.mock_build_title.assert_called_with(self.mock_edge_title_None)