Skip to content

Commit

Permalink
wip: break more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rvazarkar committed Jul 8, 2024
1 parent 0e9aa08 commit de7bcf8
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 147 deletions.
8 changes: 4 additions & 4 deletions test/unit/CommonLibHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ public void ConvertFileTimeToUnixEpoch_Null_NegativeOne()
Assert.Equal(-1, result);
}

[WindowsOnlyFact]
[Fact]
public void ConvertFileTimeToUnixEpoch_WrongFormat_FortmatException()
{
Exception ex =
Assert.Throws<FormatException>(() => SharpHoundCommonLib.Helpers.ConvertFileTimeToUnixEpoch("asdsf"));
Assert.Equal("Input string was not in a correct format.", ex.Message);
Assert.Equal("The input string 'asdsf' was not in a correct format.", ex.Message);
}

[Fact]
Expand All @@ -229,12 +229,12 @@ public void ConvertTimestampToUnixEpoch_ValidTimestamp_ValidUnixEpoch()
Assert.Equal(d.ToUniversalTime().Date, testDate);
}

[WindowsOnlyFact]
[Fact]
public void ConvertTimestampToUnixEpoch_InvalidTimestamp_FormatException()
{
Exception ex = Assert.Throws<FormatException>(() =>
SharpHoundCommonLib.Helpers.ConvertFileTimeToUnixEpoch("-201adsfasf12180244"));
Assert.Equal("Input string was not in a correct format.", ex.Message);
Assert.Equal("The input string '-201adsfasf12180244' was not in a correct format.", ex.Message);
}
}
}
214 changes: 107 additions & 107 deletions test/unit/SPNProcessorsTest.cs
Original file line number Diff line number Diff line change
@@ -1,107 +1,107 @@
using System;
using System.Threading.Tasks;
using CommonLibTest.Facades;
using SharpHoundCommonLib;
using SharpHoundCommonLib.Enums;
using SharpHoundCommonLib.OutputTypes;
using SharpHoundCommonLib.Processors;
using Xunit;

