Skip to content

Commit

Permalink
Publish v15 (#160)
Browse files Browse the repository at this point in the history
* Augmentation is now enabled by default on a new LDAP connection, when it is added through the UI
* Augment groups with the same attribute as the one set in the LDAPCP configuration. #148
* Fix: In claims configurfation page, the values in the list of "PickerEntity metadata" was not populated correctly, which caused an issue with the "Title" (and a few others)
* Update NuGet package NUnit3TestAdapter to v3.16.1
* Update NuGet package Newtonsoft.Json to 12.0.3
  • Loading branch information
Yvand authored Apr 21, 2022
1 parent c0670eb commit 43b7723
Show file tree
Hide file tree
Showing 19 changed files with 248 additions and 602 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change log for LDAPCP

## Unreleased

* Augmentation is now enabled by default on a new LDAP connection, when it is added through the UI
* Augment groups with the same attribute as the one set in the LDAPCP configuration. https://github.com/Yvand/LDAPCP/issues/148
* Fix: In claims configurfation page, the values in the list of "PickerEntity metadata" was not populated correctly, which caused an issue with the "Title" (and a few others)
* Update NuGet package NUnit3TestAdapter to v3.16.1
* Update NuGet package Newtonsoft.Json to 12.0.3

## LDAPCP 14.1.20191007.981 enhancements & bug-fixes - Published in October 7, 2019

* Fix regression: after installing v14, users are stuck in SharePoint just after sign-in to ADFS. https://github.com/Yvand/LDAPCP/issues/99
Expand Down
123 changes: 0 additions & 123 deletions DevOps-RunTests.yml

This file was deleted.

2 changes: 2 additions & 0 deletions LDAPCP.Tests/BackupCurrentConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class BackupCurrentConfig
[OneTimeSetUp]
public void Init()
{
Trace.WriteLine($"{DateTime.Now.ToString("s")} Start backup of current LDAPCP configuration");
Config = LDAPCPConfig.GetConfiguration(UnitTestsHelper.ClaimsProviderConfigName, UnitTestsHelper.SPTrust.Name);
if (Config == null)
{
Expand All @@ -39,6 +40,7 @@ public void Cleanup()
{
Config.ApplyConfiguration(BackupConfig);
Config.Update();
Trace.WriteLine($"{DateTime.Now.ToString("s")} Restored original settings of LDAPCP configuration");
}
}
}
8 changes: 5 additions & 3 deletions LDAPCP.Tests/LDAPCP.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@
<Version>1.0.12</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.2</Version>
<Version>13.0.1</Version>
</PackageReference>
<PackageReference Include="NUnit">
<Version>3.12.0</Version>
<Version>3.13.3</Version>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter">
<Version>3.13.0</Version>
<Version>4.2.1</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions LDAPCP.Tests/ModifyConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ public void DuplicateClaimType()

// Modify an existing claim type to set a claim type already defined should throw exception InvalidOperationException
var anotherCTConfig = Config.ClaimTypes.FirstOrDefault(x => !String.IsNullOrEmpty(x.ClaimType) && !String.Equals(firstCTConfig.ClaimType, x.ClaimType, StringComparison.InvariantCultureIgnoreCase));
string backupClaimType = anotherCTConfig.ClaimType;
anotherCTConfig.ClaimType = firstCTConfig.ClaimType;
Assert.Throws<InvalidOperationException>(() => Config.Update(), $"Modify an existing claim type to set a claim type already defined should throw exception InvalidOperationException with this message: \"{ConfigUpdateErrorMessage}\"");
anotherCTConfig.ClaimType = backupClaimType; // Revert the change to continue with a clean config
}

