Skip to content

Commit

Permalink
Merge pull request #74 from BloodHoundAD/improve-coverage
Browse files Browse the repository at this point in the history
chore: improve test coverage
  • Loading branch information
urangel authored Oct 4, 2023
2 parents 90cbb09 + ec9191b commit a7ec97a
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 85 deletions.
13 changes: 6 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Build

``` powershell
```powershell
dotnet build
```

Expand All @@ -17,31 +17,30 @@ dotnet build
This project is configured to generate test coverage every time tests are run and produces a HTML report at
[./docfx/coverage/report](./docfx/coverage/report).


``` powershell
```powershell
dotnet test
```

## Documentation

Documentation is generated into Html from Markdown using [docfx](https://https://dotnet.github.io/docfx/).
Documentation is generated into HTML from Markdown using [docfx](https://dotnet.github.io/docfx/).

To build the docs:

``` powershell
```powershell
dotnet build docfx
```

To preview the docs:

``` powershell
```powershell
dotnet build docfx
dotnet build docfx -t:Serve
```

To preview the docs with test coverage:

``` powershell
```powershell
dotnet test
dotnet build docfx
dotnet build docfx -t:Serve
Expand Down
14 changes: 12 additions & 2 deletions src/CommonLib/Processors/LDAPPropertyProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,12 @@ public static Dictionary<string, object> ReadEnrollmentServiceProperties(ISearch
}
public static Dictionary<string, object> ReadNTAuthStoreProperties(ISearchResultEntry entry)
{
var props = GetCommonProps(entry);
return props;
var ntAuthStoreProps = new NTAuthStoreProperties
{
Props = GetCommonProps(entry)
};

return ntAuthStoreProps.Props;
}

public static Dictionary<string, object> ReadCertTemplateProperties(ISearchResultEntry entry)
Expand Down Expand Up @@ -638,4 +642,10 @@ public class ComputerProperties
public TypedPrincipal[] SidHistory { get; set; } = Array.Empty<TypedPrincipal>();
public TypedPrincipal[] DumpSMSAPassword { get; set; } = Array.Empty<TypedPrincipal>();
}

public class NTAuthStoreProperties
{
public Dictionary<string, object> Props { get; set; } = new();
public TypedPrincipal[] CertThumbprints { get; set; } = Array.Empty<TypedPrincipal>();
}
}
53 changes: 26 additions & 27 deletions test/unit/ACLProcessorTest.cs

Large diffs are not rendered by default.

37 changes: 32 additions & 5 deletions test/unit/Facades/MockSearchResultEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using SharpHoundCommonLib;
using SharpHoundCommonLib.Enums;

Expand Down Expand Up @@ -37,22 +38,41 @@ public string GetProperty(string propertyName)

public byte[] GetByteProperty(string propertyName)
{
if (!_properties.Contains(propertyName))
return null;

if (_properties[propertyName] is string prop)
{
return Encoding.ASCII.GetBytes(prop);
}

return _properties[propertyName] as byte[];
}

public string[] GetArrayProperty(string propertyName)
{
return _properties[propertyName] as string[];
if (!_properties.Contains(propertyName))
return Array.Empty<string>();

var value = _properties[propertyName];
if (value.IsArray())
return value as string[];

return new [] { (value ?? "").ToString() };
}

public byte[][] GetByteArrayProperty(string propertyName)
{
return _properties[propertyName] as byte[][];
if (!_properties.Contains(propertyName))
return Array.Empty<byte[]>();

var property = _properties[propertyName] as byte[][];
return property;
}

public bool GetIntProperty(string propertyName, out int value)
{
value = _properties[propertyName] is int ? (int) _properties[propertyName] : 0;
value = _properties[propertyName] is int ? (int)_properties[propertyName] : 0;
return true;
}

Expand Down Expand Up @@ -88,12 +108,19 @@ public string GetGuid()

public int PropCount(string prop)
{
throw new NotImplementedException();
var property = _properties[prop];
if (property.IsArray())
{
var cast = property as string[];
return cast?.Length ?? 0;
}

return 1;
}

public IEnumerable<string> PropertyNames()
{
throw new NotImplementedException();
foreach (var property in _properties.Keys) yield return property.ToString().ToLower();
}

public bool IsMSA()
Expand Down
8 changes: 8 additions & 0 deletions test/unit/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ internal static async Task<T[]> ToArrayAsync<T>(this IAsyncEnumerable<T> items,
results.Add(item);
return results.ToArray();
}

internal static bool IsArray(this object obj)
{
var valueType = obj?.GetType();
if (valueType == null)
return false;
return valueType.IsArray;
}
}

public sealed class WindowsOnlyFact : FactAttribute
Expand Down
Loading

0 comments on commit a7ec97a

Please sign in to comment.