public void Unrestricted()
        {
            DnsPermissionAttribute a = new DnsPermissionAttribute(SecurityAction.Assert);

            a.Unrestricted = true;
            DnsPermission dp = (DnsPermission)a.CreatePermission();

            Assert.IsTrue(dp.IsUnrestricted(), "IsUnrestricted");

            a.Unrestricted = false;
            dp             = (DnsPermission)a.CreatePermission();
            Assert.IsFalse(dp.IsUnrestricted(), "!IsUnrestricted");
        }
Ejemplo n.º 2
0
        public void PermissionState_Bad()
        {
            PermissionState ps = (PermissionState)Int32.MinValue;
            DnsPermission   dp = new DnsPermission(ps);

            // no ArgumentException here
            Assert.IsFalse(dp.IsUnrestricted());
        }
Ejemplo n.º 3
0
        public void PermissionState_Unrestricted()
        {
            PermissionState ps = PermissionState.Unrestricted;
            DnsPermission   dp = new DnsPermission(ps);

            Assert.IsTrue(dp.IsUnrestricted(), "IsUnrestricted");

            SecurityElement se = dp.ToXml();

            Assert.AreEqual("true", se.Attribute("Unrestricted"), "Xml-Unrestricted");
            Assert.AreEqual(3, se.Attributes.Count, "Xml-Attributes#");
            Assert.IsNull(se.Children, "Xml-Children");

            DnsPermission copy = (DnsPermission)dp.Copy();

            Assert.IsFalse(Object.ReferenceEquals(dp, copy), "ReferenceEquals");
            Assert.AreEqual(dp.IsUnrestricted(), copy.IsUnrestricted(), "IsUnrestricted ()");
        }
Ejemplo n.º 4
0
        public void PermissionState_None()
        {
            PermissionState ps = PermissionState.None;
            DnsPermission   dp = new DnsPermission(ps);

            Assert.IsFalse(dp.IsUnrestricted(), "IsUnrestricted");

            SecurityElement se = dp.ToXml();

            // only class and version are present
            Assert.AreEqual(2, se.Attributes.Count, "Xml-Attributes#");
            Assert.IsNull(se.Children, "Xml-Children");

            DnsPermission copy = (DnsPermission)dp.Copy();

            Assert.IsFalse(Object.ReferenceEquals(dp, copy), "ReferenceEquals");
            Assert.AreEqual(dp.IsUnrestricted(), copy.IsUnrestricted(), "IsUnrestricted ()");
        }
Ejemplo n.º 5
0
        public void Intersect()
        {
            DnsPermission dpn = new DnsPermission(PermissionState.None);

            Assert.IsNull(dpn.Intersect(null), "None N null");
            Assert.IsNull(dpn.Intersect(dpn), "None N None");

            DnsPermission dpu = new DnsPermission(PermissionState.Unrestricted);

            Assert.IsNull(dpu.Intersect(null), "Unrestricted N null");

            DnsPermission result = (DnsPermission)dpu.Intersect(dpu);

            Assert.IsTrue(result.IsUnrestricted(), "Unrestricted N Unrestricted");

            Assert.IsNull(dpn.Intersect(dpu), "None N Unrestricted");
            Assert.IsNull(dpu.Intersect(dpn), "Unrestricted N None");
        }
// <Snippet1>
    public void useDns()
    {
        // Create a DnsPermission instance.
        DnsPermission permission = new DnsPermission(PermissionState.Unrestricted);

        // Check for permission.
        permission.Demand();
        Console.WriteLine("Attributes and Values of DnsPermission instance :");
        // Print the attributes and values.
        PrintKeysAndValues(permission.ToXml().Attributes);
        // Check the permission state.
        if (permission.IsUnrestricted())
        {
            Console.WriteLine("Overall permissions : Unrestricted");
        }
        else
        {
            Console.WriteLine("Overall permissions : Restricted");
        }
    }
Ejemplo n.º 7
0
        public void Union()
        {
            DnsPermission dpn = new DnsPermission(PermissionState.None);
            DnsPermission dpu = new DnsPermission(PermissionState.Unrestricted);

            DnsPermission result = (DnsPermission)dpn.Union(null);

            Assert.IsFalse(result.IsUnrestricted(), "None U null");

            result = (DnsPermission)dpu.Union(null);
            Assert.IsTrue(result.IsUnrestricted(), "Unrestricted U null");

            result = (DnsPermission)dpn.Union(dpn);
            Assert.IsFalse(result.IsUnrestricted(), "None U None");

            result = (DnsPermission)dpu.Union(dpu);
            Assert.IsTrue(result.IsUnrestricted(), "Unrestricted U Unrestricted");

            result = (DnsPermission)dpn.Union(dpu);
            Assert.IsTrue(result.IsUnrestricted(), "None U Unrestricted");

            result = (DnsPermission)dpu.Union(dpn);
            Assert.IsTrue(result.IsUnrestricted(), "Unrestricted U None");
        }
