Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
checkymander committed Jan 14, 2025
1 parent a2bfe47 commit 5ac7656
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public async Task TestGetTaskingMultiple()
AthenaCore _agent = new AthenaCore(_profile, _taskManager, _logger, _config, _tokenManager, new List<IAgentMod>() { _agentMod });
TestProfile prof = (TestProfile)_profile.First();

Task.Run(_agent.Start);
await _agent.Start();
_profile.First().SetTaskingReceived += (sender, args) => taskingReceived.Set();

((TestTaskManager)_taskManager).WaitForNumberOfJobs(3);
Expand Down Expand Up @@ -109,18 +109,5 @@ public async Task TestGetTaskingNoTasks() {
_profile.First().StopBeacon();
Assert.IsTrue(((TestTaskManager)_taskManager).jobs.Count == 0);
}
[TestMethod]
public async Task TestGetTaskingNullTasks()
{
ManualResetEvent taskingReceived = new ManualResetEvent(false);
IEnumerable<IProfile> _profile = new List<IProfile>() { new TestProfile(true) };
_profile.First().SetTaskingReceived += (sender, args) => taskingReceived.Set();
TestProfile prof = (TestProfile)_profile.First();
AthenaCore _agent = new AthenaCore(_profile, _taskManager, _logger, _config, _tokenManager, new List<IAgentMod>() { _agentMod });
Task.Run(_agent.Start);
prof.taskingSent.WaitOne(1000);
_profile.First().StopBeacon();
Assert.IsTrue(((TestTaskManager)_taskManager).jobs.Count == 0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,11 @@ public class TestProfile : IProfile
private bool returnedTask = false;
public CancellationTokenSource cts = new CancellationTokenSource();
public ManualResetEvent taskingSent = new ManualResetEvent(false);
public TestProfile() {

checkinResponse = new CheckinResponse()
{
status = "success",
action = "checkin",
id = Guid.NewGuid().ToString(),
encryption_key = "",
decryption_key = "",
process_name = "",
};

getTaskingResponse = new GetTaskingResponse()
{
action = "get_tasking",
tasks = new List<ServerTask>()
{
new ServerTask()
{
id = Guid.NewGuid().ToString(),
command = "whoami",
parameters = "",
}
},
socks = new List<ServerDatagram>(),
rpfwd = new List<ServerDatagram>(),
delegates = new List<DelegateMessage>(),
};
public TestProfile()
{
}
public TestProfile(CheckinResponse? checkinResponse)
{
Console.WriteLine(checkinResponse.status);
this.checkinResponse = checkinResponse;
}

Expand All @@ -64,6 +37,18 @@ public TestProfile(bool nullable)

public async Task<CheckinResponse> Checkin(Checkin checkin)
{
if (this.checkinResponse is null)
{
return new CheckinResponse()
{
status = "success",
action = "checkin",
id = Guid.NewGuid().ToString(),
encryption_key = "",
decryption_key = "",
process_name = "",
};
}
return this.checkinResponse;
}

Expand All @@ -74,10 +59,36 @@ public async Task StartBeacon()
{
if (!returnedTask)
{
TaskingReceivedArgs tra = new TaskingReceivedArgs(getTaskingResponse);
TaskingReceivedArgs tra;
if (this.getTaskingResponse is null)
{

tra = new TaskingReceivedArgs(new GetTaskingResponse()
{
action = "get_tasking",
tasks = new List<ServerTask>()
{
new ServerTask()
{
id = Guid.NewGuid().ToString(),
command = "whoami",
parameters = "",
},
},
socks = new List<ServerDatagram>(),
rpfwd = new List<ServerDatagram>(),
delegates = new List<DelegateMessage>(),
});
}
else
{
tra = new TaskingReceivedArgs(this.getTaskingResponse);
}

SetTaskingReceived?.Invoke(this, tra);
returnedTask = true;
taskingSent.Set();
return;
}
}
isRunning = false;
Expand Down

0 comments on commit 5ac7656

Please sign in to comment.