Author: mprobst
Date: 2007-08-24 12:54:35 -0400 (Fri, 24 Aug 2007)
New Revision: 84810
Added:
trunk/mono/mono/tests/coreclr-security.cs
Modified:
trunk/mono/mono/tests/ChangeLog
trunk/mono/mono/tests/Makefile.am
Log:
2007-08-24 Mark Probst <[EMAIL PROTECTED]>
* coreclr-security.cs, Makefile.am: Added test for CoreCLR
security.
Modified: trunk/mono/mono/tests/ChangeLog
===================================================================
--- trunk/mono/mono/tests/ChangeLog 2007-08-24 16:37:35 UTC (rev 84809)
+++ trunk/mono/mono/tests/ChangeLog 2007-08-24 16:54:35 UTC (rev 84810)
@@ -1,3 +1,8 @@
+2007-08-24 Mark Probst <[EMAIL PROTECTED]>
+
+ * coreclr-security.cs, Makefile.am: Added test for CoreCLR
+ security.
+
2007-08-21 Massimiliano Mantione <[EMAIL PROTECTED]>
* bug-81466.il, bug-81466-lib.il, Makefile.am:
Modified: trunk/mono/mono/tests/Makefile.am
===================================================================
--- trunk/mono/mono/tests/Makefile.am 2007-08-24 16:37:35 UTC (rev 84809)
+++ trunk/mono/mono/tests/Makefile.am 2007-08-24 16:54:35 UTC (rev 84810)
@@ -12,9 +12,11 @@
with_mono_path = MONO_PATH=$(mcs_topdir)/class/lib/default
with_mono_path2 = MONO_PATH=$(mcs_topdir)/class/lib/net_2_0
+with_mono_path21 = MONO_PATH=$(mcs_topdir)/class/lib/net_2_1
RUNTIME = $(with_mono_path) $(top_builddir)/runtime/mono-wrapper
RUNTIME2 = $(with_mono_path2) $(top_builddir)/runtime/mono-wrapper
+RUNTIME21 = $(with_mono_path21) $(top_builddir)/runtime/mono-wrapper
MKBUNDLE = \
PKG_CONFIG_PATH=$(top_builddir):$(PKG_CONFIG_PATH) \
@@ -22,6 +24,7 @@
MCS = $(RUNTIME) $(mcs_topdir)/class/lib/default/mcs.exe -unsafe -nowarn:0162
-nowarn:0168 -nowarn:0219
GMCS = $(RUNTIME2) $(mcs_topdir)/class/lib/net_2_0/gmcs.exe -unsafe
-nowarn:0162 -nowarn:0168 -nowarn:0219
+SMCS = $(RUNTIME21) $(mcs_topdir)/class/lib/net_2_1/smcs.exe -unsafe
-nowarn:0162 -nowarn:0168 -nowarn:0219
ILASM = $(RUNTIME) $(mcs_topdir)/class/lib/default/ilasm.exe
ILASM2 = $(RUNTIME2) $(mcs_topdir)/class/lib/net_2_0/ilasm.exe
@@ -338,6 +341,10 @@
endif
endif
+if INSTALL_2_1
+test : test-coreclr-security
+endif
+
TestDriver.dll:
$(MCS) -target:library -out:$@ $(srcdir)/../mini/TestDriver.cs
@@ -544,6 +551,15 @@
test-bug-81466: bug-81466.exe bug-81466-lib.dll
$(RUNTIME) bug-81466.exe
+if INSTALL_2_1
+EXTRA_DIST += coreclr-security.cs
+coreclr-security.exe : coreclr-security.cs
+ $(SMCS) -out:coreclr-security.exe $(srcdir)/coreclr-security.cs
+
+test-coreclr-security : coreclr-security.exe
+ $(RUNTIME21) --security=core-clr-test coreclr-security.exe
+endif
+
# Useful if mono is compiled with --enable-shared=no
patch-libtool:
cp "../../libtool" .
Added: trunk/mono/mono/tests/coreclr-security.cs
===================================================================
--- trunk/mono/mono/tests/coreclr-security.cs 2007-08-24 16:37:35 UTC (rev
84809)
+++ trunk/mono/mono/tests/coreclr-security.cs 2007-08-24 16:54:35 UTC (rev
84810)
@@ -0,0 +1,250 @@
+using System.Security;
+using System;
+using System.Runtime.InteropServices;
+using System.Reflection;
+
+[SecurityCriticalAttribute]
+public class CClass
+{
+ public CClass ()
+ {
+ //Console.WriteLine ("c ctor");
+ }
+
+ public virtual void Method ()
+ {
+ //Console.WriteLine ("c class");
+ }
+
+ public static void StaticMethod ()
+ {
+ //Console.WriteLine ("c class static");
+ }
+}
+
+[SecuritySafeCriticalAttribute]
+public class SCClass
+{
+ public SCClass ()
+ {
+ //Console.WriteLine ("sc ctor");
+ }
+
+ public virtual void Method ()
+ {
+ //Console.WriteLine ("sc class");
+ CClass cc = new CClass ();
+ cc.Method ();
+ }
+}
+
+public class SCDevClass : SCClass
+{
+ public SCDevClass ()
+ {
+ Test.error ("safe-critical-derived class instantiated");
+ }
+
+ public override void Method ()
+ {
+ //base.Method ();
+ Test.error ("safe-critical-derived method called");
+ }
+}
+
+public class CMethodClass
+{
+ public CMethodClass ()
+ {
+ //Console.WriteLine ("cmethod ctor");
+ }
+
+ [SecurityCriticalAttribute]
+ public virtual void Method ()
+ {
+ //Console.WriteLine ("cmethod");
+ }
+}
+
+public class CMethodDevClass : CMethodClass
+{
+ public CMethodDevClass ()
+ {
+ Test.error ("critical-derived constructor called");
+ }
+
+ public override void Method ()
+ {
+ //base.Method();
+ Test.error ("critical-derived method called");
+ }
+}
+
+public interface CMethodInterface {
+ [SecurityCriticalAttribute]
+ void Method ();
+}
+
+public class CInterfaceClass : CMethodInterface {
+ public CInterfaceClass () { }
+
+ public void Method ()
+ {
+ Test.error ("security-critical-interface-derived method
called");
+ }
+}
+
+[SecurityCriticalAttribute]
+public class CriticalClass {
+
+ public class NestedClassInsideCritical {
+
+ static public void Method ()
+ {
+ Test.error ("critical inner class method called");
+ }
+ }
+}
+
+public delegate void MethodDelegate ();
+
+public class Test
+{
+ static bool haveError = false;
+
+ public static void error (string text)
+ {
+ Console.WriteLine (text);
+ haveError = true;
+ }
+
+ [SecurityCriticalAttribute]
+ static void CMethod ()
+ {
+ //Console.WriteLine ("c");
+ }
+
+ [SecuritySafeCriticalAttribute]
+ static void SCMethod ()
+ {
+ //Console.WriteLine ("sc");
+ CMethod ();
+ }
+
+ static void doSCDev ()
+ {
+ SCDevClass scdev = new SCDevClass ();
+ scdev.Method ();
+ }
+
+ static void doCMethodDev ()
+ {
+ CMethodDevClass cmdev = new CMethodDevClass ();
+ error ("critical-derived object instantiated");
+ cmdev.Method ();
+ Console.WriteLine ("critical-derived method called");
+ }
+
+ static void doSCInterfaceDev ()
+ {
+ CMethodInterface mi = new CInterfaceClass ();
+ error ("safe-critical-interface-derived object instantiated");
+ mi.Method ();
+ error ("safe-critical-interface-derived method called");
+ }
+
+ /*
+ static unsafe void unsafeMethod ()
+ {
+ byte *p = null;
+ error ("unsafe method called");
+ }
+ */
+
+ [SecurityCriticalAttribute]
+ public static void ReflectionCMethod ()
+ {
+ error ("method called via reflection");
+ }
+
+ [DllImport ("/lib64/libc.so.6")]
+ static extern int getpid ();
+
+ public static int Main ()
+ {
+ SCMethod ();
+
+ try {
+ CMethod ();
+ error ("static critical method called");
+ } catch (MethodAccessException) {
+ }
+
+ SCClass sc = new SCClass ();
+ sc.Method ();
+
+ try {
+ CClass c = new CClass (); // Illegal
+ error ("critical object instantiated");
+ c.Method (); // Illegal
+ error ("critical method called");
+ } catch (MethodAccessException) {
+ }
+
+ try {
+ doSCDev ();
+ error ("security-critical-derived class error");
+ } catch (TypeLoadException) {
+ }
+
+ try {
+ doCMethodDev ();
+ } catch (TypeLoadException) {
+ }
+
+ try {
+ getpid ();
+ error ("pinvoke called");
+ } catch (MethodAccessException) {
+ }
+
+ try {
+ MethodDelegate md = new MethodDelegate
(CClass.StaticMethod);
+ md ();
+ error ("critical method called via delegate");
+ } catch (MethodAccessException) {
+ }
+
+ try {
+ CriticalClass.NestedClassInsideCritical.Method ();
+ } catch (MethodAccessException) {
+ }
+
+ try {
+ doSCInterfaceDev ();
+ } catch (TypeLoadException) {
+ }
+
+ /*
+ try {
+ unsafeMethod ();
+ } catch (VerificationException) {
+ }
+
+ try {
+ Type type = Type.GetType ("Test");
+ MethodInfo method = type.GetMethod
("ReflectionCMethod");
+
+ method.Invoke(null, null);
+ } catch (MethodAccessException) {
+ }
+ */
+
+ //Console.WriteLine ("ok");
+
+ if (haveError)
+ return 1;
+
+ return 0;
+ }
+}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches