New test.
[mono.git] / mono / tests / cas / linkdemand / noncas3.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         [PrincipalPermission (SecurityAction.LinkDemand, Authenticated=false)]
10         static int LinkDemand () 
11         {
12                 Console.WriteLine ("*0* [this should print]");
13                 return 0;
14         }
15
16         static int Test ()
17         {
18                 Console.WriteLine ("[this should print - as JIT will accept the unauthenticated LinkDemand]");
19
20                 GenericIdentity identity = new GenericIdentity ("me");
21                 string[] roles = new string [1] { "mono hacker" };
22                 Thread.CurrentPrincipal = new GenericPrincipal (identity, roles);
23
24                 return LinkDemand ();
25         }
26
27         [STAThread]
28         static int Main (string[] args)
29         {
30                 try {
31                         return Test ();
32                 }
33                 catch (SecurityException se) {
34                         Console.WriteLine ("*1* Unexpected SecurityException\n{0}", se);
35                         return 1;
36                 }
37                 catch (Exception e) {
38                         Console.WriteLine ("*2* Unexpected Exception\n{0}", e);
39                         return 2;
40                 }
41         }
42 }
43