2009-03-11 Zoltan Varga <vargaz@gmail.com>
[mono-debugger.git] / mono / tests / cas / linkdemand / noncas4.cs
blob60f75a35b01720d55eea5eb6c3f318e7e40ed551
1 using System;
2 using System.Security;
3 using System.Security.Permissions;
4 using System.Security.Principal;
5 using System.Threading;
7 class LinkDemandTest {
9 // Note: this should also fail if you replace "me" with your username
11 [PrincipalPermission (SecurityAction.LinkDemand, Name="me")]
12 static int LinkDemand ()
14 Console.WriteLine ("*1* [this should not print]");
15 return 1;
18 static int Test ()
20 Console.WriteLine ("[this should not print - as JIT will reject the LinkDemand]");
22 GenericIdentity identity = new GenericIdentity ("me");
23 string[] roles = new string [1] { "mono hacker" };
24 Thread.CurrentPrincipal = new GenericPrincipal (identity, roles);
26 return LinkDemand ();
29 [STAThread]
30 static int Main (string[] args)
32 try {
33 return Test ();
35 catch (SecurityException se) {
36 Console.WriteLine ("*0* Expected SecurityException\n{0}", se);
37 return 0;
39 catch (Exception e) {
40 Console.WriteLine ("*2* Unexpected Exception\n{0}", e);
41 return 2;