Ejemplo n.º 8
0
        public void GetStandardPermissionSetLocalIntranetPermissionSetTest()
        {
            // Get a copy of LocalIntranet which is not extended with any same-site permission
            PermissionSet intranetBase = PermissionSetFactory.GetStandardPermissionSet(StandardPermissionSet.LocalIntranet, null);

            // It shouldn't be fully trusted, and should contain a set of well known permissions
            Assert.IsFalse(intranetBase.IsUnrestricted());
            Assert.IsTrue(intranetBase.Count == 8 || intranetBase.Count == 10);

            // We should have SecurityPermission/Execution,Assertion,BindingRedirects
            SecurityPermission baseSecurityPermission = intranetBase.GetPermission(typeof(SecurityPermission)) as SecurityPermission;

            Assert.IsNotNull(baseSecurityPermission);
            Assert.AreEqual(SecurityPermissionFlag.Execution | SecurityPermissionFlag.Assertion | SecurityPermissionFlag.BindingRedirects, baseSecurityPermission.Flags);

            // Unrestricted FileDialogPermission
            FileDialogPermission baseFileDialogPermission = intranetBase.GetPermission(typeof(FileDialogPermission)) as FileDialogPermission;

            Assert.IsNotNull(baseFileDialogPermission);
            Assert.IsTrue(baseFileDialogPermission.IsUnrestricted());

            // IsolatedStorageFilePermission/AssemblyIsolationByUser
            IsolatedStorageFilePermission baseIsostorePermission = intranetBase.GetPermission(typeof(IsolatedStorageFilePermission)) as IsolatedStorageFilePermission;

            Assert.IsNotNull(baseIsostorePermission);
            Assert.AreEqual(IsolatedStorageContainment.AssemblyIsolationByUser, baseIsostorePermission.UsageAllowed);

            // Unrestricted UIPermission
            UIPermission baseUIPermission = intranetBase.GetPermission(typeof(UIPermission)) as UIPermission;

            Assert.IsNotNull(baseUIPermission);
            Assert.IsTrue(baseUIPermission.IsUnrestricted());

            // PrintingPermission/DefaultPrinting
            PrintingPermission basePrintingPermission = intranetBase.GetPermission(typeof(PrintingPermission)) as PrintingPermission;

            Assert.IsNotNull(basePrintingPermission);
            Assert.AreEqual(PrintingPermissionLevel.DefaultPrinting, basePrintingPermission.Level);

            // EnvironmentPermission/Read USERNAME
            EnvironmentPermission baseEnvironmentPermission = intranetBase.GetPermission(typeof(EnvironmentPermission)) as EnvironmentPermission;

            Assert.IsNotNull(baseEnvironmentPermission);
            Assert.AreEqual("USERNAME", baseEnvironmentPermission.GetPathList(EnvironmentPermissionAccess.Read));

            // ReflectionPermission/ReflectionEmit
            ReflectionPermission baseReflectionPermission = intranetBase.GetPermission(typeof(ReflectionPermission)) as ReflectionPermission;

            Assert.IsNotNull(baseReflectionPermission);
            Assert.AreEqual(ReflectionPermissionFlag.ReflectionEmit, baseReflectionPermission.Flags);

            // Unrestricted DNS permission
            DnsPermission baseDnsPermission = intranetBase.GetPermission(typeof(DnsPermission)) as DnsPermission;

            Assert.IsNotNull(baseDnsPermission);
            Assert.IsTrue(baseDnsPermission.IsUnrestricted());

            // Also check for WPF extensions
            MediaPermission baseMediaPermission = intranetBase.GetPermission(typeof(MediaPermission)) as MediaPermission;

            if (baseMediaPermission != null)
            {
                Assert.AreEqual(MediaPermissionAudio.SafeAudio, baseMediaPermission.Audio);
                Assert.AreEqual(MediaPermissionImage.SafeImage, baseMediaPermission.Image);
                Assert.AreEqual(MediaPermissionVideo.SafeVideo, baseMediaPermission.Video);
            }

            WebBrowserPermission baseWebPermission = intranetBase.GetPermission(typeof(WebBrowserPermission)) as WebBrowserPermission;

            if (baseWebPermission != null)
            {
                Assert.AreEqual(WebBrowserPermissionLevel.Safe, baseWebPermission.Level);
            }

            // Now try to extend with a local URL - we should get FileIOPermission
            Url           localUrl = new Url(@"file://c:\windows");
            PermissionSet intranetLocalExtended = PermissionSetFactory.GetStandardPermissionSet(StandardPermissionSet.LocalIntranet, localUrl);

            Assert.IsTrue(intranetBase.IsSubsetOf(intranetLocalExtended));
            Assert.IsFalse(intranetLocalExtended.IsUnrestricted());
            Assert.AreEqual(intranetBase.Count + 1, intranetLocalExtended.Count);

            FileIOPermission filePermission = intranetLocalExtended.GetPermission(typeof(FileIOPermission)) as FileIOPermission;

            Assert.IsNotNull(filePermission);
            Assert.IsFalse(filePermission.IsUnrestricted());

            // Finally, try to extend with a Web URL, which should provide same site web access
            Url           webUrl = new Url("htt://www.microsoft.com/");
            PermissionSet intranetWebExtended = PermissionSetFactory.GetStandardPermissionSet(StandardPermissionSet.LocalIntranet, webUrl);

            Assert.IsTrue(intranetBase.IsSubsetOf(intranetWebExtended));
            Assert.IsFalse(intranetWebExtended.IsUnrestricted());
            Assert.AreEqual(intranetBase.Count + 1, intranetWebExtended.Count);

            WebPermission webPermission = intranetWebExtended.GetPermission(typeof(WebPermission)) as WebPermission;

            Assert.IsNotNull(webPermission);
            Assert.IsFalse(webPermission.IsUnrestricted());
        }