Skip to content

Commit

Permalink
Merge pull request #191 from Yvand/update-graph
Browse files Browse the repository at this point in the history
move AzureCP SE to dev
  • Loading branch information
Yvand authored Aug 16, 2023
2 parents a413502 + 024e1a0 commit 01f8c8f
Show file tree
Hide file tree
Showing 54 changed files with 4,562 additions and 4,458 deletions.
18 changes: 9 additions & 9 deletions AzureCP.Tests/AzureCP.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<ProjectGuid>{DB8C79E5-F7F7-4841-8A8C-A9832A9CAE88}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AzureCP.Tests</RootNamespace>
<AssemblyName>AzureCP.Tests</AssemblyName>
<RootNamespace>Yvand.ClaimsProviders.Tests</RootNamespace>
<AssemblyName>AzureCPSE.Tests</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Expand Down Expand Up @@ -41,22 +41,22 @@
<Reference Include="Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\AzureCP\references\SPSE\Microsoft.SharePoint.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="ExcludeAllUserAccountsTests.cs" />
<Compile Include="BasicTests.cs" />
<Compile Include="ExcludeAUserTypeTests.cs" />
<Compile Include="EntityTestsBase.cs" />
<Compile Include="ExcludeMemberUserAccountsTests.cs" />
<Compile Include="ExcludeGuestUserAccountsTests.cs" />
<Compile Include="GuestAccountsUPNTests.cs" />
<Compile Include="BackupCurrentConfig.cs" />
<Compile Include="RequireExactMatchTests.cs" />
<Compile Include="UnitTestsHelper.cs" />
<Compile Include="CustomConfigTests.cs" />
<Compile Include="ModifyConfigTests.cs" />
<Compile Include="CustomizeConfigTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WrongConfigTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="local.runsettings" />
Expand All @@ -73,13 +73,13 @@
<Version>1.0.12</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.2</Version>
<Version>13.0.3</Version>
</PackageReference>
<PackageReference Include="NUnit">
<Version>3.13.3</Version>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter">
<Version>4.4.2</Version>
<Version>4.5.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
46 changes: 0 additions & 46 deletions AzureCP.Tests/BackupCurrentConfig.cs

This file was deleted.

66 changes: 66 additions & 0 deletions AzureCP.Tests/BasicTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using NUnit.Framework;