namespace CommonLibTest
{
public class SPNProcessorsTest
{
[Fact]
public async Task ReadSPNTargets_SPNLengthZero_YieldBreak()
{
var processor = new SPNProcessors(new MockLDAPUtils());
var servicePrincipalNames = Array.Empty<string>();
const string distinguishedName = "cn=policies,cn=system,DC=testlab,DC=local";
await foreach (var spn in processor.ReadSPNTargets(servicePrincipalNames, distinguishedName))
Assert.Null(spn);
}

[Fact]
public async Task ReadSPNTargets_NoPortSupplied_ParsedCorrectly()
{
var processor = new SPNProcessors(new MockLDAPUtils());
string[] servicePrincipalNames = {"MSSQLSvc/PRIMARY.TESTLAB.LOCAL"};
const string distinguishedName = "cn=policies,cn=system,DC=testlab,DC=local";

var expected = new SPNPrivilege
{
ComputerSID = "S-1-5-21-3130019616-2776909439-2417379446-1001", Port = 1433,
Service = EdgeNames.SQLAdmin
};

await foreach (var actual in processor.ReadSPNTargets(servicePrincipalNames, distinguishedName))
{
Assert.Equal(expected.ComputerSID, actual.ComputerSID);
Assert.Equal(expected.Port, actual.Port);
Assert.Equal(expected.Service, actual.Service);
}
}

[Fact]
public async Task ReadSPNTargets_BadPortSupplied_ParsedCorrectly()
{
var processor = new SPNProcessors(new MockLDAPUtils());
string[] servicePrincipalNames = {"MSSQLSvc/PRIMARY.TESTLAB.LOCAL:abcd"};
const string distinguishedName = "cn=policies,cn=system,DC=testlab,DC=local";

var expected = new SPNPrivilege
{
ComputerSID = "S-1-5-21-3130019616-2776909439-2417379446-1001", Port = 1433,
Service = EdgeNames.SQLAdmin
};

await foreach (var actual in processor.ReadSPNTargets(servicePrincipalNames, distinguishedName))
{
Assert.Equal(expected.ComputerSID, actual.ComputerSID);
Assert.Equal(expected.Port, actual.Port);
Assert.Equal(expected.Service, actual.Service);
}
}

[Fact]
public async void ReadSPNTargets_SuppliedPort_ParsedCorrectly()
{
var processor = new SPNProcessors(new MockLDAPUtils());
string[] servicePrincipalNames = {"MSSQLSvc/PRIMARY.TESTLAB.LOCAL:2345"};
const string distinguishedName = "cn=policies,cn=system,DC=testlab,DC=local";

var expected = new SPNPrivilege
{
ComputerSID = "S-1-5-21-3130019616-2776909439-2417379446-1001", Port = 2345,
Service = EdgeNames.SQLAdmin
};

await foreach (var actual in processor.ReadSPNTargets(servicePrincipalNames, distinguishedName))
{
Assert.Equal(expected.ComputerSID, actual.ComputerSID);
Assert.Equal(expected.Port, actual.Port);
Assert.Equal(expected.Service, actual.Service);
}
}

[Fact]
public async void ReadSPNTargets_MissingMssqlSvc_NotRead()
{
var processor = new SPNProcessors(new MockLDAPUtils());
string[] servicePrincipalNames = {"myhost.redmond.microsoft.com:1433"};
const string distinguishedName = "CN=Jeff Smith,OU=Sales,DC=Fabrikam,DC=COM";
await foreach (var spn in processor.ReadSPNTargets(servicePrincipalNames, distinguishedName))
Assert.Null(spn);
}

[Fact]
public async void ReadSPNTargets_SPNWithAddressSign_NotRead()
{
var processor = new SPNProcessors(new MockLDAPUtils());
string[] servicePrincipalNames = {"MSSQLSvc/myhost.redmond.microsoft.com:1433 user@domain"};
const string distinguishedName = "CN=Jeff Smith,OU=Sales,DC=Fabrikam,DC=COM";
await foreach (var spn in processor.ReadSPNTargets(servicePrincipalNames, distinguishedName))
Assert.Null(spn);
}
}
}
// using System;
// using System.Threading.Tasks;
// using CommonLibTest.Facades;
// using SharpHoundCommonLib;
// using SharpHoundCommonLib.Enums;
// using SharpHoundCommonLib.OutputTypes;
// using SharpHoundCommonLib.Processors;
// using Xunit;
//
// namespace CommonLibTest
// {
// public class SPNProcessorsTest
// {
// [Fact]
// public async Task ReadSPNTargets_SPNLengthZero_YieldBreak()
// {
// var processor = new SPNProcessors(new MockLDAPUtils());
// var servicePrincipalNames = Array.Empty<string>();
// const string distinguishedName = "cn=policies,cn=system,DC=testlab,DC=local";
// await foreach (var spn in processor.ReadSPNTargets(servicePrincipalNames, distinguishedName))
// Assert.Null(spn);
// }
//
// [Fact]
// public async Task ReadSPNTargets_NoPortSupplied_ParsedCorrectly()
// {
// var processor = new SPNProcessors(new MockLDAPUtils());
// string[] servicePrincipalNames = {"MSSQLSvc/PRIMARY.TESTLAB.LOCAL"};
// const string distinguishedName = "cn=policies,cn=system,DC=testlab,DC=local";
//
// var expected = new SPNPrivilege
// {
// ComputerSID = "S-1-5-21-3130019616-2776909439-2417379446-1001", Port = 1433,
// Service = EdgeNames.SQLAdmin
// };
//
// await foreach (var actual in processor.ReadSPNTargets(servicePrincipalNames, distinguishedName))
// {
// Assert.Equal(expected.ComputerSID, actual.ComputerSID);
// Assert.Equal(expected.Port, actual.Port);
// Assert.Equal(expected.Service, actual.Service);
// }
// }
//
// [Fact]
// public async Task ReadSPNTargets_BadPortSupplied_ParsedCorrectly()
// {
// var processor = new SPNProcessors(new MockLDAPUtils());
// string[] servicePrincipalNames = {"MSSQLSvc/PRIMARY.TESTLAB.LOCAL:abcd"};
// const string distinguishedName = "cn=policies,cn=system,DC=testlab,DC=local";
//
// var expected = new SPNPrivilege
// {
// ComputerSID = "S-1-5-21-3130019616-2776909439-2417379446-1001", Port = 1433,
// Service = EdgeNames.SQLAdmin
// };
//
// await foreach (var actual in processor.ReadSPNTargets(servicePrincipalNames, distinguishedName))
// {
// Assert.Equal(expected.ComputerSID, actual.ComputerSID);
// Assert.Equal(expected.Port, actual.Port);
// Assert.Equal(expected.Service, actual.Service);
// }
// }
//
// [Fact]
// public async void ReadSPNTargets_SuppliedPort_ParsedCorrectly()
// {
// var processor = new SPNProcessors(new MockLDAPUtils());
// string[] servicePrincipalNames = {"MSSQLSvc/PRIMARY.TESTLAB.LOCAL:2345"};
// const string distinguishedName = "cn=policies,cn=system,DC=testlab,DC=local";
//
// var expected = new SPNPrivilege
// {
// ComputerSID = "S-1-5-21-3130019616-2776909439-2417379446-1001", Port = 2345,
// Service = EdgeNames.SQLAdmin
// };
//
// await foreach (var actual in processor.ReadSPNTargets(servicePrincipalNames, distinguishedName))
// {
// Assert.Equal(expected.ComputerSID, actual.ComputerSID);
// Assert.Equal(expected.Port, actual.Port);
// Assert.Equal(expected.Service, actual.Service);
// }
// }
//
// [Fact]
// public async void ReadSPNTargets_MissingMssqlSvc_NotRead()
// {
// var processor = new SPNProcessors(new MockLDAPUtils());
// string[] servicePrincipalNames = {"myhost.redmond.microsoft.com:1433"};
// const string distinguishedName = "CN=Jeff Smith,OU=Sales,DC=Fabrikam,DC=COM";
// await foreach (var spn in processor.ReadSPNTargets(servicePrincipalNames, distinguishedName))
// Assert.Null(spn);
// }
//
// [Fact]
// public async void ReadSPNTargets_SPNWithAddressSign_NotRead()
// {
// var processor = new SPNProcessors(new MockLDAPUtils());
// string[] servicePrincipalNames = {"MSSQLSvc/myhost.redmond.microsoft.com:1433 user@domain"};
// const string distinguishedName = "CN=Jeff Smith,OU=Sales,DC=Fabrikam,DC=COM";
// await foreach (var spn in processor.ReadSPNTargets(servicePrincipalNames, distinguishedName))
// Assert.Null(spn);
// }
// }
// }
72 changes: 36 additions & 36 deletions test/unit/SearchResultEntryTests.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
using System.Collections.Generic;
using System.Security.Principal;
using CommonLibTest.Facades;
using SharpHoundCommonLib;
using SharpHoundCommonLib.Enums;
using Xunit;