[Test]
Expand Down
101 changes: 65 additions & 36 deletions LDAPCP.Tests/UnitTestsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,19 @@ public class UnitTestsHelper
[OneTimeSetUp]
public static void InitializeSiteCollection()
{
#if DEBUG
TestSiteCollUri = new Uri("http://spsites/sites/" + TestContext.Parameters["TestSiteCollectionName"]);
return; // Uncommented when debugging LDAPCP code from unit tests
#endif

logFileListener = new TextWriterTraceListener(TestContext.Parameters["TestLogFileName"]);
Trace.Listeners.Add(logFileListener);
Trace.AutoFlush = true;
Trace.TraceInformation($"{DateTime.Now.ToString("s")} Start integration tests of {ClaimsProviderName} {FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(typeof(ldapcp.LDAPCP)).Location).FileVersion}.");
Trace.WriteLine($"{DateTime.Now.ToString("s")} DataFile_AllAccounts_Search: {DataFile_AllAccounts_Search}");
Trace.WriteLine($"{DateTime.Now.ToString("s")} DataFile_AllAccounts_Validate: {DataFile_AllAccounts_Validate}");
Trace.WriteLine($"{DateTime.Now.ToString("s")} TestSiteCollectionName: {TestContext.Parameters["TestSiteCollectionName"]}");

#if DEBUG
TestSiteCollUri = new Uri("http://spsites/sites/" + TestContext.Parameters["TestSiteCollectionName"]);
//return; // Uncommented when debugging LDAPCP code from unit tests
#endif

if (SPTrust == null)
{
Trace.TraceError($"{DateTime.Now.ToString("s")} SPTrust: is null");
Expand Down Expand Up @@ -127,7 +128,6 @@ public static void InitializeSiteCollection()
{
Trace.TraceError($"{DateTime.Now.ToString("s")} Web application was NOT found.");
}

}

[OneTimeTearDown]
Expand Down Expand Up @@ -160,18 +160,29 @@ public static void InitializeConfiguration(LDAPCPConfig config)
/// <param name="expectedClaimValue"></param>
public static void TestSearchOperation(string inputValue, int expectedCount, string expectedClaimValue)
{
string[] entityTypes = new string[] { "User", "SecGroup", "SharePointGroup", "System", "FormsRole" };
try
{
Stopwatch timer = new Stopwatch();
timer.Start();
string[] entityTypes = new string[] { "User", "SecGroup", "SharePointGroup", "System", "FormsRole" };

SPProviderHierarchyTree providerResults = ClaimsProvider.Search(TestSiteCollUri, entityTypes, inputValue, null, 30);
List<PickerEntity> entities = new List<PickerEntity>();
foreach (var children in providerResults.Children)
{
entities.AddRange(children.EntityData);
}
VerifySearchTest(entities, inputValue, expectedCount, expectedClaimValue);

SPProviderHierarchyTree providerResults = ClaimsProvider.Search(TestSiteCollUri, entityTypes, inputValue, null, 30);
List<PickerEntity> entities = new List<PickerEntity>();
foreach (var children in providerResults.Children)
entities = ClaimsProvider.Resolve(TestSiteCollUri, entityTypes, inputValue).ToList();
VerifySearchTest(entities, inputValue, expectedCount, expectedClaimValue);
timer.Stop();
Trace.WriteLine($"{DateTime.Now.ToString("s")} TestSearchOperation finished in {timer.ElapsedMilliseconds} ms. Parameters: inputValue: '{inputValue}', expectedCount: '{expectedCount}', expectedClaimValue: '{expectedClaimValue}'.");
}
catch (Exception ex)
{
entities.AddRange(children.EntityData);
Trace.TraceError($"{DateTime.Now.ToString("s")} TestSearchOperation failed with exception '{ex.GetType()}', message '{ex.Message}'. Parameters: inputValue: '{inputValue}', expectedCount: '{expectedCount}', expectedClaimValue: '{expectedClaimValue}'.");
}
VerifySearchTest(entities, inputValue, expectedCount, expectedClaimValue);

entities = ClaimsProvider.Resolve(TestSiteCollUri, entityTypes, inputValue).ToList();
VerifySearchTest(entities, inputValue, expectedCount, expectedClaimValue);
}

public static void VerifySearchTest(List<PickerEntity> entities, string input, int expectedCount, string expectedClaimValue)
Expand Down Expand Up @@ -203,42 +214,60 @@ public static void VerifySearchTest(List<PickerEntity> entities, string input, i

public static void TestValidationOperation(SPClaim inputClaim, bool shouldValidate, string expectedClaimValue)
{
string[] entityTypes = new string[] { "User" };
try
{
Stopwatch timer = new Stopwatch();
timer.Start();
var entityTypes = new[] { "User" };

PickerEntity[] entities = ClaimsProvider.Resolve(TestSiteCollUri, entityTypes, inputClaim);
PickerEntity[] entities = ClaimsProvider.Resolve(TestSiteCollUri, entityTypes, inputClaim);

int expectedCount = shouldValidate ? 1 : 0;
Assert.AreEqual(expectedCount, entities.Length, $"Validation of entity \"{inputClaim.Value}\" should have returned {expectedCount} entity, but it returned {entities.Length} instead.");
if (shouldValidate)
int expectedCount = shouldValidate ? 1 : 0;
Assert.AreEqual(expectedCount, entities.Length, $"Validation of entity \"{inputClaim.Value}\" should have returned {expectedCount} entity, but it returned {entities.Length} instead.");
if (shouldValidate)
{
StringAssert.AreEqualIgnoringCase(expectedClaimValue, entities[0].Claim.Value, $"Validation of entity \"{inputClaim.Value}\" should have returned value \"{expectedClaimValue}\", but it returned \"{entities[0].Claim.Value}\" instead.");
}
timer.Stop();
Trace.WriteLine($"{DateTime.Now.ToString("s")} TestValidationOperation finished in {timer.ElapsedMilliseconds} ms. Parameters: inputClaim.Value: '{inputClaim.Value}', shouldValidate: '{shouldValidate}', expectedClaimValue: '{expectedClaimValue}'.");
}
catch (Exception ex)
{
StringAssert.AreEqualIgnoringCase(expectedClaimValue, entities[0].Claim.Value, $"Validation of entity \"{inputClaim.Value}\" should have returned value \"{expectedClaimValue}\", but it returned \"{entities[0].Claim.Value}\" instead.");
Trace.TraceError($"{DateTime.Now.ToString("s")} TestValidationOperation failed with exception '{ex.GetType()}', message '{ex.Message}'. Parameters: inputClaim.Value: '{inputClaim.Value}', shouldValidate: '{shouldValidate}', expectedClaimValue: '{expectedClaimValue}'.");
}
}

public static void TestAugmentationOperation(string claimType, string claimValue, bool isMemberOfTrustedGroup)
{
SPClaim inputClaim = new SPClaim(claimType, claimValue, ClaimValueTypes.String, SPOriginalIssuers.Format(SPOriginalIssuerType.TrustedProvider, UnitTestsHelper.SPTrust.Name));
Uri context = new Uri(TestSiteCollUri.AbsoluteUri);
SPClaim[] groups = ClaimsProvider.GetClaimsForEntity(context, inputClaim);
bool groupFound = false;
string groupsValueText = "No group was returned by the claims provider.";

if (groups != null && groups.Count() > 0)
try
{
groupsValueText = $"Claims provider returned those {groups.Count()} groups: {string.Join(", ", Array.ConvertAll(groups, x => x.Value))}";
if (groups.Contains(TrustedGroup))
Stopwatch timer = new Stopwatch();
timer.Start();
SPClaim inputClaim = new SPClaim(claimType, claimValue, ClaimValueTypes.String, SPOriginalIssuers.Format(SPOriginalIssuerType.TrustedProvider, UnitTestsHelper.SPTrust.Name));
Uri context = new Uri(UnitTestsHelper.TestSiteCollUri.AbsoluteUri);

SPClaim[] groups = ClaimsProvider.GetClaimsForEntity(context, inputClaim);

bool groupFound = false;
if (groups != null && groups.Contains(TrustedGroup))
{
groupFound = true;
}
}

if (isMemberOfTrustedGroup)
{
Assert.IsTrue(groupFound, $"Entity \"{claimValue}\" should be member of group \"{TrustedGroupToAdd_ClaimValue}\", but this group was not found in the claims returned by the claims provider. {groupsValueText}");
if (isMemberOfTrustedGroup)
{
Assert.IsTrue(groupFound, $"Entity \"{claimValue}\" should be member of group \"{TrustedGroupToAdd_ClaimValue}\", but this group was not found in the claims returned by the claims provider.");
}
else
{
Assert.IsFalse(groupFound, $"Entity \"{claimValue}\" should NOT be member of group \"{TrustedGroupToAdd_ClaimValue}\", but this group was found in the claims returned by the claims provider.");
}
timer.Stop();
Trace.WriteLine($"{DateTime.Now.ToString("s")} TestAugmentationOperation finished in {timer.ElapsedMilliseconds} ms. Parameters: claimType: '{claimType}', claimValue: '{claimValue}', isMemberOfTrustedGroup: '{isMemberOfTrustedGroup}'.");
}
else
catch (Exception ex)
{
Assert.IsFalse(groupFound, $"Entity \"{claimValue}\" should NOT be member of group \"{TrustedGroupToAdd_ClaimValue}\", but this group was found in the claims returned by the claims provider. {groupsValueText}");
Trace.TraceError($"{DateTime.Now.ToString("s")} TestAugmentationOperation failed with exception '{ex.GetType()}', message '{ex.Message}'. Parameters: claimType: '{claimType}', claimValue: '{claimValue}', isMemberOfTrustedGroup: '{isMemberOfTrustedGroup}'.");
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion LDAPCP/ADMIN/LDAPCP/ClaimTypesConfig.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ private void Initialize()
Type EntityDataKeysInfo = typeof(PeopleEditorEntityDataKeys);
foreach (object field in EntityDataKeysInfo.GetFields())
{
DdlNewEntityMetadata.Items.Add(((FieldInfo)field).Name);
FieldInfo fi = (FieldInfo)field;
object fieldValue = fi.GetValue(null);
DdlNewEntityMetadata.Items.Add(fieldValue.ToString());
}

// Populate EntityType DDL
Expand Down
2 changes: 1 addition & 1 deletion LDAPCP/ADMIN/LDAPCP/ClaimTypesConfig.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Claim types configuration for LDAPCP
</asp:Content>
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server">
<%= String.Format("LDAPCP v{0} - <a href=\"{1}\" target=\"_blank\">LDAPCP.com</a>", FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(typeof(LDAPCP)).Location).FileVersion, ClaimsProviderConstants.PUBLICSITEURL) %>
<%= String.Format("LDAPCP {0} - <a href=\"{1}\" target=\"_blank\">LDAPCP.com</a>", FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(typeof(LDAPCP)).Location).FileVersion, ClaimsProviderConstants.PUBLICSITEURL) %>
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
Expand Down
Loading

0 comments on commit 43b7723

Please sign in to comment.