Skip to content

Commit

Permalink
chore: fix broken tests
Browse files Browse the repository at this point in the history
fix: make gpolocalgroup processor a bit smarter
  • Loading branch information
rvazarkar committed Jul 26, 2024
1 parent d172461 commit 925f168
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
13 changes: 12 additions & 1 deletion src/CommonLib/Processors/GPOLocalGroupProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,18 @@ public async Task<ResultingGPOChanges> ReadGPOLocalGroups(string gpLink, string
if (gpLink == null)
return ret;

var domain = Helpers.DistinguishedNameToDomain(distinguishedName);
string domain;
//If our dn is null, use our default domain
if (string.IsNullOrEmpty(distinguishedName)) {
if (!_utils.GetDomain(out var d)) {
return ret;
}

domain = d.Name;
} else {
domain = Helpers.DistinguishedNameToDomain(distinguishedName);
}

// First lets check if this OU actually has computers that it contains. If not, then we'll ignore it.
// Its cheaper to fetch the affected computers from LDAP first and then process the GPLinks
var affectedComputers = new List<TypedPrincipal>();
Expand Down
13 changes: 5 additions & 8 deletions test/unit/GPOLocalGroupProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ public async Task GPOLocalGroupProcessor_ReadGPOLocalGroups_Null_Gpcfilesyspath(
var result = await processor.ReadGPOLocalGroups(testGPLinkProperty, null);

Assert.NotNull(result);
Assert.Single(result.AffectedComputers);
var actual = result.AffectedComputers.First();
Assert.Equal(Label.Computer, actual.ObjectType);
Assert.Equal("teapot", actual.ObjectIdentifier);
Assert.Empty(result.AffectedComputers);
}

[Fact]
Expand Down Expand Up @@ -189,12 +186,12 @@ public async Task GPOLocalGroupProcessor_ReadGPOLocalGroups() {
"[LDAP:/o=foo/ou=foo Group (ABC123)/cn=foouser (blah)123/dc=somedomain;0;][LDAP:/o=foo/ou=foo Group (ABC123)/cn=foouser (blah)123/dc=someotherdomain;2;]";
var result = await processor.ReadGPOLocalGroups(testGPLinkProperty, null);

var domain = MockableDomain.Construct("TESTLAB.LOCAL");
mockLDAPUtils.Setup(x => x.GetDomain(out domain)).Returns(true);

mockLDAPUtils.VerifyAll();
Assert.NotNull(result);
Assert.Single(result.AffectedComputers);
var actual = result.AffectedComputers.First();
Assert.Equal(Label.Computer, actual.ObjectType);
Assert.Equal("teapot", actual.ObjectIdentifier);
Assert.Empty(result.AffectedComputers);
}

[Fact]
Expand Down

0 comments on commit 925f168

Please sign in to comment.