forked from p15670423/monkey
Lowered code dup in get_result_event
This commit is contained in:
parent
dd9a4b2d10
commit
76c642e4b3
|
@ -3,6 +3,10 @@ from common.data.zero_trust_consts import EVENT_TYPE_MONKEY_NETWORK, STATUS_FAIL
|
|||
from monkey_island.cc.models.zero_trust.aggregate_finding import AggregateFinding
|
||||
from monkey_island.cc.models.zero_trust.event import Event
|
||||
|
||||
COMM_AS_NEW_USER_FAILED_FORMAT = "Monkey on {} couldn't communicate as new user. Details: {}"
|
||||
COMM_AS_NEW_USER_SUCCEEDED_FORMAT = \
|
||||
"New user created by Monkey on {} successfully tried to communicate with the internet. Details: {}"
|
||||
|
||||
|
||||
def test_new_user_communication(current_monkey, success, message):
|
||||
AggregateFinding.create_or_add_to_existing(
|
||||
|
@ -24,16 +28,9 @@ def get_attempt_event(current_monkey):
|
|||
|
||||
|
||||
def get_result_event(current_monkey, message, success):
|
||||
if success:
|
||||
event_to_append = Event.create_event(
|
||||
title="Communicate as new user",
|
||||
message="New user created by Monkey on {} successfully tried to communicate with the internet. "
|
||||
"Details: {}".format(current_monkey.hostname, message),
|
||||
event_type=EVENT_TYPE_MONKEY_NETWORK)
|
||||
else:
|
||||
event_to_append = Event.create_event(
|
||||
title="Communicate as new user",
|
||||
message="Monkey on {} couldn't communicate as new user. Details: {}".format(
|
||||
current_monkey.hostname, message),
|
||||
event_type=EVENT_TYPE_MONKEY_NETWORK)
|
||||
return event_to_append
|
||||
message_format = COMM_AS_NEW_USER_SUCCEEDED_FORMAT if success else COMM_AS_NEW_USER_FAILED_FORMAT
|
||||
|
||||
return Event.create_event(
|
||||
title="Communicate as new user",
|
||||
message=message_format.format(current_monkey.hostname, message),
|
||||
event_type=EVENT_TYPE_MONKEY_NETWORK)
|
||||
|
|
Loading…
Reference in New Issue