Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests #276

Merged
merged 10 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Yvand.EntraCP.Tests/BasicConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public override void CheckSettingsTest()
base.CheckSettingsTest();
}

[Test, TestCaseSource(typeof(EntraIdTestGroupsSource), nameof(EntraIdTestGroupsSource.GetSomeGroups), new object[] { true, UnitTestsHelper.MaxNumberOfGroupsToTest })]
public void TestGroups(EntraIdTestGroup group)
[Test, TestCaseSource(typeof(TestEntitySourceManager), nameof(TestEntitySourceManager.GetSomeGroups), new object[] { TestEntitySourceManager.MaxNumberOfGroupsToTest, true })]
public void TestGroups(TestGroup group)
{
TestSearchAndValidateForEntraIDGroup(group);
}
Expand All @@ -33,8 +33,8 @@ public void TestGroups(EntraIdTestGroup group)
// TestSearchAndValidateForEntraIDGroup(group);
//}

[Test, TestCaseSource(typeof(EntraIdTestUsersSource), nameof(EntraIdTestUsersSource.GetSomeUsers), new object[] { UnitTestsHelper.MaxNumberOfUsersToTest })]
public void TestUsers(EntraIdTestUser user)
[Test, TestCaseSource(typeof(TestEntitySourceManager), nameof(TestEntitySourceManager.GetSomeUsers), new object[] { TestEntitySourceManager.MaxNumberOfUsersToTest })]
public void TestUsers(TestUser user)
{
base.TestSearchAndValidateForEntraIDUser(user);
}
Expand All @@ -58,7 +58,7 @@ public override void TestAugmentationOfGoldUsersAgainstRandomGroups()
[TestCase("testEntraCPUser_020")]
public void DebugTestUser(string upnPrefix)
{
EntraIdTestUser user = EntraIdTestUsersSource.Users.Find(x => x.UserPrincipalName.StartsWith(upnPrefix));
TestUser user = TestEntitySourceManager.AllTestUsers.First(x => x.UserPrincipalName.StartsWith(upnPrefix));
base.TestSearchAndValidateForEntraIDUser(user);
}

Expand Down
16 changes: 8 additions & 8 deletions Yvand.EntraCP.Tests/BypassDirectoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public override void CheckSettingsTest()
base.CheckSettingsTest();
}

[Test, TestCaseSource(typeof(EntraIdTestUsersSource), nameof(EntraIdTestUsersSource.GetSomeUsers), new object[] { UnitTestsHelper.MaxNumberOfUsersToTest })]
public void TestUsers(EntraIdTestUser user)
[Test, TestCaseSource(typeof(TestEntitySourceManager), nameof(TestEntitySourceManager.GetSomeUsers), new object[] { TestEntitySourceManager.MaxNumberOfUsersToTest })]
public void TestUsers(TestUser user)
{
base.TestSearchAndValidateForEntraIDUser(user);
user.UserPrincipalName = user.DisplayName;
Expand All @@ -36,8 +36,8 @@ public void TestUsers(EntraIdTestUser user)
base.TestSearchAndValidateForEntraIDUser(user);
}

[Test, TestCaseSource(typeof(EntraIdTestGroupsSource), nameof(EntraIdTestGroupsSource.GetSomeGroups), new object[] { true, UnitTestsHelper.MaxNumberOfGroupsToTest })]
public void TestGroups(EntraIdTestGroup group)
[Test, TestCaseSource(typeof(TestEntitySourceManager), nameof(TestEntitySourceManager.GetSomeGroups), new object[] { TestEntitySourceManager.MaxNumberOfGroupsToTest, true })]
public void TestGroups(TestGroup group)
{
TestSearchAndValidateForEntraIDGroup(group);
group.Id = group.DisplayName;
Expand Down Expand Up @@ -77,14 +77,14 @@ public override void CheckSettingsTest()
base.CheckSettingsTest();
}

[Test, TestCaseSource(typeof(EntraIdTestGroupsSource), nameof(EntraIdTestGroupsSource.GetSomeGroups), new object[] { true, UnitTestsHelper.MaxNumberOfGroupsToTest })]
public void TestGroups(EntraIdTestGroup group)
[Test, TestCaseSource(typeof(TestEntitySourceManager), nameof(TestEntitySourceManager.GetSomeGroups), new object[] { TestEntitySourceManager.MaxNumberOfGroupsToTest, true })]
public void TestGroups(TestGroup group)
{
TestSearchAndValidateForEntraIDGroup(group);
}

