Skip to content

Commit

Permalink
Added a couple of null tests for ResolveGroupName and an error test f…
Browse files Browse the repository at this point in the history
…or GetLocalGroups.
  • Loading branch information
ktstrader committed Nov 15, 2024
1 parent 9e03f0c commit dbb3cd5
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions test/unit/LocalGroupProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using SharpHoundCommonLib.OutputTypes;
using SharpHoundCommonLib.Processors;
using SharpHoundRPC;
using SharpHoundRPC.SAMRPCNative;
using SharpHoundRPC.Wrappers;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -113,6 +115,40 @@ public async Task LocalGroupProcessor_ResolveGroupName_DC()
;
Assert.Equal("TESTLAB.LOCAL-S-1-5-32-544", result.ObjectId);
}

[Fact]
public async Task LocalGroupProcessor_ResolveGroupName_NullComputerDomainSid_DC_NotBuiltIn()
{
var mockUtils = new Mock<MockLdapUtils>();
var proc = new LocalGroupProcessor(mockUtils.Object);

var resultTask = TestPrivateMethod.InstanceMethod<Task<NamedPrincipal>>(proc, "ResolveGroupName",
new object[]
{
"ADMINISTRATORS", "PRIMARY.TESTLAB.LOCAL", null, "TESTLAB.LOCAL", 544, true, false
});

var result = await resultTask;

Assert.Equal(null, result);
}

[Fact]
public async Task LocalGroupProcessor_ResolveGroupName_NullComputerDomainSid_NonDC()
{
var mockUtils = new Mock<MockLdapUtils>();
var proc = new LocalGroupProcessor(mockUtils.Object);

var resultTask = TestPrivateMethod.InstanceMethod<Task<NamedPrincipal>>(proc, "ResolveGroupName",
new object[]
{
"ADMINISTRATORS", "PRIMARY.TESTLAB.LOCAL", null, "TESTLAB.LOCAL", 544, false, true
});

var result = await resultTask;

Assert.Equal(null, result);
}

[Fact]
public async Task LocalGroupProcessor_TestTimeout() {
Expand All @@ -136,5 +172,49 @@ public async Task LocalGroupProcessor_TestTimeout() {
var status = receivedStatus[0];
Assert.Equal("Timeout", status.Status);
}

[Fact]
public async Task LocalGroupProcessor_TestStatusAccessDenied() {
var mockUtils = new Mock<MockLdapUtils>();
var mockProcessor = new Mock<LocalGroupProcessor>(mockUtils.Object, null);

mockProcessor.Setup(x => x.OpenSamServer(It.IsAny<string>())).Returns(() => {
Task.Delay(100).Wait();
return NtStatus.StatusAccessDenied;
});
var processor = mockProcessor.Object;
var machineDomainSid = $"{Consts.MockDomainSid}-1000";
var receivedStatus = new List<CSVComputerStatus>();
processor.ComputerStatusEvent += async status => {
receivedStatus.Add(status);
};
var results = await processor.GetLocalGroups("primary.testlab.local", machineDomainSid, "testlab.local", true)
.ToArrayAsync();
Assert.Empty(results);
Assert.Single(receivedStatus);
var status = receivedStatus[0];
Assert.Equal("StatusAccessDenied", status.Status);
}

// [Fact]
// public async Task LocalGroupProcessor_OpenSamServer()
// {
// var mockUtils = new Mock<MockLdapUtils>();
// var mockProcessor = new Mock<LocalGroupProcessor>(mockUtils.Object, null);
// var mockSamServer = new MockWorkstationSAMServer();
// var receivedStatus = new SharpHoundRPC.Result<ISAMServer>();
// // mockProcessor.Setup(x => SAMServer.OpenServer("primary.testlab.local", mockSamServer.)).Returns(() => {
// // Task.Delay(100).Wait();
// // return receivedStatus.Error;
// // });
// var processor = mockProcessor.Object;
//
//
// var results = processor.OpenSamServer(It.IsAny<string>());
//
// Assert.True(results.IsFailed);
//
//
// }
}
}

0 comments on commit dbb3cd5

Please sign in to comment.