Skip to content

Added EntraID app support for unit tests #1131

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
44 changes: 33 additions & 11 deletions src/lib/PnP.Framework.Test/TestCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,15 @@ static TestCommon()
UserName = AppSetting("SPOUserName");
Password = EncryptionUtility.ToSecureString(AppSetting("SPOPassword"));
}
else if (!String.IsNullOrEmpty(AppSetting("AppId")) &&
!String.IsNullOrEmpty(AppSetting("AppSecret")))
{
AppId = AppSetting("AppId");
AppSecret = AppSetting("AppSecret");
}
else
{
if (!String.IsNullOrEmpty(AppSetting("AppId")) &&
!String.IsNullOrEmpty(AppSetting("AppSecret")))
{
AppId = AppSetting("AppId");
AppSecret = AppSetting("AppSecret");
}
else
{
throw new ConfigurationErrorsException("Tenant credentials in App.config are not set up.");
}
// Different authentication methods could be set e.g. azure AD
}
}
#endregion
Expand All @@ -126,6 +123,14 @@ static TestCommon()
/// </summary>
public static string DefaultSiteOwner { get; set; }

public static String TenantId
{
get
{
return AppSetting("TenantId");
}
}

public static string TestWebhookUrl
{
get
Expand Down Expand Up @@ -157,6 +162,14 @@ public static String AzureADCertificateFilePath
}
}

public static String AzureADCertificateThumbprint
{
get
{
return AppSetting("AzureADCertificateThumbprint");
}
}

public static String NoScriptSite
{
get
Expand Down Expand Up @@ -323,7 +336,16 @@ private static ClientContext CreateContext(string contextUrl, AzureEnvironment a
{

ClientContext context = null;
if (!String.IsNullOrEmpty(AppId) && !String.IsNullOrEmpty(AppSecret))

if (!String.IsNullOrEmpty(AzureADClientId))
{
if (!string.IsNullOrEmpty(AzureADCertificateThumbprint))
{
using var am = AuthenticationManager.CreateWithCertificate(AzureADClientId, System.Security.Cryptography.X509Certificates.StoreName.My, System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser, AzureADCertificateThumbprint, TenantId);
context = am.GetContext(contextUrl);
}
}
else if (!String.IsNullOrEmpty(AppId) && !String.IsNullOrEmpty(AppSecret))
{
using (AuthenticationManager am = new AuthenticationManager())
{
Expand Down