From dbb3cd5b5e38c1817449b4b819ff5a527c8525b8 Mon Sep 17 00:00:00 2001 From: Katie Strader Date: Fri, 15 Nov 2024 10:17:09 -0700 Subject: [PATCH] Added a couple of null tests for ResolveGroupName and an error test for GetLocalGroups. --- test/unit/LocalGroupProcessorTest.cs | 80 ++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/test/unit/LocalGroupProcessorTest.cs b/test/unit/LocalGroupProcessorTest.cs index 01d68d67..335dfbd9 100644 --- a/test/unit/LocalGroupProcessorTest.cs +++ b/test/unit/LocalGroupProcessorTest.cs @@ -9,6 +9,8 @@ using SharpHoundCommonLib.OutputTypes; using SharpHoundCommonLib.Processors; using SharpHoundRPC; +using SharpHoundRPC.SAMRPCNative; +using SharpHoundRPC.Wrappers; using Xunit; using Xunit.Abstractions; @@ -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(); + var proc = new LocalGroupProcessor(mockUtils.Object); + + var resultTask = TestPrivateMethod.InstanceMethod>(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(); + var proc = new LocalGroupProcessor(mockUtils.Object); + + var resultTask = TestPrivateMethod.InstanceMethod>(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() { @@ -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(); + var mockProcessor = new Mock(mockUtils.Object, null); + + mockProcessor.Setup(x => x.OpenSamServer(It.IsAny())).Returns(() => { + Task.Delay(100).Wait(); + return NtStatus.StatusAccessDenied; + }); + var processor = mockProcessor.Object; + var machineDomainSid = $"{Consts.MockDomainSid}-1000"; + var receivedStatus = new List(); + 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(); + // var mockProcessor = new Mock(mockUtils.Object, null); + // var mockSamServer = new MockWorkstationSAMServer(); + // var receivedStatus = new SharpHoundRPC.Result(); + // // 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()); + // + // Assert.True(results.IsFailed); + // + // + // } } } \ No newline at end of file