-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
147 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
// } | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
// } | ||
// } | ||
// } |