[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / corlib / Test / System.Security.Permissions / UrlIdentityPermissionAttributeTest.cs
blob4cc9c400ae3eae4d7d3d0d671857a428a92cc6c0
1 //
2 // UrlIdentityPermissionAttributeTest.cs -
3 // NUnit Test Cases for UrlIdentityPermissionAttribute
4 //
5 // Author:
6 // Sebastien Pouliot <sebastien@ximian.com>
7 //
8 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using NUnit.Framework;
32 using System;
33 using System.Security;
34 using System.Security.Permissions;
36 namespace MonoTests.System.Security.Permissions {
38 [TestFixture]
39 public class UrlIdentityPermissionAttributeTest {
41 [Test]
42 public void Default ()
44 UrlIdentityPermissionAttribute a = new UrlIdentityPermissionAttribute (SecurityAction.Assert);
45 Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
46 Assert.IsFalse (a.Unrestricted, "Unrestricted");
47 Assert.IsNull (a.Url, "Url");
50 [Test]
51 public void DefaultPermission ()
53 UrlIdentityPermissionAttribute a = new UrlIdentityPermissionAttribute (SecurityAction.Assert);
54 Assert.IsNull (a.Url, "Url");
55 // UrlIdentityPermission would throw a ArgumentNullException for a null URL ...
56 UrlIdentityPermission perm = (UrlIdentityPermission) a.CreatePermission ();
57 // ... but this works ...
58 Assert.IsNotNull (perm, "CreatePermission(null url)");
59 // ... but this doesn't!
60 string url = perm.Url;
61 Assert.AreEqual (String.Empty, url, "Url-2");
64 [Category ("NotWorking")]
65 [Test]
66 public void Action ()
68 UrlIdentityPermissionAttribute a = new UrlIdentityPermissionAttribute (SecurityAction.Assert);
69 Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
70 a.Action = SecurityAction.Demand;
71 Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
72 a.Action = SecurityAction.Deny;
73 Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
74 a.Action = SecurityAction.InheritanceDemand;
75 Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
76 a.Action = SecurityAction.LinkDemand;
77 Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
78 a.Action = SecurityAction.PermitOnly;
79 Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
80 a.Action = SecurityAction.RequestMinimum;
81 Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
82 a.Action = SecurityAction.RequestOptional;
83 Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
84 a.Action = SecurityAction.RequestRefuse;
85 Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
88 [Test]
89 public void Action_Invalid ()
91 UrlIdentityPermissionAttribute a = new UrlIdentityPermissionAttribute ((SecurityAction)Int32.MinValue);
92 // no validation in attribute
95 [Test]
96 public void Url ()
98 UrlIdentityPermissionAttribute a = new UrlIdentityPermissionAttribute (SecurityAction.Assert);
99 a.Url = "mono";
100 Assert.AreEqual ("mono", a.Url, "Url-1");
101 a.Url = null;
102 Assert.IsNull (a.Url, "Url-2");
103 a.Url = "mono again";
104 Assert.AreEqual ("mono again", a.Url, "Url-3");
107 [Test]
108 [Category ("NotWorking")]
109 public void Unrestricted ()
111 UrlIdentityPermissionAttribute a = new UrlIdentityPermissionAttribute (SecurityAction.Assert);
112 a.Unrestricted = true;
113 IPermission perm = a.CreatePermission ();
116 [Test]
117 public void Attributes ()
119 Type t = typeof (UrlIdentityPermissionAttribute);
120 Assert.IsTrue (t.IsSerializable, "IsSerializable");
122 object[] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
123 Assert.AreEqual (1, attrs.Length, "AttributeUsage");
124 AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
125 Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
126 Assert.IsFalse (aua.Inherited, "Inherited");
127 AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method);
128 Assert.AreEqual (at, aua.ValidOn, "ValidOn");