public void ShouldPatchAndroidPolicy()
        {
            using (MockContext context = MockContext.Start("Microsoft.Azure.Management.Intune.Tests.ScenarioTests.PolicyScenarioTests"))
            {
                var    client       = IntuneClientHelper.GetIntuneResourceManagementClient(context);
                string policyName   = TestContextHelper.GetValueFromTestContext(Guid.NewGuid, Guid.Parse, "IntunePolicy").ToString();
                string friendlyName = TestUtilities.GenerateName(IntuneConstants.IntuneAndroidPolicy);
                var    payload      = DefaultAndroidPolicy.GetPayload(friendlyName);
                try
                {
                    var policyCreated = client.Android.CreateOrUpdateMAMPolicy(
                        IntuneClientHelper.AsuHostName,
                        policyName,
                        payload);

                    //Modified properties to patch..
                    var appSharingFromLevelUpdated         = AppSharingType.allApps.ToString();
                    var accessRecheckOfflineTimeoutUpdated = new TimeSpan(24, 0, 0);
                    int pinNumRetryUpdated = 50;
                    client.Android.PatchMAMPolicy(IntuneClientHelper.AsuHostName,
                                                  policyName,
                                                  new Models.AndroidMAMPolicy
                    {
                        AppSharingFromLevel         = appSharingFromLevelUpdated,
                        AccessRecheckOfflineTimeout = accessRecheckOfflineTimeoutUpdated,
                        PinNumRetry = pinNumRetryUpdated
                    });

                    var policy = client.Android.GetMAMPolicyByName(IntuneClientHelper.AsuHostName, policyName);

                    Assert.True(policy.Id.Contains(policyName));
                    Assert.Equal(policy.FriendlyName, friendlyName);

                    //Verify updated properties
                    Assert.Equal(policy.AppSharingFromLevel, appSharingFromLevelUpdated);
                    Assert.Equal(policy.AccessRecheckOfflineTimeout, accessRecheckOfflineTimeoutUpdated);
                    Assert.Equal(policy.PinNumRetry, pinNumRetryUpdated);

                    //Verify couple of properties that are not supposed to be updated.
                    Assert.Equal(policy.ScreenCapture, FilterType.allow.ToString());
                    Assert.Equal(policy.AccessRecheckOnlineTimeout, TimeSpan.FromMinutes(IntuneConstants.DefaultRecheckAccessTimeoutMinutes));
                }
                finally
                {
                    client.Android.DeleteMAMPolicy(IntuneClientHelper.AsuHostName, policyName);
                }
            }
        }
Exemplo n.º 2
0
        public void ShouldAddAndRemoveAndroidMAMGroupsForPolicy()
        {
            using (MockContext context = MockContext.Start("Microsoft.Azure.Management.Intune.Tests.ScenarioTests.GroupScenarioTests"))
            {
                //Initialize aadClient if the test mode is not Playback
                AADClientHelper aadClient = null;
                if (HttpMockServer.Mode != HttpRecorderMode.Playback)
                {
                    aadClient = new AADClientHelper();
                }

                var client = IntuneClientHelper.GetIntuneResourceManagementClient(context);
                //Create a policy
                string policyName   = TestContextHelper.GetValueFromTestContext(Guid.NewGuid, Guid.Parse, "IntunePolicy").ToString();
                string friendlyName = TestUtilities.GenerateName(IntuneConstants.IntuneAndroidPolicy);
                var    payload      = DefaultAndroidPolicy.GetPayload(friendlyName);
                try
                {
                    var policyCreated1 = client.Android.CreateOrUpdateMAMPolicy(
                        IntuneClientHelper.AsuHostName,
                        policyName,
                        payload);

                    //Get groups for tenant
                    var adGroup = TestContextHelper.GetAdGroupFromTestContext("adGroup");

                    //Add group for the policy
                    var groupPayload1 = AppOrGroupPayloadMaker.PrepareMAMPolicyPayload(client, LinkType.GroupType, adGroup);
                    client.Android.AddGroupForMAMPolicy(IntuneClientHelper.AsuHostName, policyName, adGroup, groupPayload1);

                    //Get groups for the policy
                    var groups = client.Android.GetGroupsForMAMPolicy(IntuneClientHelper.AsuHostName, policyName).ToList();
                    Assert.True(groups.Count == 1, string.Format("Expected groups.Count == 1 and actual:{0}", groups.Count));

                    //Remove groups from the policy
                    client.Android.DeleteGroupForMAMPolicy(IntuneClientHelper.AsuHostName, policyName, adGroup);

                    //Get groups for the policy & verify groups are removed.
                    groups = client.Android.GetGroupsForMAMPolicy(IntuneClientHelper.AsuHostName, policyName).ToList();
                    Assert.True(groups.Count == 0, string.Format("Expected groups.Count == 0 but actual groups.Count = {0}", groups.Count));
                }
                finally
                {
                    client.Android.DeleteMAMPolicy(IntuneClientHelper.AsuHostName, policyName);
                }
            }
        }
