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

            a.Unrestricted = true;
            EventLogPermission wp = (EventLogPermission)a.CreatePermission();

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

            a.Unrestricted = false;
            wp             = (EventLogPermission)a.CreatePermission();
            Assert.IsFalse(wp.IsUnrestricted(), "!IsUnrestricted");
        }
        public void PermissionState_Bad()
        {
            PermissionState    ps  = (PermissionState)77;
            EventLogPermission elp = new EventLogPermission(ps);

            Assert.IsFalse(elp.IsUnrestricted(), "IsUnrestricted");
        }
        public void Union_None()
        {
            EventLogPermission elp1 = new EventLogPermission(PermissionState.None);

            foreach (EventLogPermissionAccess elpa in AllAccess)
            {
                EventLogPermission elp2 = new EventLogPermission(PermissionState.None);
                elp2.PermissionEntries.Add(new EventLogPermissionEntry(elpa, elpa.ToString()));
                EventLogPermission union = (EventLogPermission)elp1.Union(elp2);
                Assert.IsFalse(union.IsUnrestricted(), "target.IsUnrestricted " + elpa.ToString());
                Assert.AreEqual(1, union.PermissionEntries.Count, "target.Count " + elpa.ToString());

                union = (EventLogPermission)elp2.Union(elp1);
                Assert.IsFalse(union.IsUnrestricted(), "source.IsUnrestricted " + elpa.ToString());
                Assert.AreEqual(1, union.PermissionEntries.Count, "source.Count " + elpa.ToString());
            }
        }
        public void PermissionState_Unrestricted()
        {
            PermissionState    ps  = PermissionState.Unrestricted;
            EventLogPermission elp = new EventLogPermission(ps);

            Assert.AreEqual(0, elp.PermissionEntries.Count, "PermissionEntries");
            Assert.IsTrue(elp.IsUnrestricted(), "IsUnrestricted");

            SecurityElement se = elp.ToXml();

            // only class and version are present
            Assert.AreEqual("true", se.Attribute("Unrestricted"), "Xml-Unrestricted");
            Assert.IsNull(se.Children, "Xml-Children");

            EventLogPermission copy = (EventLogPermission)elp.Copy();

            Assert.IsFalse(Object.ReferenceEquals(elp, copy), "ReferenceEquals");
            Assert.AreEqual(elp.PermissionEntries.Count, copy.PermissionEntries.Count, "copy-PermissionEntries");
            Assert.AreEqual(elp.IsUnrestricted(), copy.IsUnrestricted(), "copy-IsUnrestricted ()");
        }
 public void Union_Self()
 {
     foreach (EventLogPermissionAccess elpa in AllAccess)
     {
         EventLogPermission elp = new EventLogPermission(PermissionState.None);
         elp.PermissionEntries.Add(new EventLogPermissionEntry(elpa, elpa.ToString()));
         EventLogPermission union = (EventLogPermission)elp.Union(elp);
         Assert.IsFalse(union.IsUnrestricted(), "IsUnrestricted " + elpa.ToString());
         Assert.AreEqual(1, union.PermissionEntries.Count, "Count " + elpa.ToString());
     }
 }
        public void Default()
        {
            EventLogPermissionAttribute a = new EventLogPermissionAttribute(SecurityAction.Assert);

            Assert.AreEqual(a.ToString(), a.TypeId.ToString(), "TypeId");
            Assert.IsFalse(a.Unrestricted, "Unrestricted");
            Assert.AreEqual(".", a.MachineName, "MachineName");
            Assert.AreEqual(EventLogPermissionAccess.Write, a.PermissionAccess, "PermissionAccess");
            EventLogPermission sp = (EventLogPermission)a.CreatePermission();

            Assert.IsFalse(sp.IsUnrestricted(), "IsUnrestricted");
        }
