Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rvazarkar committed Oct 4, 2023
1 parent bebdd5b commit ec9191b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
39 changes: 22 additions & 17 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,8 +38,14 @@ public string GetProperty(string propertyName)

public byte[] GetByteProperty(string propertyName)
{
//returning something not null specifically for these properties for the parseAllProperties tests
if (propertyName == "badpasswordtime" || propertyName == "domainsid") return new byte[] { 0x20 };
if (!_properties.Contains(propertyName))
return null;

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

return _properties[propertyName] as byte[];
}

Expand All @@ -48,24 +55,19 @@ public string[] GetArrayProperty(string propertyName)
return Array.Empty<string>();

var value = _properties[propertyName];
Type valueType = value.GetType();

if (valueType.IsArray)
if (value.IsArray())
return value as string[];
else
return new string[1] { (value ?? "").ToString() };

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

public byte[][] GetByteArrayProperty(string propertyName)
{

if (!_properties.Contains(propertyName))
return Array.Empty<byte[]>();

var byteArray = new byte[] { 0x20 };
var byteArrayArray = new byte[][] { byteArray };

return byteArrayArray;

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

public bool GetIntProperty(string propertyName, out int value)
Expand Down Expand Up @@ -106,11 +108,14 @@ public string GetGuid()

public int PropCount(string prop)
{
var count = 0;

foreach (var property in _properties) count++;
var property = _properties[prop];
if (property.IsArray())
{
var cast = property as string[];
return cast?.Length ?? 0;
}

return count;
return 1;
}

public IEnumerable<string> PropertyNames()
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

0 comments on commit ec9191b

Please sign in to comment.