diff --git a/src/ResourceManagement/Intune/Intune.Tests/Helpers/AADClientHelper.cs b/src/ResourceManagement/Intune/Intune.Tests/Helpers/AADClientHelper.cs index d9e6d7048a43..c80ed4191586 100644 --- a/src/ResourceManagement/Intune/Intune.Tests/Helpers/AADClientHelper.cs +++ b/src/ResourceManagement/Intune/Intune.Tests/Helpers/AADClientHelper.cs @@ -27,7 +27,7 @@ namespace Microsoft.Azure.Management.Intune.Tests.Helpers /// /// Types of environment in Intune /// - internal enum EnvironmentType + public enum EnvironmentType { OneBox, Dogfood, @@ -38,7 +38,7 @@ internal enum EnvironmentType /// /// Azure Active directory related operations helper class. /// - internal class AADClientHelper + public class AADClientHelper { public const string AadAuthDogfoodEnpoint = "https://login.windows-ppe.net/"; @@ -87,7 +87,25 @@ private set } } - public AADClientHelper(string userName, string password, EnvironmentType env) + public AADClientHelper() + { + var orgIdAuth = Environment.GetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION"); + var parts = orgIdAuth.Split(new char[] { ';' }).ToList(); + var authParams = new Dictionary(); + parts.ForEach(a => { var splitVal = a.Split(new char[] { '=' }); authParams.Add(splitVal[0], splitVal[1]); }); + EnvironmentType enType = EnvironmentType.Dogfood; + if (authParams["Environment"] == "Dogfood") + { + enType = EnvironmentType.Dogfood; + } + else if (authParams["Environment"] == "Prod") + { + enType = EnvironmentType.Prod; + } + + InitializeAADClient(authParams["UserId"], authParams["Password"], enType); + } + private void InitializeAADClient(string userName, string password, EnvironmentType env) { this.userName = userName; this.password = password; diff --git a/src/ResourceManagement/Intune/Intune.Tests/Helpers/IntuneClientHelper.cs b/src/ResourceManagement/Intune/Intune.Tests/Helpers/IntuneClientHelper.cs index e68c0ae4150a..a20fe83e2460 100644 --- a/src/ResourceManagement/Intune/Intune.Tests/Helpers/IntuneClientHelper.cs +++ b/src/ResourceManagement/Intune/Intune.Tests/Helpers/IntuneClientHelper.cs @@ -71,8 +71,10 @@ internal static string AsuHostName internal static void InitializeEnvironment() { //Environment.SetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION", "SubscriptionId=3e9e6f07-6225-4d10-8fd4-5f0236c28f5a;Environment=Dogfood;UserId=admin@aad296.ccsctp.net;Password=XXXXXXX"); //Environment.SetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION", "SubscriptionId=None;Environment=Dogfood;UserId=admin@uxmdmonly.ccsctp.net;Password=XXXXXX"); + //Environment.SetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION", "SubscriptionId=None;Environment=Prod;UserId=admin@franktrtestdomain.onmicrosoft.com;Password=XXXXXX"); + //AZURE_TEST_MODE = None, Record, Playback - //Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback"); + Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback"); } } } diff --git a/src/ResourceManagement/Intune/Intune.Tests/Helpers/TestContextHelper.cs b/src/ResourceManagement/Intune/Intune.Tests/Helpers/TestContextHelper.cs index 40b810b30eff..b8cb631a50ff 100644 --- a/src/ResourceManagement/Intune/Intune.Tests/Helpers/TestContextHelper.cs +++ b/src/ResourceManagement/Intune/Intune.Tests/Helpers/TestContextHelper.cs @@ -14,6 +14,7 @@ using System; using Microsoft.Azure.Test.HttpRecorder; +using System.Linq; namespace Microsoft.Azure.Management.Intune.Tests.Helpers { @@ -43,5 +44,60 @@ public static T GetValueFromTestContext(Func constructor, Func return retValue; } + + public static string GetAdGroupFromTestContext(string mockName) + { + string retValue = string.Empty; + if (HttpMockServer.Mode != HttpRecorderMode.Playback) + { + var aadClient = new AADClientHelper(); + var adGroups = aadClient.GetUserGroups().GetAwaiter().GetResult(); + var adGroupList = adGroups.Where(x => x.Keys.Contains("ID")).Select(x => x["ID"]).ToList(); + if (adGroupList.Count >= 1) + { + retValue = HttpMockServer.Variables[mockName] = adGroupList.ElementAt(0); + } + else + { + throw new Exception(string.Format("Unexpected number of Groups. Expected: adGroupList.Count >= 1 but actual = {0}", adGroupList.Count)); + } + } + else + { + if (HttpMockServer.Variables.ContainsKey(mockName)) + { + retValue = HttpMockServer.Variables[mockName]; + } + else + { + throw new Exception(string.Format("HttpMockServer.Variables does not have a value to retrieve for mockName={0}", mockName)); + } + } + + return retValue; + } + + public static string GetAdUserFromTestContext(string mockName) + { + string retValue = string.Empty; + if (HttpMockServer.Mode != HttpRecorderMode.Playback) + { + var aadClient = new AADClientHelper(); + retValue = HttpMockServer.Variables[mockName] = aadClient.UserId; + } + else + { + if (HttpMockServer.Variables.ContainsKey(mockName)) + { + retValue = HttpMockServer.Variables[mockName]; + } + else + { + throw new Exception(string.Format("HttpMockServer.Variables does not have a value to retrieve for mockName={0}", mockName)); + } + } + + return retValue; + } } } diff --git a/src/ResourceManagement/Intune/Intune.Tests/Intune.Tests.csproj b/src/ResourceManagement/Intune/Intune.Tests/Intune.Tests.csproj index 15726c2d8bdc..9b853d7bde83 100644 --- a/src/ResourceManagement/Intune/Intune.Tests/Intune.Tests.csproj +++ b/src/ResourceManagement/Intune/Intune.Tests/Intune.Tests.csproj @@ -1,7 +1,7 @@  - - + + Debug AnyCPU @@ -152,8 +152,10 @@ Resources.resx + + @@ -164,35 +166,52 @@ - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + PreserveNewest @@ -222,7 +241,7 @@ - +