forked from p34709852/monkey
Refactored test_new_user_communication, mostly separated to functions
This commit is contained in:
parent
4330a39725
commit
dd9a4b2d10
|
@ -5,31 +5,35 @@ from monkey_island.cc.models.zero_trust.event import Event
|
||||||
|
|
||||||
|
|
||||||
def test_new_user_communication(current_monkey, success, message):
|
def test_new_user_communication(current_monkey, success, message):
|
||||||
|
AggregateFinding.create_or_add_to_existing(
|
||||||
|
test=TEST_COMMUNICATE_AS_NEW_USER,
|
||||||
|
status=STATUS_PASSED if success else STATUS_FAILED,
|
||||||
|
events=[
|
||||||
|
get_attempt_event(current_monkey),
|
||||||
|
get_result_event(current_monkey, message, success)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_attempt_event(current_monkey):
|
||||||
tried_to_communicate_event = Event.create_event(
|
tried_to_communicate_event = Event.create_event(
|
||||||
title="Communicate as new user",
|
title="Communicate as new user",
|
||||||
message="Monkey on {} tried to create a new user and communicate from it.".format(current_monkey.hostname),
|
message="Monkey on {} tried to create a new user and communicate from it.".format(current_monkey.hostname),
|
||||||
event_type=EVENT_TYPE_MONKEY_NETWORK)
|
event_type=EVENT_TYPE_MONKEY_NETWORK)
|
||||||
events = [tried_to_communicate_event]
|
return tried_to_communicate_event
|
||||||
|
|
||||||
|
|
||||||
|
def get_result_event(current_monkey, message, success):
|
||||||
if success:
|
if success:
|
||||||
events.append(
|
event_to_append = Event.create_event(
|
||||||
Event.create_event(
|
|
||||||
title="Communicate as new user",
|
title="Communicate as new user",
|
||||||
message="New user created by Monkey on {} successfully tried to communicate with the internet. "
|
message="New user created by Monkey on {} successfully tried to communicate with the internet. "
|
||||||
"Details: {}".format(current_monkey.hostname, message),
|
"Details: {}".format(current_monkey.hostname, message),
|
||||||
event_type=EVENT_TYPE_MONKEY_NETWORK)
|
event_type=EVENT_TYPE_MONKEY_NETWORK)
|
||||||
)
|
|
||||||
test_status = STATUS_FAILED
|
|
||||||
else:
|
else:
|
||||||
events.append(
|
event_to_append = Event.create_event(
|
||||||
Event.create_event(
|
|
||||||
title="Communicate as new user",
|
title="Communicate as new user",
|
||||||
message="Monkey on {} couldn't communicate as new user. Details: {}".format(
|
message="Monkey on {} couldn't communicate as new user. Details: {}".format(
|
||||||
current_monkey.hostname, message),
|
current_monkey.hostname, message),
|
||||||
event_type=EVENT_TYPE_MONKEY_NETWORK)
|
event_type=EVENT_TYPE_MONKEY_NETWORK)
|
||||||
)
|
return event_to_append
|
||||||
test_status = STATUS_PASSED
|
|
||||||
|
|
||||||
AggregateFinding.create_or_add_to_existing(
|
|
||||||
test=TEST_COMMUNICATE_AS_NEW_USER, status=test_status, events=events
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in New Issue