Переглянути джерело

svn path=/trunk/mono/; revision=41835

Sebastien Pouliot 21 роки тому
батько
коміт
e80b099f7d

+ 6 - 3
mono/tests/cas/demand/Makefile

@@ -3,13 +3,16 @@ CSCOMPILE = mcs --debug
 PROFILE = net_1_1
 
 all:	pinvoke1.exe pinvoke2.exe pinvoke3.exe \
-	sucs1.exe sucs2.exe sucs3.exe sucs4.exe 
+	sucs1.exe sucs2.exe sucs3.exe sucs4.exe \
+	selfassert.exe selfdeny.exe selfpermit.exe
 
 aot:	pinvoke1.exe.so pinvoke2.exe.so pinvoke3.exe.so \
-	sucs1.exe.so sucs2.exe.so sucs3.exe.so sucs4.exe.so 
+	sucs1.exe.so sucs2.exe.so sucs3.exe.so sucs4.exe.so \
+	selfassert.exe.so selfdeny.exe.so selfpermit.exe.so
 
 FULLTRUST_TEST_FILES = pinvoke1 pinvoke2 pinvoke3 \
-	sucs1 sucs2 sucs3 sucs4
+	sucs1 sucs2 sucs3 sucs4 \
+	selfassert selfdeny selfpermit
 
 UNHANDLED_TEST_FILES = 
 

+ 14 - 0
mono/tests/cas/demand/README

@@ -27,3 +27,17 @@ sucs4.cs	Call native code with [SUCS] attributes at both class and
 Notes
 - With Mono runtime the native function getuid is called in libc
 - With MS runtime the native function GetTickCount is called in kernel32.dll
+
+
+** Self
+
+Stack walk starts at the caller frame - i.e. the current frame is ignored. The
+self*.cs tests ensure that the walk starts at the right frame (or at least 
+that it ignore the caller frame).
+
+selfassert.cs	Deny on caller, Assert and Demand on callee. Assert is 
+		ignored, Demand is executed and fail on caller's Deny.
+selfdeny.cs	Deny and Demand on the same frame. Deny is ignored. Demand is
+		executed (stack walk).
+selfpermit.cs	PermitOnly Unmanaged, Demand ControlAppDomain. PermitOnly is
+		ignored and Demand (for ControlAppDomain) succeed.

+ 28 - 0
mono/tests/cas/demand/selfassert.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Security;
+using System.Security.Permissions;
+
+public class Program {
+
+	[SecurityPermission (SecurityAction.Assert, UnmanagedCode=true)]
+	[SecurityPermission (SecurityAction.Demand, UnmanagedCode=true)]
+	static int Test ()
+	{
+		return 1;
+	}
+
+	[SecurityPermission (SecurityAction.Deny, UnmanagedCode=true)]
+	static int Main ()
+	{
+		int result = 2;
+		try {
+			result = Test ();
+			Console.WriteLine ("*1* Unexpected call to Test");
+		}
+		catch (SecurityException se) {
+			result = 0;
+			Console.WriteLine ("*0* Expected SecurityException\n{0}", se);
+		}
+		return result;
+	}
+}

+ 18 - 0
mono/tests/cas/demand/selfdeny.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Security.Permissions;
+
+public class Program {
+
+	[SecurityPermission (SecurityAction.Deny, UnmanagedCode=true)]
+	[SecurityPermission (SecurityAction.Demand, UnmanagedCode=true)]
+	static int Test ()
+	{
+		Console.WriteLine ("*0* Expected call to Test()");
+		return 0;
+	}
+
+	static int Main ()
+	{
+		return Test ();
+	}
+}

+ 19 - 0
mono/tests/cas/demand/selfpermit.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Security;
+using System.Security.Permissions;
+
+public class Program {
+
+	[SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode=true)]
+	[SecurityPermission (SecurityAction.Demand, ControlAppDomain=true)]
+	static int Test ()
+	{
+		Console.WriteLine ("*0* Expected call to Test()");
+		return 0;
+	}
+
+	static int Main ()
+	{
+		return Test ();
+	}
+}