public void Default() { FileIOPermissionAttribute a = new FileIOPermissionAttribute(SecurityAction.Assert); Assert.IsNull(a.Append, "Append"); Assert.IsNull(a.PathDiscovery, "PathDiscovery"); Assert.IsNull(a.Read, "Read"); Assert.IsNull(a.Write, "Write"); #if NET_2_0 Assert.IsNotNull(a.AllFiles, "AllFiles"); Assert.IsNotNull(a.AllLocalFiles, "AllLocalFiles"); Assert.IsNull(a.ChangeAccessControl, "ChangeAccessControl"); Assert.IsNull(a.ViewAccessControl, "ViewAccessControl"); #endif Assert.AreEqual(a.ToString(), a.TypeId.ToString(), "TypeId"); Assert.IsFalse(a.Unrestricted, "Unrestricted"); #if !NET_2_1 FileIOPermission perm = (FileIOPermission)a.CreatePermission(); Assert.AreEqual(FileIOPermissionAccess.NoAccess, perm.AllFiles, "CreatePermission-AllFiles"); Assert.AreEqual(FileIOPermissionAccess.NoAccess, perm.AllLocalFiles, "CreatePermission-AllLocalFiles"); Assert.IsFalse(perm.IsUnrestricted(), "perm-Unrestricted"); #endif }
public void Read() { string filename = Assembly.GetCallingAssembly().Location; FileIOPermissionAttribute attr = new FileIOPermissionAttribute(SecurityAction.Assert); attr.Read = filename; Assert.IsNull(attr.Append, "Append=null"); Assert.IsNull(attr.PathDiscovery, "PathDiscovery=null"); Assert.AreEqual(filename, attr.Read, "Read=Read"); Assert.IsNull(attr.Write, "Write=null"); #if NET_2_0 Assert.IsNotNull(attr.AllFiles, "AllFiles"); Assert.IsNotNull(attr.AllLocalFiles, "AllLocalFiles"); Assert.IsNull(attr.ChangeAccessControl, "ChangeAccessControl"); Assert.IsNull(attr.ViewAccessControl, "ViewAccessControl"); #endif #if !NET_2_1 FileIOPermission p = (FileIOPermission)attr.CreatePermission(); filename = Path.GetFullPath(filename); Assert.IsNull(p.GetPathList(FileIOPermissionAccess.Append), "PathDiscovery=FileIOPermissionAttribute-Append"); Assert.IsNull(p.GetPathList(FileIOPermissionAccess.PathDiscovery), "PathDiscovery=FileIOPermissionAttribute-PathDiscovery"); Assert.AreEqual(filename, p.GetPathList(FileIOPermissionAccess.Read) [0], "PathDiscovery=FileIOPermissionAttribute-Read"); Assert.IsNull(p.GetPathList(FileIOPermissionAccess.Write), "PathDiscovery=FileIOPermissionAttribute-Write"); #endif }
public void Unrestricted() { FileIOPermissionAttribute a = new FileIOPermissionAttribute(SecurityAction.Assert); a.Unrestricted = true; FileIOPermission perm = (FileIOPermission)a.CreatePermission(); Assert.IsTrue(perm.IsUnrestricted(), "CreatePermission.IsUnrestricted"); Assert.AreEqual(FileIOPermissionAccess.AllAccess, perm.AllFiles, "CreatePermission.AllFiles"); Assert.AreEqual(FileIOPermissionAccess.AllAccess, perm.AllLocalFiles, "CreatePermission.AllLocalFiles"); }
public void Write() { string filename = Assembly.GetCallingAssembly().Location; FileIOPermissionAttribute attr = new FileIOPermissionAttribute(SecurityAction.Assert); attr.Write = filename; Assert.IsNull(attr.Append, "Append=null"); Assert.IsNull(attr.PathDiscovery, "PathDiscovery=null"); Assert.IsNull(attr.Read, "Read=null"); Assert.AreEqual(filename, attr.Write, "Write=Write"); FileIOPermission p = (FileIOPermission)attr.CreatePermission(); filename = Path.GetFullPath(filename); Assert.IsNull(p.GetPathList(FileIOPermissionAccess.Append), "PathDiscovery=FileIOPermissionAttribute-Append"); Assert.IsNull(p.GetPathList(FileIOPermissionAccess.PathDiscovery), "PathDiscovery=FileIOPermissionAttribute-PathDiscovery"); Assert.IsNull(p.GetPathList(FileIOPermissionAccess.Read), "PathDiscovery=FileIOPermissionAttribute-Read"); Assert.AreEqual(filename, p.GetPathList(FileIOPermissionAccess.Write) [0], "PathDiscovery=FileIOPermissionAttribute-Write"); }
public void NonC14NPath() { string filename = Path.Combine(Path.GetTempPath(), "test"); filename = Path.Combine(filename, ".."); filename = Path.Combine(filename, "here"); FileIOPermissionAttribute attr = new FileIOPermissionAttribute(SecurityAction.Assert); // attribute class will keep the .. in the path attr.All = filename; Assert.AreEqual(filename, attr.Append, "All=Append"); Assert.AreEqual(filename, attr.PathDiscovery, "All=PathDiscovery"); Assert.AreEqual(filename, attr.Read, "All=Read"); Assert.AreEqual(filename, attr.Write, "All=Write"); // but the permission class will c14n it filename = Path.GetFullPath(filename); FileIOPermission p = (FileIOPermission)attr.CreatePermission(); Assert.AreEqual(filename, p.GetPathList(FileIOPermissionAccess.Append) [0], "All=FileIOPermissionAttribute-Append"); Assert.AreEqual(filename, p.GetPathList(FileIOPermissionAccess.PathDiscovery) [0], "All=FileIOPermissionAttribute-PathDiscovery"); Assert.AreEqual(filename, p.GetPathList(FileIOPermissionAccess.Read) [0], "All=FileIOPermissionAttribute-Read"); Assert.AreEqual(filename, p.GetPathList(FileIOPermissionAccess.Write) [0], "All=FileIOPermissionAttribute-Write"); }