namespace Yvand.ClaimsProviders.Tests
{
[TestFixture]
[Parallelizable(ParallelScope.Children)]
internal class BasicTests : EntityTestsBase
{
[Test, TestCaseSource(typeof(SearchEntityDataSource), "GetTestData", new object[] { EntityDataSourceType.AllAccounts })]
[Repeat(UnitTestsHelper.TestRepeatCount)]
public override void SearchEntities(SearchEntityData registrationData)
{
base.SearchEntities(registrationData);
}

[Test, TestCaseSource(typeof(ValidateEntityDataSource), "GetTestData", new object[] { EntityDataSourceType.AllAccounts })]
[MaxTime(UnitTestsHelper.MaxTime)]
[Repeat(UnitTestsHelper.TestRepeatCount)]
public override void ValidateClaim(ValidateEntityData registrationData)
{
base.ValidateClaim(registrationData);
}

[Test, TestCaseSource(typeof(ValidateEntityDataSource), "GetTestData", new object[] { EntityDataSourceType.AllAccounts })]
[Repeat(UnitTestsHelper.TestRepeatCount)]
public override void AugmentEntity(ValidateEntityData registrationData)
{
base.AugmentEntity(registrationData);
}

#if DEBUG
////[TestCaseSource(typeof(SearchEntityDataSourceCollection))]
//public void DEBUG_SearchEntitiesFromCollection(string inputValue, string expectedCount, string expectedClaimValue)
//{
// if (!TestSearch) { return; }

// TestSearchOperation(inputValue, Convert.ToInt32(expectedCount), expectedClaimValue);
//}

[TestCase(@"AADGroup1130", 1, "e86ace87-37ba-4ee1-8087-ecd783728233")]
[TestCase(@"xyzguest", 0, "[email protected]")]
[TestCase(@"AzureGr}", 1, "ef7d18e6-5c4d-451a-9663-a976be81c91e")]
[TestCase(@"aad", 30, "")]
[TestCase(@"AADGroup", 30, "")]
public override void SearchEntities(string inputValue, int expectedResultCount, string expectedEntityClaimValue)
{
base.SearchEntities(inputValue, expectedResultCount, expectedEntityClaimValue);
}

[TestCase("http://schemas.microsoft.com/ws/2008/06/identity/claims/role", "ef7d18e6-5c4d-451a-9663-a976be81c91e", true)]
[TestCase("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn", "[email protected]", false)]
[TestCase("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress", "FakeGuest.com#EXT#@XXX.onmicrosoft.com", false)]
[TestCase("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn", "FakeGuest.com#EXT#@XXX.onmicrosoft.com", false)]
public override void ValidateClaim(string claimType, string claimValue, bool shouldValidate)
{
base.ValidateClaim(claimType, claimValue, shouldValidate);
}

[TestCase("[email protected]", false)]
public override void AugmentEntity(string claimValue, bool shouldHavePermissions)
{
base.AugmentEntity(claimValue, shouldHavePermissions);
}
#endif
}
}
82 changes: 33 additions & 49 deletions AzureCP.Tests/CustomConfigTests.cs
Original file line number Diff line number Diff line change
@@ -1,94 +1,78 @@
using azurecp;
using Microsoft.SharePoint.Administration.Claims;
using Microsoft.SharePoint.Administration.Claims;
using NUnit.Framework;
using System;
using System.Linq;
using System.Security.Claims;
using Yvand.ClaimsProviders.AzureAD;
using Yvand.ClaimsProviders.Config;

