Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 43 additions & 11 deletions tests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,21 @@ def test_search_indicators(self, mock_post):
mock_response.content = b'{"indicators": [{"name": "test"}]}'
mock_post.return_value = mock_response

result = self.api.search_indicators(name="test")
result = self.api.search_indicators(
name="test", description="test_description", tags=["tag1"]
)
self.assertEqual(result, [{"name": "test"}])
mock_post.assert_called_with(
"http://fake-url/api/v2/indicators/search",
json={"query": {"name": "test"}, "count": 0},
json={
"query": {
"name": "test",
"description": "test_description",
"tags": ["tag1"],
},
"count": 100,
"page": 0,
},
)

@patch("yeti.api.requests.Session.post")
Expand All @@ -42,11 +52,17 @@ def test_search_entities(self, mock_post):
mock_response.content = b'{"entities": [{"name": "test_entity"}]}'
mock_post.return_value = mock_response

result = self.api.search_entities(name="test_entity")
result = self.api.search_entities(
name="test_entity", description="test_description"
)
self.assertEqual(result, [{"name": "test_entity"}])
mock_post.assert_called_with(
"http://fake-url/api/v2/entities/search",
json={"query": {"name": "test_entity"}, "count": 0},
json={
"query": {"name": "test_entity", "description": "test_description"},
"count": 100,
"page": 0,
},
)

@patch("yeti.api.requests.Session.post")
Expand All @@ -55,11 +71,15 @@ def test_search_observables(self, mock_post):
mock_response.content = b'{"observables": [{"value": "test_value"}]}'
mock_post.return_value = mock_response

result = self.api.search_observables(value="test_value")
result = self.api.search_observables(value="test_value", tags=["tag1"])
self.assertEqual(result, [{"value": "test_value"}])
mock_post.assert_called_with(
"http://fake-url/api/v2/observables/search",
json={"query": {"value": "test_value"}, "count": 0},
json={
"query": {"value": "test_value", "tags": ["tag1"]},
"count": 100,
"page": 0,
},
)

@patch("yeti.api.requests.Session.post")
Expand Down Expand Up @@ -121,11 +141,22 @@ def test_search_dfiq(self, mock_post):
mock_response.content = b'{"dfiq": [{"name": "test_dfiq"}]}'
mock_post.return_value = mock_response

result = self.api.search_dfiq(name="test_dfiq")
result = self.api.search_dfiq(
name="test_dfiq", dfiq_yaml="yaml_content", dfiq_tags=["tag1"]
)
self.assertEqual(result, [{"name": "test_dfiq"}])
mock_post.assert_called_with(
"http://fake-url/api/v2/dfiq/search",
json={"query": {"name": "test_dfiq"}, "count": 0},
json={
"query": {
"name": "test_dfiq",
"dfiq_yaml": "yaml_content",
"dfiq_tags": ["tag1"],
},
"count": 100,
"filter_aliases": [["dfiq_tags", "list"], ["dfiq_id", "text"]],
"page": 0,
},
)

@patch("yeti.api.requests.Session.post")
Expand Down Expand Up @@ -275,14 +306,15 @@ def test_search_graph(self, mock_post):
mock_response.content = b'{"graph": "data"}'
mock_post.return_value = mock_response

result = self.api.search_graph("source", "graph", ["type"])
result = self.api.search_graph("source", ["type"])
self.assertEqual(result, {"graph": "data"})
mock_post.assert_called_with(
"http://fake-url/api/v2/graph/search",
json={
"count": 0,
"count": 50,
"page": 0,
"source": "source",
"graph": "graph",
"graph": "links",
"min_hops": 1,
"max_hops": 1,
"direction": "outbound",
Expand Down
42 changes: 39 additions & 3 deletions tests/e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def test_auth_refresh(self):
self.api.search_indicators(name="test")

def test_search_indicators(self):
self.api.auth_api_key(os.getenv("YETI_API_KEY"))
self.api.auth_api_key(os.getenv("YETI_API_KEY"))
self.api.new_indicator(
{
Expand All @@ -61,13 +60,14 @@ def test_search_indicators(self):
tags=["testtag"],
)
time.sleep(5)
result = self.api.search_indicators(name="testSear")
result = self.api.search_indicators(
name="testSear", description="tes", tags=["testtag"]
)
self.assertEqual(len(result), 1, result)
self.assertEqual(result[0]["name"], "testSearch")
self.assertEqual(result[0]["tags"][0]["name"], "testtag")

def test_find_indicator(self):
self.api.auth_api_key(os.getenv("YETI_API_KEY"))
self.api.auth_api_key(os.getenv("YETI_API_KEY"))
self.api.new_indicator(
{
Expand All @@ -85,3 +85,39 @@ def test_find_indicator(self):
self.assertEqual(indicator["name"], "testGet")
self.assertEqual(indicator["pattern"], "test[0-9]")
self.assertEqual(indicator["tags"][0]["name"], "testtag")

def test_link_objects(self):
self.api.auth_api_key(os.getenv("YETI_API_KEY"))
indicator = self.api.new_indicator(
{
"name": "testLink",
"type": "regex",
"description": "test",
"pattern": "test[0-9]",
"diamond": "victim",
}
)
malware = self.api.new_entity(
{
"name": "testMalware",
"type": "malware",
"description": "test",
}
)
self.api.link_objects(
source=indicator,
target=malware,
link_type="indicates",
description="test link",
)

# get neighbors
neighbors = self.api.search_graph(
f'indicator/{indicator["id"]}',
target_types=["malware"],
include_original=False,
)
self.assertEqual(len(neighbors["vertices"]), 1)
self.assertEqual(
neighbors["vertices"][f'entities/{malware["id"]}']["name"], "testMalware"
)
Loading