Exemple #7
0
        }// CreateDataTable

        protected override void PutValuesinPage()
        {
            // Put in the text for the radio buttons
            m_radUnrestricted.Text             = CResourceStore.GetString("EventLogPermission:GrantUnrestrict");
            m_radGrantFollowingPermission.Text = CResourceStore.GetString("EventLogPermission:GrantFollowing");


            EventLogPermission perm = (EventLogPermission)m_perm;

            CheckUnrestricted(perm);

            if (!perm.IsUnrestricted())
            {
                // Run through the list of socket permissions we have to accept connections
                IEnumerator enumer = perm.PermissionEntries.GetEnumerator();
                while (enumer.MoveNext())
                {
                    EventLogPermissionEntry elpp = (EventLogPermissionEntry)enumer.Current;
                    DataRow newRow;
                    newRow = m_dt.NewRow();

                    newRow["Machine"] = elpp.MachineName;

                    String sAccess = CResourceStore.GetString("None");
                    if ((elpp.PermissionAccess & EventLogPermissionAccess.Audit) == EventLogPermissionAccess.Audit)
                    {
                        sAccess = CResourceStore.GetString("EventLogPermission:Audit");
                    }
                    else if ((elpp.PermissionAccess & EventLogPermissionAccess.Instrument) == EventLogPermissionAccess.Instrument)
                    {
                        sAccess = CResourceStore.GetString("EventLogPermission:Instrument");
                    }
                    else if ((elpp.PermissionAccess & EventLogPermissionAccess.Browse) == EventLogPermissionAccess.Browse)
                    {
                        sAccess = CResourceStore.GetString("EventLogPermission:Browse");
                    }

                    newRow["Access"] = new DataGridComboBoxEntry(sAccess);


                    m_dt.Rows.Add(newRow);
                }
            }

            // We want at least 1 row so it looks pretty
            while (m_dt.Rows.Count < 1)
            {
                AddEmptyRow(m_dt);
            }
        }// PutValuesinPage
        public void Intersect_Unrestricted()
        {
            // Intersection with unrestricted == Copy
            // a. source (this) is unrestricted
            EventLogPermission elp1 = new EventLogPermission(PermissionState.Unrestricted);
            EventLogPermission elp2 = new EventLogPermission(PermissionState.None);

            // 1. Unrestricted N None
            EventLogPermission result = (EventLogPermission)elp1.Intersect(elp2);

            Assert.IsFalse(result.IsUnrestricted(), "(Unrestricted N None).IsUnrestricted");
            Assert.AreEqual(0, result.PermissionEntries.Count, "(Unrestricted N None).Count");

            // 2. None N Unrestricted
            result = (EventLogPermission)elp2.Intersect(elp1);
            Assert.IsFalse(result.IsUnrestricted(), "(None N Unrestricted).IsUnrestricted");
            Assert.AreEqual(0, result.PermissionEntries.Count, "(None N Unrestricted).Count");

            // 3. Unrestricted N Unrestricted
            result = (EventLogPermission)elp1.Intersect(elp1);
            Assert.IsTrue(result.IsUnrestricted(), "(Unrestricted N Unrestricted).IsUnrestricted");
            Assert.AreEqual(0, result.PermissionEntries.Count, "(Unrestricted N Unrestricted).Count");

            // 4. Unrestricted N Entry
            elp2.PermissionEntries.Add(new EventLogPermissionEntry(EventLogPermissionAccess.None, "localhost"));
            result = (EventLogPermission)elp1.Intersect(elp2);
            Assert.IsFalse(result.IsUnrestricted(), "(Unrestricted N Entry).IsUnrestricted");
            Assert.AreEqual(1, result.PermissionEntries.Count, "(Unrestricted N Entry).Count");

            // 5. Entry N Unrestricted
            result = (EventLogPermission)elp2.Intersect(elp1);
            Assert.IsFalse(result.IsUnrestricted(), "(Entry N Unrestricted).IsUnrestricted");
            Assert.AreEqual(1, result.PermissionEntries.Count, "(Entry N Unrestricted).Count");

            // 6. Unrestricted N Unrestricted
            elp1.PermissionEntries.Add(new EventLogPermissionEntry(EventLogPermissionAccess.None, "localhost"));
            result = (EventLogPermission)elp1.Intersect(elp1);
            Assert.IsTrue(result.IsUnrestricted(), "(Unrestricted N Unrestricted).IsUnrestricted");
            Assert.AreEqual(1, result.PermissionEntries.Count, "(Unrestricted N Unrestricted).Count");
        }