Exemplo n.º 3
0
        public void ShouldAddAndRemoveAndroidMAMAppForPolicy()
        {
            using (MockContext context = MockContext.Start("Microsoft.Azure.Management.Intune.Tests.ScenarioTests.AppScenarioTests"))
            {
                var client = IntuneClientHelper.GetIntuneResourceManagementClient(context);

                //Create a policy
                string policyName    = TestContextHelper.GetValueFromTestContext(Guid.NewGuid, Guid.Parse, "IntunePolicy").ToString();
                string friendlyName1 = TestUtilities.GenerateName(IntuneConstants.IntuneAndroidPolicy);
                var    payload       = DefaultAndroidPolicy.GetPayload(friendlyName1);
                try
                {
                    var policyCreated1 = client.Android.CreateOrUpdateMAMPolicy(
                        IntuneClientHelper.AsuHostName,
                        policyName,
                        payload);

                    //Get apps for Android
                    string filter      = string.Format(IntuneConstants.PlatformTypeQuery, PlatformType.Android.ToString().ToLower());
                    var    androidApps = client.GetApps(IntuneClientHelper.AsuHostName, filter).ToList();
                    Assert.True(androidApps.Count >= 1, string.Format("Expected androidApps.Count>=1 and actual:{0}", androidApps.Count));

                    //Add app for the policy
                    var appPayload1 = AppOrGroupPayloadMaker.PrepareMAMPolicyPayload(client, LinkType.AppType, androidApps[0].Name);
                    client.Android.AddAppForMAMPolicy(IntuneClientHelper.AsuHostName, policyName, androidApps[0].Name, appPayload1);

                    //Get Apps for the policy
                    var apps = client.Android.GetAppForMAMPolicy(IntuneClientHelper.AsuHostName, policyName).ToList();
                    Assert.True(apps.Count == 1, string.Format("Expected apps.Count==1 and actual:{0}", apps.Count));

                    //Remove Apps for the policy
                    client.Android.DeleteAppForMAMPolicy(IntuneClientHelper.AsuHostName, policyName, androidApps[0].Name);

                    //Get Apps for the policy
                    apps = client.Android.GetAppForMAMPolicy(IntuneClientHelper.AsuHostName, policyName).ToList();
                    Assert.True(apps.Count == 0, string.Format("Expected apps.Count==0 and actual:{0}", apps.Count));
                }
                finally
                {
                    client.Android.DeleteMAMPolicy(IntuneClientHelper.AsuHostName, policyName);
                }
            }
        }
        public void ShouldCreateAndroidPolicyWithDefaults()
        {
            using (MockContext context = MockContext.Start("Microsoft.Azure.Management.Intune.Tests.ScenarioTests.PolicyScenarioTests"))
            {
                var    client        = IntuneClientHelper.GetIntuneResourceManagementClient(context);
                string policyName    = TestContextHelper.GetValueFromTestContext(Guid.NewGuid, Guid.Parse, "IntunePolicy").ToString();
                string friendlyName  = TestUtilities.GenerateName(IntuneConstants.IntuneAndroidPolicy);
                var    payload       = DefaultAndroidPolicy.GetPayload(friendlyName);
                var    policyCreated = client.Android.CreateOrUpdateMAMPolicy(
                    IntuneClientHelper.AsuHostName,
                    policyName,
                    payload);

                var policy = client.Android.GetMAMPolicyByName(IntuneClientHelper.AsuHostName, policyName);

                Assert.True(policy.Id.Contains(policyName));
                Assert.Equal(policy.FriendlyName, friendlyName);

                //Verify defaults
                Assert.Equal(policy.AppSharingToLevel, AppSharingType.none.ToString());
                Assert.Equal(policy.Description, Properties.Resources.AndroidPolicyDescription);
                Assert.Equal(policy.AppSharingFromLevel, AppSharingType.none.ToString());
                Assert.Equal(policy.Authentication, ChoiceType.required.ToString());
                Assert.Equal(policy.ClipboardSharingLevel, ClipboardSharingLevelType.blocked.ToString());
                Assert.Equal(policy.DataBackup, FilterType.allow.ToString());
                Assert.Equal(policy.FileSharingSaveAs, FilterType.allow.ToString());
                Assert.Equal(policy.Pin, ChoiceType.required.ToString());
                Assert.Equal(policy.PinNumRetry, IntuneConstants.DefaultPinRetries);
                Assert.Equal(policy.DeviceCompliance, OptionType.enable.ToString());
                Assert.Equal(policy.ManagedBrowser, ChoiceType.required.ToString());
                Assert.Equal(policy.AccessRecheckOfflineTimeout, TimeSpan.FromMinutes(IntuneConstants.DefaultRecheckAccessOfflineGraceperiodMinutes));
                Assert.Equal(policy.AccessRecheckOnlineTimeout, TimeSpan.FromMinutes(IntuneConstants.DefaultRecheckAccessTimeoutMinutes));
                Assert.Equal(policy.OfflineWipeTimeout, TimeSpan.FromDays(IntuneConstants.DefaultOfflineWipeIntervalDays));

                //Verify Android specific defaults
                Assert.Equal(policy.FileEncryption, ChoiceType.required.ToString());
                Assert.Equal(policy.ScreenCapture, FilterType.allow.ToString());

                client.Android.DeleteMAMPolicy(IntuneClientHelper.AsuHostName, policyName);
            }
        }
        public void ShouldGetMultipleAndroidPolicies()
        {
            using (MockContext context = MockContext.Start("Microsoft.Azure.Management.Intune.Tests.ScenarioTests.PolicyScenarioTests"))
            {
                var    client      = IntuneClientHelper.GetIntuneResourceManagementClient(context);
                string policyName1 = TestContextHelper.GetValueFromTestContext(Guid.NewGuid, Guid.Parse, "IntunePolicy1").ToString();
                string policyName2 = TestContextHelper.GetValueFromTestContext(Guid.NewGuid, Guid.Parse, "IntunePolicy2").ToString();
                try
                {
                    string friendlyName1  = TestUtilities.GenerateName(IntuneConstants.IntuneAndroidPolicy);
                    var    payload1       = DefaultAndroidPolicy.GetPayload(friendlyName1);
                    var    policyCreated1 = client.Android.CreateOrUpdateMAMPolicy(
                        IntuneClientHelper.AsuHostName,
                        policyName1,
                        payload1);

                    string friendlyName2  = TestUtilities.GenerateName(IntuneConstants.IntuneAndroidPolicy);
                    var    payload2       = DefaultAndroidPolicy.GetPayload(friendlyName2);
                    var    policyCreated2 = client.Android.CreateOrUpdateMAMPolicy(
                        IntuneClientHelper.AsuHostName,
                        policyName2,
                        payload2);

                    var policies = client.Android.GetMAMPolicies(IntuneClientHelper.AsuHostName, null).ToList();
                    int cnt      = 0;
                    policies.ForEach(p => { if (p.FriendlyName == friendlyName1 || p.FriendlyName == friendlyName2)
                                            {
                                                cnt++;
                                            }
                                     });
                    Assert.True(2 == cnt, "Less than 2 created policies returned");
                }
                finally
                {
                    client.Android.DeleteMAMPolicy(IntuneClientHelper.AsuHostName, policyName1);
                    client.Android.DeleteMAMPolicy(IntuneClientHelper.AsuHostName, policyName2);
                }
            }
        }