< Summary

Class:SharpHoundCommonLib.DirectoryObjects.DirectoryObjectExtensions
Assembly:SharpHoundCommonLib
File(s):D:\a\SharpHoundCommon\SharpHoundCommon\src\CommonLib\DirectoryObjects\DirectoryObjectExtensions.cs
Covered lines:42
Uncovered lines:0
Coverable lines:42
Total lines:71
Line coverage:100% (42 of 42)
Covered branches:22
Total branches:24
Branch coverage:91.6% (22 of 24)

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
IsMSA(...)100%20100%
IsGMSA(...)100%20100%
GetObjectIdentifier(...)66.66%60100%
GetLabel(...)100%40100%
IsDeleted(...)100%20100%
HasLAPS(...)100%80100%

File(s)

D:\a\SharpHoundCommon\SharpHoundCommon\src\CommonLib\DirectoryObjects\DirectoryObjectExtensions.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using SharpHoundCommonLib.Enums;
 4
 5namespace SharpHoundCommonLib.DirectoryObjects;
 6
 7public static class DirectoryObjectExtensions {
 128    public static bool IsMSA(this IDirectoryObject directoryObject) {
 199        if (!directoryObject.TryGetArrayProperty(LDAPProperties.ObjectClass, out var classes)) {
 710            return false;
 11        }
 12
 513        return classes.Contains(ObjectClass.MSAClass, StringComparer.InvariantCultureIgnoreCase);
 1214    }
 15
 1116    public static bool IsGMSA(this IDirectoryObject directoryObject) {
 1817        if (!directoryObject.TryGetArrayProperty(LDAPProperties.ObjectClass, out var classes)) {
 718            return false;
 19        }
 20
 421        return classes.Contains(ObjectClass.GMSAClass, StringComparer.InvariantCultureIgnoreCase);
 1122    }
 23
 3924    public static bool GetObjectIdentifier(this IDirectoryObject directoryObject, out string objectIdentifier) {
 7225        if (directoryObject.TryGetSecurityIdentifier(out objectIdentifier) && !string.IsNullOrWhiteSpace(objectIdentifie
 3326            return true;
 27        }
 28
 629        return directoryObject.TryGetGuid(out objectIdentifier) && !string.IsNullOrWhiteSpace(objectIdentifier);
 3930    }
 31
 2832    public static bool GetLabel(this IDirectoryObject directoryObject, out Label type) {
 2833        type = Label.Base;
 2934        if (!directoryObject.GetObjectIdentifier(out var objectIdentifier)) {
 135            return false;
 36        }
 37
 4838        if (!directoryObject.TryGetLongProperty(LDAPProperties.Flags, out var flags)) {
 2139            flags = 0;
 2140        }
 41
 2742        directoryObject.TryGetDistinguishedName(out var distinguishedName);
 2743        directoryObject.TryGetProperty(LDAPProperties.SAMAccountType, out var samAccountType);
 2744        directoryObject.TryGetArrayProperty(LDAPProperties.ObjectClass, out var objectClasses);
 45
 2746        return LdapUtils.ResolveLabel(objectIdentifier, distinguishedName, samAccountType, objectClasses, (int)flags,
 2747            out type);
 2848    }
 49
 1050    public static bool IsDeleted(this IDirectoryObject directoryObject) {
 1851        if (!directoryObject.TryGetProperty(LDAPProperties.IsDeleted, out var deleted)) {
 852            return false;
 53        }
 54
 255        return bool.TryParse(deleted, out var isDeleted) && isDeleted;
 1056    }
 57
 358    public static bool HasLAPS(this IDirectoryObject directoryObject) {
 359        if (directoryObject.TryGetLongProperty(LDAPProperties.LAPSExpirationTime, out var lapsExpiration) &&
 460            lapsExpiration > 0) {
 161            return true;
 62        }
 63
 264        if (directoryObject.TryGetLongProperty(LDAPProperties.LegacyLAPSExpirationTime, out var legacyLapsExpiration) &&
 365            legacyLapsExpiration > 0) {
 166            return true;
 67        }
 68
 169        return false;
 370    }
 71}