[Test, TestCaseSource(typeof(EntraIdTestUsersSource), nameof(EntraIdTestUsersSource.GetSomeUsers), new object[] { UnitTestsHelper.MaxNumberOfUsersToTest })]
public void TestUsers(EntraIdTestUser user)
[Test, TestCaseSource(typeof(TestEntitySourceManager), nameof(TestEntitySourceManager.GetSomeUsers), new object[] { TestEntitySourceManager.MaxNumberOfUsersToTest })]
public void TestUsers(TestUser user)
{
base.TestSearchAndValidateForEntraIDUser(user);
}
Expand Down
28 changes: 14 additions & 14 deletions Yvand.EntraCP.Tests/ClaimsProviderTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ public string GroupIdentifierClaimType

private object _LockVerifyIfCurrentUserShouldBeFound = new object();
private object _LockInitGroupsWhichUsersMustBeMemberOfAny = new object();
private List<EntraIdTestGroupSettings> _GroupsWhichUsersMustBeMemberOfAny;
protected List<EntraIdTestGroupSettings> GroupsWhichUsersMustBeMemberOfAny
private List<TestGroup> _GroupsWhichUsersMustBeMemberOfAny;
protected List<TestGroup> GroupsWhichUsersMustBeMemberOfAny
{
get
{
if (_GroupsWhichUsersMustBeMemberOfAny != null) { return _GroupsWhichUsersMustBeMemberOfAny; }
lock (_LockInitGroupsWhichUsersMustBeMemberOfAny)
{
if (_GroupsWhichUsersMustBeMemberOfAny != null) { return _GroupsWhichUsersMustBeMemberOfAny; }
_GroupsWhichUsersMustBeMemberOfAny = new List<EntraIdTestGroupSettings>();
_GroupsWhichUsersMustBeMemberOfAny = new List<TestGroup>();
string groupsWhichUsersMustBeMemberOfAny = Settings.RestrictSearchableUsersByGroups;
if (!String.IsNullOrWhiteSpace(groupsWhichUsersMustBeMemberOfAny))
{
string[] groupIds = groupsWhichUsersMustBeMemberOfAny.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string groupId in groupIds)
{
EntraIdTestGroupSettings groupSettings = EntraIdTestGroupsSource.GroupsSettings.FirstOrDefault(x => x.Id == groupId);
if (groupSettings == null) { groupSettings = new EntraIdTestGroupSettings(); }
TestGroup groupSettings = TestEntitySourceManager.GroupsWithCustomSettings.FirstOrDefault(x => x.Id == groupId);
if (groupSettings == null) { groupSettings = new TestGroup(); }
_GroupsWhichUsersMustBeMemberOfAny.Add(groupSettings);
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ public virtual void CheckSettingsTest()
}
}

public void TestSearchAndValidateForEntraIDGroup(EntraIdTestGroup entity)
public void TestSearchAndValidateForEntraIDGroup(TestGroup entity)
{
string inputValue = entity.DisplayName;
int expectedCount = 1;
Expand All @@ -137,7 +137,7 @@ public void TestSearchAndValidateForEntraIDGroup(EntraIdTestGroup entity)
TestValidationOperation(GroupIdentifierClaimType, entity.Id, shouldValidate);
}

public void TestSearchAndValidateForEntraIDUser(EntraIdTestUser entity)
public void TestSearchAndValidateForEntraIDUser(TestUser entity)
{
int expectedCount = 1;
string inputValue = entity.DisplayName;
Expand Down Expand Up @@ -172,8 +172,8 @@ public void TestSearchAndValidateForEntraIDUser(EntraIdTestUser entity)
if (!groupWithAllTestUsersAreMembersFound)
{

EntraIdTestUserSettings userSettings = EntraIdTestUsersSource.UsersWithSpecificSettings.FirstOrDefault(x => String.Equals(x.UserPrincipalName, entity.UserPrincipalName, StringComparison.InvariantCultureIgnoreCase));
if (userSettings == null) { userSettings = new EntraIdTestUserSettings(); }
TestUser userSettings = TestEntitySourceManager.UsersWithCustomSettings.FirstOrDefault(x => String.Equals(x.UserPrincipalName, entity.UserPrincipalName, StringComparison.InvariantCultureIgnoreCase));
if (userSettings == null) { userSettings = new TestUser(); }
if (!userSettings.IsMemberOfAllGroups)
{
shouldValidate = false;
Expand Down Expand Up @@ -219,22 +219,22 @@ public void TestSearchAndValidateForEntraIDUser(EntraIdTestUser entity)
public virtual void TestAugmentationOfGoldUsersAgainstRandomGroups()
{
Random rnd = new Random();
int randomIdx = rnd.Next(0, EntraIdTestGroupsSource.Groups.Count - 1);
int randomIdx = rnd.Next(0, TestEntitySourceManager.AllTestGroups.Count - 1);
Trace.TraceInformation($"{DateTime.Now:s} [{this.GetType().Name}] TestAugmentationOfGoldUsersAgainstRandomGroups: Get group in EntraIdTestGroupsSource.Groups at index {randomIdx}.");
EntraIdTestGroup randomGroup = null;
TestGroup randomGroup = null;
try
{
randomGroup = EntraIdTestGroupsSource.Groups[randomIdx];
randomGroup = TestEntitySourceManager.AllTestGroups[randomIdx];
}
catch (ArgumentOutOfRangeException)
{
string errorMessage = $"{DateTime.Now:s} [{this.GetType().Name}] TestAugmentationOfGoldUsersAgainstRandomGroups: Could not get group in EntraIdTestGroupsSource.Groups at index {randomIdx}. EntraIdTestGroupsSource.Groups has {EntraIdTestGroupsSource.Groups.Count} items.";
string errorMessage = $"{DateTime.Now:s} [{this.GetType().Name}] TestAugmentationOfGoldUsersAgainstRandomGroups: Could not get group in EntraIdTestGroupsSource.Groups at index {randomIdx}. EntraIdTestGroupsSource.Groups has {TestEntitySourceManager.AllTestGroups.Count} items.";
Trace.TraceError(errorMessage);
throw new ArgumentOutOfRangeException(errorMessage);
}
bool shouldBeMember = Settings.FilterSecurityEnabledGroupsOnly && !randomGroup.SecurityEnabled ? false : true;

foreach (string userPrincipalName in EntraIdTestUsersSource.UsersWithSpecificSettings.Where(x => x.IsMemberOfAllGroups).Select(x => x.UserPrincipalName))
foreach (string userPrincipalName in TestEntitySourceManager.UsersWithCustomSettings.Where(x => x.IsMemberOfAllGroups).Select(x => x.UserPrincipalName))
{
TestAugmentationOperation(userPrincipalName, shouldBeMember, randomGroup.Id);
}
Expand Down
24 changes: 12 additions & 12 deletions Yvand.EntraCP.Tests/ExcludeAUserTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public override void CheckSettingsTest()
base.CheckSettingsTest();
}

[Test, TestCaseSource(typeof(EntraIdTestGroupsSource), nameof(EntraIdTestGroupsSource.GetSomeGroups), new object[] { true, UnitTestsHelper.MaxNumberOfGroupsToTest })]
public void TestGroups(EntraIdTestGroup group)
[Test, TestCaseSource(typeof(TestEntitySourceManager), nameof(TestEntitySourceManager.GetSomeGroups), new object[] { TestEntitySourceManager.MaxNumberOfGroupsToTest, true })]
public void TestGroups(TestGroup group)
{
TestSearchAndValidateForEntraIDGroup(group);
}

[Test, TestCaseSource(typeof(EntraIdTestUsersSource), nameof(EntraIdTestUsersSource.GetSomeUsers), new object[] { UnitTestsHelper.MaxNumberOfUsersToTest })]
public void TestUsers(EntraIdTestUser user)
[Test, TestCaseSource(typeof(TestEntitySourceManager), nameof(TestEntitySourceManager.GetSomeUsers), new object[] { TestEntitySourceManager.MaxNumberOfUsersToTest })]
public void TestUsers(TestUser user)
{
base.TestSearchAndValidateForEntraIDUser(user);
}
Expand Down Expand Up @@ -60,14 +60,14 @@ public override void CheckSettingsTest()
base.CheckSettingsTest();
}

[Test, TestCaseSource(typeof(EntraIdTestGroupsSource), nameof(EntraIdTestGroupsSource.GetSomeGroups), new object[] { true, UnitTestsHelper.MaxNumberOfGroupsToTest })]
public void TestGroups(EntraIdTestGroup group)
[Test, TestCaseSource(typeof(TestEntitySourceManager), nameof(TestEntitySourceManager.GetSomeGroups), new object[] { TestEntitySourceManager.MaxNumberOfGroupsToTest, true })]
public void TestGroups(TestGroup group)
{
TestSearchAndValidateForEntraIDGroup(group);
}

[Test, TestCaseSource(typeof(EntraIdTestUsersSource), nameof(EntraIdTestUsersSource.GetSomeUsers), new object[] { UnitTestsHelper.MaxNumberOfUsersToTest })]
public void TestUsers(EntraIdTestUser user)
[Test, TestCaseSource(typeof(TestEntitySourceManager), nameof(TestEntitySourceManager.GetSomeUsers), new object[] { TestEntitySourceManager.MaxNumberOfUsersToTest })]
public void TestUsers(TestUser user)
{
base.TestSearchAndValidateForEntraIDUser(user);
}
Expand Down Expand Up @@ -99,14 +99,14 @@ public override void CheckSettingsTest()
base.CheckSettingsTest();
}

[Test, TestCaseSource(typeof(EntraIdTestGroupsSource), nameof(EntraIdTestGroupsSource.GetSomeGroups), new object[] { true, UnitTestsHelper.MaxNumberOfGroupsToTest })]
public void TestGroups(EntraIdTestGroup group)
[Test, TestCaseSource(typeof(TestEntitySourceManager), nameof(TestEntitySourceManager.GetSomeGroups), new object[] { TestEntitySourceManager.MaxNumberOfGroupsToTest, true })]
public void TestGroups(TestGroup group)
{
TestSearchAndValidateForEntraIDGroup(group);
}

[Test, TestCaseSource(typeof(EntraIdTestUsersSource), nameof(EntraIdTestUsersSource.GetSomeUsers), new object[] { UnitTestsHelper.MaxNumberOfUsersToTest })]
public void TestUsers(EntraIdTestUser user)
[Test, TestCaseSource(typeof(TestEntitySourceManager), nameof(TestEntitySourceManager.GetSomeUsers), new object[] { TestEntitySourceManager.MaxNumberOfUsersToTest })]
public void TestUsers(TestUser user)
{
base.TestSearchAndValidateForEntraIDUser(user);
}
Expand Down
24 changes: 13 additions & 11 deletions Yvand.EntraCP.Tests/FilterUsersBasedOnGroupsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class FilterUsersBasedOnSingleGroupTests : ClaimsProviderTestsBase
public override void InitializeSettings()
{
base.InitializeSettings();
Settings.RestrictSearchableUsersByGroups = EntraIdTestGroupsSource.GetSomeGroups(true, 1).ToArray()[0].Id;
Settings.RestrictSearchableUsersByGroups = TestEntitySourceManager.GetOneGroup(true).Id;
base.ApplySettings();
}

Expand All @@ -23,8 +23,8 @@ public override void CheckSettingsTest()
base.CheckSettingsTest();
}

[Test, TestCaseSource(typeof(EntraIdTestUsersSource), nameof(EntraIdTestUsersSource.GetSomeUsers), new object[] { UnitTestsHelper.MaxNumberOfUsersToTest })]
public void TestUsers(EntraIdTestUser user)
[Test, TestCaseSource(typeof(TestEntitySourceManager), nameof(TestEntitySourceManager.GetSomeUsers), new object[] { TestEntitySourceManager.MaxNumberOfUsersToTest })]
public void TestUsers(TestUser user)
{
base.TestSearchAndValidateForEntraIDUser(user);
}
Expand All @@ -34,7 +34,7 @@ public void TestUsers(EntraIdTestUser user)
[TestCase("testEntraCPUser_020")]
public void DebugTestUser(string upnPrefix)
{
EntraIdTestUser user = EntraIdTestUsersSource.Users.Find(x => x.UserPrincipalName.StartsWith(upnPrefix));
TestUser user = TestEntitySourceManager.AllTestUsers.Find(x => x.UserPrincipalName.StartsWith(upnPrefix));
base.TestSearchAndValidateForEntraIDUser(user);
}
#endif
Expand All @@ -49,7 +49,9 @@ public override void InitializeSettings()
base.InitializeSettings();

// Pick the Id of 18 (max possible) random groups, and set them in property RestrictSearchableUsersByGroups
Settings.RestrictSearchableUsersByGroups = String.Join(",", EntraIdTestGroupsSource.GetSomeGroups(true, 18).Select(x => x.Id).ToArray());
Settings.RestrictSearchableUsersByGroups = String.Join(",", TestEntitySourceManager.GetSomeGroups(18, true).Select(x => x.Id).ToArray());
//Settings.RestrictSearchableUsersByGroups = "3c1c6c1a-2565-4cfd-b5f8-8ec732f93077,3c98541c-9601-47c0-aeea-fc0679b9d756,807c95cd-88de-49d9-a06e-12ce2329dfb7,807c95cd-88de-49d9-a06e-12ce2329dfb7,1beb24dd-0fae-46cb-b321-dd0baf5c9ecc,01572e9f-4a9a-4dd1-9314-05972d87d1c2,89d4f192-8eb0-4011-ada7-4a1d4f678b1c,bdd53ff1-866c-442b-b6d5-ac43b4306aa7,2d407401-192c-4a25-9f0e-3693cfad6f27,1c607c55-f1a0-408c-ae52-306cd89de742,1090383f-7ea5-4a16-9ba8-0551a061d7f9,874b1dcf-aa82-428a-b107-b71a09c3d452,1090383f-7ea5-4a16-9ba8-0551a061d7f9,1831bd90-e413-4b86-a8ab-5d26d8a75498,04ec1e1c-196d-4b85-85b2-c3b982644114,043e997e-0b2c-412c-b8f0-13253251569c,40d53a73-130b-48e1-946b-5fec5ec35d4f,3c98541c-9601-47c0-aeea-fc0679b9d756";
//Settings.RestrictSearchableUsersByGroups = "3c98541c-9601-47c0-aeea-fc0679b9d756";
Trace.TraceInformation($"{DateTime.Now:s} [{this.GetType().Name}] Set property RestrictSearchableUsersByGroups: \"{Settings.RestrictSearchableUsersByGroups}\".");
base.ApplySettings();
}
Expand All @@ -60,8 +62,8 @@ public override void CheckSettingsTest()
base.CheckSettingsTest();
}

