From 6b9a70085201a3b1a2e3a852a5ab751178308d99 Mon Sep 17 00:00:00 2001 From: anemeth Date: Thu, 18 Jan 2024 09:16:46 -0800 Subject: [PATCH] Begin adding tests for new functions --- .../Processors/LDAPPropertyProcessor.cs | 8 ++-- test/unit/LDAPPropertyTests.cs | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/CommonLib/Processors/LDAPPropertyProcessor.cs b/src/CommonLib/Processors/LDAPPropertyProcessor.cs index 7160128d..b7f61326 100644 --- a/src/CommonLib/Processors/LDAPPropertyProcessor.cs +++ b/src/CommonLib/Processors/LDAPPropertyProcessor.cs @@ -128,7 +128,7 @@ public async Task ReadUserProperties(ISearchResultEntry entry) var sidHistory = ReadSidHistory(entry); props.Add(PropertyMap.GetPropertyName(LDAPProperties.SIDHistory), sidHistory.ToArray()); - userProps.SidHistory = sidHistory.Select(ssid => ReadSidPrinciple(entry, ssid)).ToArray(); + userProps.SidHistory = sidHistory.Select(ssid => ReadSidPrincipal(entry, ssid)).ToArray(); userProps.Props = props; @@ -161,7 +161,7 @@ public async Task ReadComputerProperties(ISearchResultEntry var sidHistory = ReadSidHistory(entry); props.Add(PropertyMap.GetPropertyName(LDAPProperties.SIDHistory), sidHistory.ToArray()); - compProps.SidHistory = sidHistory.Select(ssid => ReadSidPrinciple(entry, ssid)).ToArray(); + compProps.SidHistory = sidHistory.Select(ssid => ReadSidPrincipal(entry, ssid)).ToArray(); compProps.DumpSMSAPassword = ReadSmsaPrinciples(entry).ToArray(); @@ -237,7 +237,7 @@ public List ReadSidHistory(ISearchResultEntry entry) /// /// /// - public TypedPrincipal ReadSidPrinciple(ISearchResultEntry entry, string sidHistoryItem) + public TypedPrincipal ReadSidPrincipal(ISearchResultEntry entry, string sidHistoryItem) { var domain = Helpers.DistinguishedNameToDomain(entry.DistinguishedName); return _utils.ResolveIDAndType(sidHistoryItem, domain); @@ -803,7 +803,7 @@ public static string GetPropertyName(string ldapProperty) case LDAPProperties.PasswordLastSet: return "pwdlastset"; case LDAPProperties.ServicePrincipalNames: - return "serviceprinciplenames"; + return "serviceprincipalnames"; case LDAPProperties.DisplayName: return "displayname"; case LDAPProperties.Email: diff --git a/test/unit/LDAPPropertyTests.cs b/test/unit/LDAPPropertyTests.cs index a1e9b807..cdc918d0 100644 --- a/test/unit/LDAPPropertyTests.cs +++ b/test/unit/LDAPPropertyTests.cs @@ -876,5 +876,43 @@ public async Task LDAPPropertyProcessor_ReadPropertyDelegates_ReturnsPoplatedLis Assert.Single(delegates, host); } } + + [WindowsOnlyFact] + public void LDAPPropertyProcessor_ReadSidHistory_ReturnsPopulatedList() + { + var mock = new MockSearchResultEntry("CN\u003dWIN10,OU\u003dTestOU,DC\u003dtestlab,DC\u003dlocal", + new Dictionary + { + { + "sidhistory", new[] + { + Helpers.B64ToBytes("AQUAAAAAAAUVAAAAIE+Qun9GhKV2SBaQUQQAAA==") + } + }, + }, "S-1-5-21-3130019616-2776909439-2417379446-1101", Label.Computer); + + var processor = new LDAPPropertyProcessor(new MockLDAPUtils()); + var sids = processor.ReadSidHistory(mock); + + Assert.Contains("S-1-5-21-3130019616-2776909439-2417379446-1105", sids); + Assert.Single(sids); + } + + [Fact] + public void LDAPPropertyProcessor_ReadSidPrincipal_GetPrincipal() + { + var mock = new MockSearchResultEntry("CN\u003dWIN10,OU\u003dTestOU,DC\u003dtestlab,DC\u003dlocal", + new Dictionary(), "S-1-5-21-3130019616-2776909439-2417379446-1101", Label.Computer); + + var sid = "S-1-5-21-3130019616-2776909439-2417379446-1105"; + var processor = new LDAPPropertyProcessor(new MockLDAPUtils()); + var principal = processor.ReadSidPrincipal(mock, sid); + + Assert.Equal(new TypedPrincipal + { + ObjectIdentifier = "S-1-5-21-3130019616-2776909439-2417379446-1105", + ObjectType = Label.User + }, principal); + } } }