namespace AzureCP.Tests
namespace Yvand.ClaimsProviders.Tests
{
[TestFixture]
public class CustomConfigTests : BackupCurrentConfig
public class CustomConfigTestsBase : EntityTestsBase
{
public static string GroupsClaimType = ClaimsProviderConstants.DefaultMainGroupClaimType;

public override void InitializeConfiguration()
{
base.InitializeConfiguration();

// Extra initialization for current test class
Config.EnableAugmentation = true;
Config.ClaimTypes.GetByClaimType(UnitTestsHelper.SPTrust.IdentityClaimTypeInformation.MappedClaimType).PrefixToBypassLookup = "bypass-user:";
Config.ClaimTypes.GetByClaimType(UnitTestsHelper.TrustedGroupToAdd_ClaimType).PrefixToBypassLookup = "bypass-group:";
Config.Update();
Settings.EnableAugmentation = true;
Settings.ClaimTypes.GetByClaimType(UnitTestsHelper.SPTrust.IdentityClaimTypeInformation.MappedClaimType).PrefixToBypassLookup = "bypass-user:";
Settings.ClaimTypes.GetByClaimType(UnitTestsHelper.TrustedGroupToAdd_ClaimType).PrefixToBypassLookup = "bypass-group:";
ClaimTypeConfig ctConfigExtensionAttribute = new ClaimTypeConfig
{
ClaimType = TestContext.Parameters["MultiPurposeCustomClaimType"],
ClaimTypeDisplayName = "extattr1",
EntityProperty = DirectoryObjectProperty.extensionAttribute1,
SharePointEntityType = "FormsRole",
};
Settings.ClaimTypes.Add(ctConfigExtensionAttribute);
GlobalConfiguration.ApplySettings(Settings, true);
}
}

[TestFixture]
[Parallelizable(ParallelScope.Children)]
public class CustomConfigTests : CustomConfigTestsBase
{
[TestCase("bypass-user:[email protected]", 1, "[email protected]")]
[TestCase("[email protected]", 0, "")]
[TestCase("bypass-user:", 0, "")]
public void BypassLookupOnIdentityClaimTest(string inputValue, int expectedCount, string expectedClaimValue)
{
UnitTestsHelper.TestSearchOperation(inputValue, expectedCount, expectedClaimValue);
TestSearchOperation(inputValue, expectedCount, expectedClaimValue);

if (expectedCount > 0)
{
SPClaim inputClaim = new SPClaim(UnitTestsHelper.SPTrust.IdentityClaimTypeInformation.MappedClaimType, expectedClaimValue, ClaimValueTypes.String, SPOriginalIssuers.Format(SPOriginalIssuerType.TrustedProvider, UnitTestsHelper.SPTrust.Name));
UnitTestsHelper.TestValidationOperation(inputClaim, true, expectedClaimValue);
TestValidationOperation(inputClaim, true, expectedClaimValue);
}
}

[TestCase(@"bypass-group:domain\groupValue", 1, @"domain\groupValue")]
[TestCase(@"domain\groupValue", 0, "")]
[TestCase("bypass-group:", 0, "")]
public void BypassLookupOnGroupClaimTest(string inputValue, int expectedCount, string expectedClaimValue)
[TestCase("val", 1, "value1")] // Extension attribute configuration
public override void SearchEntities(string inputValue, int expectedResultCount, string expectedEntityClaimValue)
{
UnitTestsHelper.TestSearchOperation(inputValue, expectedCount, expectedClaimValue);

if (expectedCount > 0)
{
SPClaim inputClaim = new SPClaim(UnitTestsHelper.TrustedGroupToAdd_ClaimType, expectedClaimValue, ClaimValueTypes.String, SPOriginalIssuers.Format(SPOriginalIssuerType.TrustedProvider, UnitTestsHelper.SPTrust.Name));
UnitTestsHelper.TestValidationOperation(inputClaim, true, expectedClaimValue);
}
base.SearchEntities(inputValue, expectedResultCount, expectedEntityClaimValue);
}

[Test]
[NonParallelizable]
public void BypassServer()
{
Config.AlwaysResolveUserInput = true;
Config.Update();

Settings.AlwaysResolveUserInput = true;
GlobalConfiguration.ApplySettings(Settings, true);
try
{
UnitTestsHelper.TestSearchOperation(UnitTestsHelper.RandomClaimValue, 2, UnitTestsHelper.RandomClaimValue);
TestSearchOperation(UnitTestsHelper.RandomClaimValue, 3, UnitTestsHelper.RandomClaimValue);

SPClaim inputClaim = new SPClaim(UnitTestsHelper.SPTrust.IdentityClaimTypeInformation.MappedClaimType, UnitTestsHelper.RandomClaimValue, ClaimValueTypes.String, SPOriginalIssuers.Format(SPOriginalIssuerType.TrustedProvider, UnitTestsHelper.SPTrust.Name));
UnitTestsHelper.TestValidationOperation(inputClaim, true, UnitTestsHelper.RandomClaimValue);
TestValidationOperation(inputClaim, true, UnitTestsHelper.RandomClaimValue);
}
finally
{
Config.AlwaysResolveUserInput = false;
Config.Update();
Settings.AlwaysResolveUserInput = false;
GlobalConfiguration.ApplySettings(Settings, true);
}
}

//[Test, TestCaseSource(typeof(ValidateEntityDataSource), "GetTestData", new object[] { EntityDataSourceType.AllAccounts })]
////[Repeat(UnitTestsHelper.TestRepeatCount)]
//public void RequireExactMatchDuringSearch(ValidateEntityData registrationData)
//{
// Config.FilterExactMatchOnly = true;
// Config.Update();

// try
// {
// int expectedCount = registrationData.ShouldValidate ? 1 : 0;
// UnitTestsHelper.TestSearchOperation(registrationData.ClaimValue, expectedCount, registrationData.ClaimValue);
// }
// finally
// {
// Config.FilterExactMatchOnly = false;
// Config.Update();
// }
//}
}
}
Loading

0 comments on commit 01f8c8f

Please sign in to comment.