namespace CommonLibTest
{
public class SearchResultEntryTests
{
[WindowsOnlyFact]
public void Test_GetLabelIssuanceOIDObjects()
{
var sid = new SecurityIdentifier("S-1-5-21-3130019616-2776909439-2417379446-500");
var bsid = new byte[sid.BinaryLength];
sid.GetBinaryForm(bsid, 0);
var attribs = new Dictionary<string, object>
{
{ "objectsid", bsid},
{ "objectclass", "msPKI-Enterprise-Oid" },
{ "flags", "2" }
};

var sre = MockableSearchResultEntry.Construct(attribs, "CN=Test,CN=OID,CN=Public Key Services,CN=Services,CN=Configuration");
var success = sre.GetLabel(out var label);
Assert.True(success);
Assert.Equal(Label.IssuancePolicy, label);

sre = MockableSearchResultEntry.Construct(attribs, "CN=OID,CN=Public Key Services,CN=Services,CN=Configuration");
success = sre.GetLabel(out label);
Assert.True(success);
Assert.Equal(Label.Container, label);
}
}
}
// using System.Collections.Generic;
// using System.Security.Principal;
// using CommonLibTest.Facades;
// using SharpHoundCommonLib;
// using SharpHoundCommonLib.Enums;
// using Xunit;
//
// namespace CommonLibTest
// {
// public class SearchResultEntryTests
// {
// [WindowsOnlyFact]
// public void Test_GetLabelIssuanceOIDObjects()
// {
// var sid = new SecurityIdentifier("S-1-5-21-3130019616-2776909439-2417379446-500");
// var bsid = new byte[sid.BinaryLength];
// sid.GetBinaryForm(bsid, 0);
// var attribs = new Dictionary<string, object>
// {
// { "objectsid", bsid},
// { "objectclass", "msPKI-Enterprise-Oid" },
// { "flags", "2" }
// };
//
// var sre = MockableSearchResultEntry.Construct(attribs, "CN=Test,CN=OID,CN=Public Key Services,CN=Services,CN=Configuration");
// var success = sre.GetLabel(out var label);
// Assert.True(success);
// Assert.Equal(Label.IssuancePolicy, label);
//
// sre = MockableSearchResultEntry.Construct(attribs, "CN=OID,CN=Public Key Services,CN=Services,CN=Configuration");
// success = sre.GetLabel(out label);
// Assert.True(success);
// Assert.Equal(Label.Container, label);
// }
// }
// }

0 comments on commit de7bcf8

Please sign in to comment.