3 // - CAS unit tests for System.CodeDom.Compiler.Executor
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using NUnit.Framework;
33 using System.CodeDom.Compiler;
35 using System.Reflection;
36 using System.Security;
37 using System.Security.Permissions;
38 using System.Security.Policy;
40 using MonoTests.System.CodeDom.Compiler;
42 namespace MonoCasTests.System.CodeDom.Compiler {
46 public class ExecutorCas {
51 if (!SecurityManager.SecurityEnabled)
52 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
56 private TempFileCollection tfc;
57 private ExecutorTest unit;
58 private MethodInfo execWaitWithCapture;
61 public void FixtureSetUp ()
64 tfc = new TempFileCollection ();
65 cmd = "ping"; // available everywhere
67 unit = new ExecutorTest ();
70 // for linkdemands tests
71 MethodInfo[] methods = typeof (Executor).GetMethods ();
72 foreach (MethodInfo mi in methods) {
73 if ((mi.Name == "ExecWaitWithCapture") && (mi.GetParameters ().Length == 4)) {
74 execWaitWithCapture = mi;
81 [FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
82 [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
83 [EnvironmentPermission (SecurityAction.PermitOnly, Unrestricted = true)]
84 public void ReuseUnitTests_PermitOnly ()
86 unit.ExecWaitWithCapture ();
87 unit.ExecWaitWithCapture_CurrentDir ();
88 unit.ExecWaitWithCapture_Token ();
89 unit.ExecWaitWithCapture_Token_CurrentDir ();
93 [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
94 [ExpectedException (typeof (SecurityException))]
95 public void ExecWaitWithCapture_Deny_FileIO ()
97 unit.ExecWaitWithCapture ();
101 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
102 [ExpectedException (typeof (SecurityException))]
103 public void ExecWaitWithCapture_Deny_UnmanagedCode ()
105 unit.ExecWaitWithCapture ();
109 [EnvironmentPermission (SecurityAction.Deny, Unrestricted = true)]
110 [ExpectedException (typeof (SecurityException))]
111 public void ExecWaitWithCapture_Deny_Environment ()
113 unit.ExecWaitWithCapture ();
117 public void LinkDemand_No_Restriction ()
119 Assert.IsNotNull (execWaitWithCapture, "ExecWaitWithCapture");
120 string output = null;
122 Assert.IsNotNull (execWaitWithCapture.Invoke (null, new object[4] { cmd, tfc, output, error }), "invoke");
126 [FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
127 [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
128 [EnvironmentPermission (SecurityAction.PermitOnly, Unrestricted = true)]
129 [ExpectedException (typeof (SecurityException))]
130 public void LinkDemand_PermitOnly ()
132 Assert.IsNotNull (execWaitWithCapture, "ExecWaitWithCapture");
133 string output = null;
135 Assert.IsNotNull (execWaitWithCapture.Invoke (null, new object[4] { cmd, tfc, output, error }), "invoke");
136 // it's not enough, so there's a LinkDemand on the class
140 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
141 [ExpectedException (typeof (SecurityException))]
142 public void LinkDemand_Deny_UnmanagedCode ()
144 // denying anything results in a non unrestricted permission set
145 Assert.IsNotNull (execWaitWithCapture, "ExecWaitWithCapture");
146 string output = null;
148 Assert.IsNotNull (execWaitWithCapture.Invoke (null, new object[4] { cmd, tfc, output, error }), "invoke");
152 [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
153 [ExpectedException (typeof (SecurityException))]
154 public void LinkDemand_Deny_FileIO ()
156 Assert.IsNotNull (execWaitWithCapture, "ExecWaitWithCapture");
157 string output = null;
159 Assert.IsNotNull (execWaitWithCapture.Invoke (null, new object[4] { cmd, tfc, output, error }), "invoke");
163 [EnvironmentPermission (SecurityAction.Deny, Read = "Mono")]
164 [ExpectedException (typeof (SecurityException))]
165 public void LinkDemand_Deny_Environment ()
167 // denying anything results in a non unrestricted permission set
168 Assert.IsNotNull (execWaitWithCapture, "ExecWaitWithCapture");
169 string output = null;
171 Assert.IsNotNull (execWaitWithCapture.Invoke (null, new object[4] { cmd, tfc, output, error }), "invoke");