[Test, TestCaseSource(typeof(EntraIdTestUsersSource), nameof(EntraIdTestUsersSource.GetSomeUsers), new object[] { UnitTestsHelper.MaxNumberOfUsersToTest })]
public void TestUsers(EntraIdTestUser user)
[Test, TestCaseSource(typeof(TestEntitySourceManager), nameof(TestEntitySourceManager.GetSomeUsers), new object[] { TestEntitySourceManager.MaxNumberOfUsersToTest })]
public void TestUsers(TestUser user)
{
base.TestSearchAndValidateForEntraIDUser(user);
}
Expand All @@ -71,7 +73,7 @@ public void TestUsers(EntraIdTestUser user)
[TestCase("testEntraCPUser_020")]
public void DebugTestUser(string upnPrefix)
{
EntraIdTestUser user = EntraIdTestUsersSource.Users.Find(x => x.UserPrincipalName.StartsWith(upnPrefix));
TestUser user = TestEntitySourceManager.FindUser(upnPrefix);
base.TestSearchAndValidateForEntraIDUser(user);
}
#endif
Expand All @@ -85,7 +87,7 @@ public class DebugFilterUsersBasedOnMultipleGroupsTests : ClaimsProviderTestsBas
public override void InitializeSettings()
{
base.InitializeSettings();
Settings.RestrictSearchableUsersByGroups = String.Join(",", EntraIdTestGroupsSource.GetSomeGroups(true, 18).Select(x => x.Id).ToArray());
Settings.RestrictSearchableUsersByGroups = String.Join(",", TestEntitySourceManager.GetSomeGroups(18, true).Select(x => x.Id).ToArray());
Trace.TraceInformation($"{DateTime.Now:s} [{this.GetType().Name}] Set property RestrictSearchableUsersByGroups: \"{Settings.RestrictSearchableUsersByGroups}\".");
base.ApplySettings();
}
Expand All @@ -94,14 +96,14 @@ public override void InitializeSettings()
[TestCase("testEntraCPUser_020")]
public void DebugTestUser(string upnPrefix)
{
EntraIdTestUser user = EntraIdTestUsersSource.Users.Find(x => x.UserPrincipalName.StartsWith(upnPrefix));
TestUser user = TestEntitySourceManager.FindUser(upnPrefix);
base.TestSearchAndValidateForEntraIDUser(user);
}

[Test]
public void DebugGuestUser()
{
EntraIdTestUser user = EntraIdTestUsersSource.Users.Find(x => x.Mail.StartsWith("testEntraCPGuestUser_001"));
TestUser user = TestEntitySourceManager.AllTestUsers.Find(x => x.Mail.StartsWith("testEntraCPGuestUser_001"));
base.TestSearchAndValidateForEntraIDUser(user);
}
}
Expand Down
Loading
Loading