2005-04-12 Dick Porter <dick@ximian.com>
[mono.git] / mono / tests / cas / linkdemand / noncas4.cs
1 using System;
2 using System.Security;
3 using System.Security.Permissions;
4 using System.Security.Principal;
5 using System.Threading;
6
7 class LinkDemandTest {
8
9         // Note: this should also fail if you replace "me" with your username
10
11         [PrincipalPermission (SecurityAction.LinkDemand, Name="me")]
12         static int LinkDemand () 
13         {
14                 Console.WriteLine ("*1* [this should not print]");
15                 return 1;
16         }
17
18         static int Test ()
19         {
20                 Console.WriteLine ("[this should not print - as JIT will reject the LinkDemand]");
21
22                 GenericIdentity identity = new GenericIdentity ("me");
23                 string[] roles = new string [1] { "mono hacker" };
24                 Thread.CurrentPrincipal = new GenericPrincipal (identity, roles);
25
26                 return LinkDemand ();
27         }
28
29         [STAThread]
30         static int Main (string[] args)
31         {
32                 try {
33                         return Test ();
34                 }
35                 catch (SecurityException se) {
36                         Console.WriteLine ("*0* Expected SecurityException\n{0}", se);
37                         return 0;
38                 }
39                 catch (Exception e) {
40                         Console.WriteLine ("*2* Unexpected Exception\n{0}", e);
41                         return 2;
42                 }
43         }
44 }
45