new: [test] Test more endpoints in sync test

pull/7637/head
Jakub Onderka 2021-08-10 22:03:35 +02:00
parent 748f74a072
commit f50b7440af
2 changed files with 112 additions and 92 deletions

View File

@ -1317,21 +1317,19 @@
"name": "CIRCL", "name": "CIRCL",
"uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f" "uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f"
}, },
"Event": [ "Event": {
{ "id": "2006",
"id": "2006", "date": "2015-08-27",
"date": "2015-08-27", "threat_level_id": "1",
"threat_level_id": "1", "info": "OSINT - Regin: Top-tier espionage tool enables stealthy surveillance by Symantec",
"info": "OSINT - Regin: Top-tier espionage tool enables stealthy surveillance by Symantec", "published": true,
"published": true, "uuid": "55df7369-7d68-428b-aa03-4f5d950d210b",
"uuid": "55df7369-7d68-428b-aa03-4f5d950d210b", "analysis": "2",
"analysis": "2", "timestamp": "1440752388",
"timestamp": "1440752388", "distribution": "3",
"distribution": "3", "org_id": "2",
"org_id": "2", "orgc_id": "2"
"orgc_id": "2" }
}
]
}, },
{ {
"Org": { "Org": {
@ -1344,21 +1342,19 @@
"name": "CIRCL", "name": "CIRCL",
"uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f" "uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f"
}, },
"Event": [ "Event": {
{ "id": "833",
"id": "833", "date": "2015-01-22",
"date": "2015-01-22", "threat_level_id": "1",
"threat_level_id": "1", "info": "OSINT - An analysis of Regin's Hopscotch and Legspin",
"info": "OSINT - An analysis of Regin's Hopscotch and Legspin", "published": true,
"published": true, "uuid": "54c0ce92-9d00-42b7-8cfc-f03f950d210b",
"uuid": "54c0ce92-9d00-42b7-8cfc-f03f950d210b", "analysis": "2",
"analysis": "2", "timestamp": "1422266910",
"timestamp": "1422266910", "distribution": "3",
"distribution": "3", "org_id": "2",
"org_id": "2", "orgc_id": "2"
"orgc_id": "2" }
}
]
}, },
{ {
"Org": { "Org": {
@ -1371,21 +1367,19 @@
"name": "CIRCL", "name": "CIRCL",
"uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f" "uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f"
}, },
"Event": [ "Event": {
{ "id": "697",
"id": "697", "date": "2014-11-24",
"date": "2014-11-24", "threat_level_id": "1",
"threat_level_id": "1", "info": "OSINT - Regin: Top-tier espionage tool enables stealthy surveillance",
"info": "OSINT - Regin: Top-tier espionage tool enables stealthy surveillance", "published": true,
"published": true, "uuid": "5472cdc5-3e3c-47c9-a3b1-47be950d210b",
"uuid": "5472cdc5-3e3c-47c9-a3b1-47be950d210b", "analysis": "2",
"analysis": "2", "timestamp": "1416818985",
"timestamp": "1416818985", "distribution": "3",
"distribution": "3", "org_id": "2",
"org_id": "2", "orgc_id": "2"
"orgc_id": "2" }
}
]
}, },
{ {
"Org": { "Org": {
@ -1398,21 +1392,19 @@
"name": "CIRCL", "name": "CIRCL",
"uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f" "uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f"
}, },
"Event": [ "Event": {
{ "id": "699",
"id": "699", "date": "2014-11-24",
"date": "2014-11-24", "threat_level_id": "1",
"threat_level_id": "1", "info": "OSINT - The Regin Espionage Toolkit",
"info": "OSINT - The Regin Espionage Toolkit", "published": true,
"published": true, "uuid": "5472fbd1-1a38-484a-b3f4-4502950d210b",
"uuid": "5472fbd1-1a38-484a-b3f4-4502950d210b", "analysis": "2",
"analysis": "2", "timestamp": "1416821880",
"timestamp": "1416821880", "distribution": "3",
"distribution": "3", "org_id": "2",
"org_id": "2", "orgc_id": "2"
"orgc_id": "2" }
}
]
}, },
{ {
"Org": { "Org": {
@ -1425,21 +1417,19 @@
"name": "CIRCL", "name": "CIRCL",
"uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f" "uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f"
}, },
"Event": [ "Event": {
{ "id": "700",
"id": "700", "date": "2014-11-24",
"date": "2014-11-24", "threat_level_id": "1",
"threat_level_id": "1", "info": "Regin Yara rules",
"info": "Regin Yara rules", "published": true,
"published": true, "uuid": "5473051e-2db8-4467-b6d5-4b1d950d210b",
"uuid": "5473051e-2db8-4467-b6d5-4b1d950d210b", "analysis": "1",
"analysis": "1", "timestamp": "1417157341",
"timestamp": "1417157341", "distribution": "3",
"distribution": "3", "org_id": "2",
"org_id": "2", "orgc_id": "2"
"orgc_id": "2" }
}
]
}, },
{ {
"Org": { "Org": {
@ -1452,21 +1442,19 @@
"name": "CIRCL", "name": "CIRCL",
"uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f" "uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f"
}, },
"Event": [ "Event": {
{ "id": "709",
"id": "709", "date": "2014-11-24",
"date": "2014-11-24", "threat_level_id": "1",
"threat_level_id": "1", "info": "OSINT - Regin: Nation-state ownage of GSM networks",
"info": "OSINT - Regin: Nation-state ownage of GSM networks", "published": true,
"published": true, "uuid": "5473429a-bc10-498d-a195-46e2950d2109",
"uuid": "5473429a-bc10-498d-a195-46e2950d2109", "analysis": "2",
"analysis": "2", "timestamp": "1416843113",
"timestamp": "1416843113", "distribution": "3",
"distribution": "3", "org_id": "2",
"org_id": "2", "orgc_id": "2"
"orgc_id": "2" }
}
]
} }
], ],
"Tag": [ "Tag": [

View File

@ -1,5 +1,5 @@
import os import os
from pymisp import PyMISP from pymisp import PyMISP, MISPEvent
def check_response(response): def check_response(response):
@ -18,8 +18,10 @@ pymisp.global_pythonify = True
remote_server = pymisp.add_server({ remote_server = pymisp.add_server({
"pull": True, "pull": True,
"pull_galaxy_clusters": True, "pull_galaxy_clusters": True,
"push_galaxy_clusters": True,
"push": True, "push": True,
"push_sightings": True, "push_sightings": True,
"caching_enabled": True,
"remote_org_id": 1, "remote_org_id": 1,
"name": "Localhost", "name": "Localhost",
"url": url, "url": url,
@ -41,17 +43,47 @@ assert remote_user["Sync flag"] == "Yes"
assert remote_user["Role name"] == "admin" assert remote_user["Role name"] == "admin"
assert remote_user["User"] == "admin@admin.test" assert remote_user["User"] == "admin@admin.test"
# Create testing event
event = MISPEvent()
event.load_file(os.path.dirname(os.path.realpath(__file__)) + "/event.json")
pymisp.delete_event_blocklist(event)
event = pymisp.add_event(event, metadata=True)
check_response(event)
# Publish that event
check_response(pymisp.publish(event))
# Preview event
url = f'servers/previewEvent/{remote_server["id"]}/{event.uuid}'
event_preview = pymisp._check_json_response(pymisp._prepare_request('GET', url))
check_response(event_preview)
assert event_preview["Event"]["uuid"] == event.uuid
# Test pull # Test pull
url = f'servers/pull/{remote_server["id"]}/disable_background_processing:1' url = f'servers/pull/{remote_server["id"]}/disable_background_processing:1'
pull_response = pymisp._check_json_response(pymisp._prepare_request('GET', url)) pull_response = pymisp._check_json_response(pymisp._prepare_request('GET', url))
check_response(pull_response) check_response(pull_response)
assert "Pull completed. 0 events pulled, 0 events could not be pulled, 0 proposals pulled, 0 sightings pulled, 0 clusters pulled." == pull_response["message"], pull_response["message"] assert "Pull completed. 0 events pulled, 0 events could not be pulled, 0 proposals pulled, 0 sightings pulled, 0 clusters pulled." == pull_response["message"], pull_response["message"]
# Test pull background
check_response(pymisp.server_pull(remote_server))
# Test push # Test push
url = f'servers/push/{remote_server["id"]}/full/disable_background_processing:1' url = f'servers/push/{remote_server["id"]}/full/disable_background_processing:1'
push_response = pymisp._check_json_response(pymisp._prepare_request('GET', url)) push_response = pymisp._check_json_response(pymisp._prepare_request('GET', url))
check_response(push_response) check_response(push_response)
assert "Push complete. 0 events pushed, 0 events could not be pushed." == push_response["message"], push_response["message"] assert "Push complete. 0 events pushed, 0 events could not be pushed." == push_response["message"], push_response["message"]
# Delete server # Test push background
check_response(pymisp.server_push(remote_server))
# Test caching
url = f'servers/cache/{remote_server["id"]}/disable_background_processing:1'
cache_response = pymisp._check_json_response(pymisp._prepare_request('GET', url))
check_response(cache_response)
assert "Caching the servers has successfully completed." == cache_response["message"], cache_response["message"]
# Delete server and test event
check_response(pymisp.delete_server(remote_server)) check_response(pymisp.delete_server(remote_server))
check_response(pymisp.delete_event(event))
check_response(pymisp.delete_event_blocklist(event))