2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / corlib / Test / System.Security.Permissions / StrongNameIdentityPermissionTest.cs
1 //
2 // StrongNameIdentityPermissionTest.cs -
3 //      NUnit Test Cases for StrongNameIdentityPermission
4 //
5 // Author:
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
9 //
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:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
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.
28 //
29
30 using NUnit.Framework;
31 using System;
32 using System.Security;
33 using System.Security.Permissions;
34
35 namespace MonoTests.System.Security.Permissions {
36
37         [TestFixture]
38         public class StrongNameIdentityPermissionTest {
39
40                 static byte[] ecma = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
41
42                 [Test]
43                 public void PermissionStateNone ()
44                 {
45                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None);
46                         Assert.AreEqual (String.Empty, snip.Name, "Name");
47                         Assert.IsNull (snip.PublicKey, "PublicKey");
48                         Assert.AreEqual ("0.0", snip.Version.ToString (), "Version");
49
50                         SecurityElement se = snip.ToXml ();
51 #if NET_2_0
52                         Assert.IsNull (se.Attribute ("Name"), "Xml-Name");
53                         Assert.IsNull (se.Attribute ("AssemblyVersion"), "Xml-AssemblyVersion");
54 #else
55                         Assert.AreEqual (String.Empty, se.Attribute ("Name"), "Xml-Name");
56                         Assert.AreEqual ("0.0", se.Attribute ("AssemblyVersion"), "Xml-AssemblyVersion");
57 #endif
58                         Assert.IsNull (se.Attribute ("PublicKeyBlob"), "Xml-PublicKeyBlob");
59
60                         // because Name == String.Empty, which is illegal using the other constructor
61                         StrongNameIdentityPermission copy = (StrongNameIdentityPermission) snip.Copy ();
62                         Assert.AreEqual (String.Empty, copy.Name, "Copy-Name");
63 #if NET_2_0
64                         // Strangely once copied the Name becomes equals to String.Empty in 2.0 [FDBK19351]
65                         Assert.IsNull (se.Attribute ("AssemblyVersion"), "Copy-Version");
66 #else
67                         Assert.AreEqual ("0.0", copy.Version.ToString (), "Copy-Version");
68 #endif
69                         Assert.IsNull (copy.PublicKey, "Copy-PublicKey");
70                 }
71 #if NET_2_0
72                 [Test]
73                 public void PermissionStateUnrestricted ()
74                 {
75                         // In 2.0 Unrestricted are permitted for identity permissions
76                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.Unrestricted);
77                         Assert.AreEqual (String.Empty, snip.Name, "Name");
78                         Assert.IsNull (snip.PublicKey, "PublicKey");
79                         Assert.AreEqual ("0.0", snip.Version.ToString (), "Version");
80                         SecurityElement se = snip.ToXml ();
81                         Assert.IsNull (se.Attribute ("Name"), "Xml-Name");
82                         Assert.IsNull (se.Attribute ("PublicKeyBlob"), "Xml-PublicKeyBlob");
83                         Assert.IsNull (se.Attribute ("AssemblyVersion"), "Xml-AssemblyVersion");
84                         StrongNameIdentityPermission copy = (StrongNameIdentityPermission)snip.Copy ();
85                         // Strangely once copied the Name becomes equals to String.Empty in 2.0 [FDBK19351]
86                         Assert.AreEqual (String.Empty, copy.Name, "Copy-Name");
87                         Assert.IsNull (copy.PublicKey, "Copy-PublicKey");
88                         Assert.IsNull (se.Attribute ("AssemblyVersion"), "Copy-Version");
89                         // and they aren't equals to None
90                         Assert.IsFalse (snip.Equals (new StrongNameIdentityPermission (PermissionState.None)));
91                 }
92 #else
93                 [Test]
94                 [ExpectedException (typeof (ArgumentException))]
95                 public void PermissionStateUnrestricted ()
96                 {
97                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.Unrestricted);
98                 }
99 #endif
100                 [Test]
101                 [ExpectedException (typeof (ArgumentException))]
102                 public void PermissionStateInvalid ()
103                 {
104                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission ((PermissionState)2);
105                 }
106
107                 [Test]
108                 [ExpectedException (typeof (ArgumentNullException))]
109                 public void StrongNameIdentityPermission_BlobNull ()
110                 {
111                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (null, "mono", new Version (0,0));
112                 }
113
114                 [Test]
115                 public void StrongNameIdentityPermission_NameNull ()
116                 {
117                         StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
118                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, null, new Version (1, 2));
119                         Assert.IsNull (snip.Name, "Name");
120                         Assert.AreEqual ("00000000000000000400000000000000", snip.PublicKey.ToString (), "PublicKey");
121                         Assert.AreEqual ("1.2", snip.Version.ToString (), "Version");
122
123                         SecurityElement se = snip.ToXml ();
124                         Assert.IsNull (se.Attribute ("Name"), "Xml-Name");
125                         Assert.AreEqual ("00000000000000000400000000000000", se.Attribute ("PublicKeyBlob"), "Xml-PublicKeyBlob");
126                         Assert.AreEqual ("1.2", se.Attribute ("AssemblyVersion"), "Xml-AssemblyVersion");
127
128                         StrongNameIdentityPermission copy = (StrongNameIdentityPermission)snip.Copy ();
129                         Assert.IsNull (se.Attribute ("Name"), "Copy-Name");
130                         Assert.AreEqual ("00000000000000000400000000000000", se.Attribute ("PublicKeyBlob"), "Copy-PublicKeyBlob");
131                         Assert.AreEqual ("1.2", se.Attribute ("AssemblyVersion"), "Copy-AssemblyVersion");
132                 }
133
134                 [Test]
135 #if NET_2_0
136                 [ExpectedException (typeof (ArgumentException))]
137 #endif
138                 public void StrongNameIdentityPermission_NameEmpty ()
139                 {
140                         StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
141                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, String.Empty, new Version (1, 2));
142 #if !NET_2_0
143                         // TODO
144 #endif
145                 }
146
147                 [Test]
148                 public void StrongNameIdentityPermission_VersionNull ()
149                 {
150                         StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
151                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", null);
152                         Assert.AreEqual ("mono", snip.Name, "Name");
153                         Assert.AreEqual ("00000000000000000400000000000000", snip.PublicKey.ToString (), "PublicKey");
154                         Assert.IsNull (snip.Version, "Version");
155
156                         SecurityElement se = snip.ToXml ();
157                         Assert.AreEqual ("mono", se.Attribute ("Name"), "Xml-Name");
158                         Assert.AreEqual ("00000000000000000400000000000000", se.Attribute ("PublicKeyBlob"), "Xml-PublicKeyBlob");
159                         Assert.IsNull (se.Attribute ("AssemblyVersion"), "Xml-AssemblyVersion");
160
161                         StrongNameIdentityPermission copy = (StrongNameIdentityPermission)snip.Copy ();
162                         Assert.AreEqual ("mono", se.Attribute ("Name"), "Copy-Name");
163                         Assert.AreEqual ("00000000000000000400000000000000", se.Attribute ("PublicKeyBlob"), "Copy-PublicKeyBlob");
164                         Assert.IsNull (se.Attribute ("AssemblyVersion"), "Copy-AssemblyVersion");
165                 }
166
167                 [Test]
168                 public void StrongNameIdentityPermission_All ()
169                 {
170                         StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
171                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4));
172                         Assert.AreEqual ("mono", snip.Name, "Name");
173                         Assert.AreEqual ("00000000000000000400000000000000", snip.PublicKey.ToString (), "PublicKey");
174                         Assert.AreEqual ("1.2.3.4", snip.Version.ToString (), "Version");
175
176                         SecurityElement se = snip.ToXml ();
177                         Assert.AreEqual ("mono", se.Attribute ("Name"), "Xml-Name");
178                         Assert.AreEqual ("00000000000000000400000000000000", se.Attribute ("PublicKeyBlob"), "Xml-PublicKeyBlob");
179                         Assert.AreEqual ("1.2.3.4", se.Attribute ("AssemblyVersion"), "Xml-AssemblyVersion");
180
181                         StrongNameIdentityPermission copy = (StrongNameIdentityPermission)snip.Copy ();
182                         Assert.AreEqual ("mono", se.Attribute ("Name"), "Copy-Name");
183                         Assert.AreEqual ("00000000000000000400000000000000", se.Attribute ("PublicKeyBlob"), "Copy-PublicKeyBlob");
184                         Assert.AreEqual ("1.2.3.4", se.Attribute ("AssemblyVersion"), "Copy-AssemblyVersion");
185                 }
186
187                 [Test]
188                 public void Name ()
189                 {
190                         StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
191                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4));
192                         Assert.AreEqual ("mono", snip.Name, "Name-1");
193                         snip.Name = null;
194                         Assert.IsNull (snip.Name, "Name-2");
195                         snip.Name = "mono";
196                         Assert.AreEqual ("mono", snip.Name, "Name-3");
197                 }
198
199                 [Test]
200 #if NET_2_0
201                 [ExpectedException (typeof (ArgumentException))]
202 #endif
203                 public void Name_Empty ()
204                 {
205                         StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
206                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4));
207                         snip.Name = String.Empty;
208 #if !NET_2_0
209                         Assert.AreEqual (String.Empty, snip.Name, "Name");
210 #endif
211                 }
212
213                 [Test]
214                 [ExpectedException (typeof (ArgumentNullException))]
215                 public void PublicKey_Null ()
216                 {
217                         StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
218                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4));
219                         snip.PublicKey = null;
220                 }
221
222                 [Test]
223                 public void Version ()
224                 {
225                         StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
226                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4));
227                         Assert.AreEqual ("1.2.3.4", snip.Version.ToString (), "Version-1");
228                         snip.Version = null;
229                         Assert.IsNull (snip.Version, "Version-2");
230                         snip.Version = new Version (1, 2, 3);
231                         Assert.AreEqual ("1.2.3", snip.Version.ToString (), "Version-3");
232                 }
233
234                 [Test]
235                 public void Copy_NameEmpty ()
236                 {
237                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None);
238                         snip.PublicKey = new StrongNamePublicKeyBlob (ecma);
239                         snip.Version = new Version ("1.2.3.4");
240
241                         // because Name == String.Empty, which is illegal using the other constructor
242                         // but (somewhat) required to copy the two other informations
243                         StrongNameIdentityPermission copy = (StrongNameIdentityPermission)snip.Copy ();
244 #if NET_2_0
245                         Assert.IsTrue (copy.Equals (snip), "Equals");
246 #else
247                         Assert.IsFalse (copy.Equals (snip), "Equals");
248 #endif
249                 }
250
251                 private void Compare (StrongNameIdentityPermission p1, StrongNameIdentityPermission p2, string prefix)
252                 {
253                         Assert.AreEqual (p1.Name, p2.Name, prefix + ".Name");
254                         Assert.AreEqual (p1.PublicKey, p2.PublicKey, prefix + ".PublicKey");
255                         Assert.AreEqual (p1.Version, p2.Version, prefix + ".Version");
256                         Assert.IsFalse (Object.ReferenceEquals (p1, p2), "ReferenceEquals");
257                 }
258
259                 [Test]
260                 public void Intersect ()
261                 {
262                         StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
263                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4));
264
265                         StrongNameIdentityPermission intersect = (StrongNameIdentityPermission)snip.Intersect (null);
266                         Assert.IsNull (intersect, "snip N null");
267
268                         StrongNameIdentityPermission empty = new StrongNameIdentityPermission (PermissionState.None);
269                         intersect = (StrongNameIdentityPermission)snip.Intersect (empty);
270 #if NET_2_0
271                         Assert.IsNull (intersect, "snip N empty");
272 #else
273                         Compare (empty, intersect, "snip U empty");
274 #endif
275                         intersect = (StrongNameIdentityPermission)snip.Intersect (snip);
276                         Compare (snip, intersect, "snip U snip");
277
278                         StrongNameIdentityPermission samePk = new StrongNameIdentityPermission (blob, "novell", new Version (1, 2));
279                         intersect = (StrongNameIdentityPermission)snip.Intersect (samePk);
280                         Assert.IsNull (intersect, "(snip N samePk)");
281                         // strange, I would have expected a SNIP with the same public key...
282                 }
283
284                 [Test]
285 #if NET_2_0
286                 [ExpectedException (typeof (ArgumentException))]
287 #endif
288                 public void Intersect_DifferentPermissions ()
289                 {
290                         StrongNameIdentityPermission a = new StrongNameIdentityPermission (PermissionState.None);
291                         SecurityPermission b = new SecurityPermission (PermissionState.None);
292                         Assert.IsNull (a.Intersect (b));
293                 }
294
295                 [Test]
296                 public void IsSubsetOf ()
297                 {
298                         StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
299                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4));
300                         Assert.IsFalse (snip.IsSubsetOf (null), "snip.IsSubsetOf (null)");
301
302                         StrongNameIdentityPermission empty = new StrongNameIdentityPermission (PermissionState.None);
303                         Assert.IsTrue (empty.IsSubsetOf (null), "empty.IsSubsetOf (null)");
304                 }
305
306                 [Test]
307                 [ExpectedException (typeof (ArgumentException))]
308                 public void IsSubsetOf_DifferentPermissions ()
309                 {
310                         StrongNameIdentityPermission a = new StrongNameIdentityPermission (PermissionState.None);
311                         SecurityPermission b = new SecurityPermission (PermissionState.None);
312                         a.IsSubsetOf (b);
313                 }
314
315                 [Test]
316                 public void Union ()
317                 {
318                         StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
319                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4));
320
321                         StrongNameIdentityPermission union = (StrongNameIdentityPermission)snip.Union (null);
322                         Compare (snip, union, "snip U null");
323
324                         StrongNameIdentityPermission empty = new StrongNameIdentityPermission (PermissionState.None);
325                         union = (StrongNameIdentityPermission)snip.Union (empty);
326                         Compare (snip, union, "snip U empty");
327
328                         union = (StrongNameIdentityPermission)snip.Union (snip);
329                         Compare (snip, union, "snip U snip");
330
331                         // note: can't be tested with PermissionState.Unrestricted
332
333                         StrongNameIdentityPermission samePk = new StrongNameIdentityPermission (blob, null, null);
334                         union = (StrongNameIdentityPermission)snip.Union (samePk);
335 #if !NET_2_0
336                         // can't compare the properties with multiple entries
337                         Compare (snip, union, "snip U samePk");
338 #endif
339                         Assert.IsTrue (snip.IsSubsetOf (union), "snip.IsSubsetOf (union)");
340
341                         union = (StrongNameIdentityPermission)samePk.Union (snip);
342 #if !NET_2_0
343                         // can't compare the properties with multiple entries
344                         Compare (snip, union, "samePk U snip");
345 #endif
346                         Assert.IsTrue (samePk.IsSubsetOf (union), "snip.IsSubsetOf (union)");
347                 }
348
349                 [Test]
350                 public void Union_DifferentPk ()
351                 {
352                         StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
353                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4));
354                         StrongNamePublicKeyBlob blob2 = new StrongNamePublicKeyBlob (new byte [16]);
355                         StrongNameIdentityPermission diffPk = new StrongNameIdentityPermission (blob2, "mono", new Version (1, 2, 3, 4));
356                         StrongNameIdentityPermission result = (StrongNameIdentityPermission) snip.Union (diffPk);
357 #if NET_2_0
358                         Assert.IsNotNull (result, "DifferentPk");
359                         // new XML format is used to contain more than one site
360                         SecurityElement se = result.ToXml ();
361                         Assert.AreEqual (2, se.Children.Count, "Childs");
362                         Assert.AreEqual ("00000000000000000400000000000000", (se.Children [0] as SecurityElement).Attribute ("PublicKeyBlob"), "Blob#1");
363                         Assert.AreEqual ("00000000000000000000000000000000", (se.Children [1] as SecurityElement).Attribute ("PublicKeyBlob"), "Blob#2");
364                         // strangely it is still versioned as 'version="1"'.
365                         Assert.AreEqual ("1", se.Attribute ("version"), "Version");
366 #endif
367                 }
368
369                 [Test]
370                 public void Union_SamePublicKey_DifferentName ()
371                 {
372                         StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
373                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4));
374                         StrongNameIdentityPermission diffName = new StrongNameIdentityPermission (blob, "novell", null);
375                         StrongNameIdentityPermission result = (StrongNameIdentityPermission) snip.Union (diffName);
376 #if NET_2_0
377                         Assert.IsNotNull (result, "DifferentName");
378                         // new XML format is used to contain more than one site
379                         SecurityElement se = result.ToXml ();
380                         Assert.AreEqual (2, se.Children.Count, "Childs");
381                         Assert.AreEqual ("mono", (se.Children [0] as SecurityElement).Attribute ("Name"), "Name#1");
382                         Assert.AreEqual ("novell", (se.Children [1] as SecurityElement).Attribute ("Name"), "Name#2");
383                         // strangely it is still versioned as 'version="1"'.
384                         Assert.AreEqual ("1", se.Attribute ("version"), "Version");
385 #endif
386                 }
387
388                 [Test]
389                 public void Union_SamePublicKey_DifferentVersion ()
390                 {
391                         StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob (ecma);
392                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (blob, "mono", new Version (1, 2, 3, 4));
393                         StrongNameIdentityPermission diffVersion = new StrongNameIdentityPermission (blob, null, new Version (1, 2));
394                         StrongNameIdentityPermission result = (StrongNameIdentityPermission) snip.Union (diffVersion);
395 #if NET_2_0
396                         Assert.IsNotNull (result, "DifferentVersion");
397                         // new XML format is used to contain more than one site
398                         SecurityElement se = result.ToXml ();
399                         Assert.AreEqual (2, se.Children.Count, "Childs");
400                         Assert.AreEqual ("1.2.3.4", (se.Children [0] as SecurityElement).Attribute ("AssemblyVersion"), "AssemblyVersion#1");
401                         Assert.AreEqual ("1.2", (se.Children [1] as SecurityElement).Attribute ("AssemblyVersion"), "AssemblyVersion#2");
402                         // strangely it is still versioned as 'version="1"'.
403                         Assert.AreEqual ("1", se.Attribute ("version"), "Version");
404 #endif
405                 }
406
407                 [Test]
408                 [ExpectedException (typeof (ArgumentException))]
409                 public void Union_DifferentPermissions ()
410                 {
411                         StrongNameIdentityPermission a = new StrongNameIdentityPermission (PermissionState.None);
412                         SecurityPermission b = new SecurityPermission (PermissionState.None);
413                         a.Union (b);
414                 }
415
416                 [Test]
417                 [ExpectedException (typeof (ArgumentNullException))]
418                 public void FromXml_Null ()
419                 {
420                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None);
421                         snip.FromXml (null);
422                 }
423
424                 [Test]
425                 [ExpectedException (typeof (ArgumentException))]
426                 public void FromXml_WrongTag ()
427                 {
428                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None);
429                         SecurityElement se = snip.ToXml ();
430                         se.Tag = "IMono";
431                         snip.FromXml (se);
432                 }
433
434                 [Test]
435                 [ExpectedException (typeof (ArgumentException))]
436                 public void FromXml_WrongTagCase ()
437                 {
438                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None);
439                         SecurityElement se = snip.ToXml ();
440                         se.Tag = "IPERMISSION"; // instead of IPermission
441                         snip.FromXml (se);
442                 }
443
444                 [Test]
445                 public void FromXml_WrongClass ()
446                 {
447                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None);
448                         SecurityElement se = snip.ToXml ();
449
450                         SecurityElement w = new SecurityElement (se.Tag);
451                         w.AddAttribute ("class", "Wrong" + se.Attribute ("class"));
452                         w.AddAttribute ("version", se.Attribute ("version"));
453                         snip.FromXml (w);
454                         // doesn't care of the class name at that stage
455                         // anyway the class has already be created so...
456                 }
457
458                 [Test]
459                 public void FromXml_NoClass ()
460                 {
461                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None);
462                         SecurityElement se = snip.ToXml ();
463
464                         SecurityElement w = new SecurityElement (se.Tag);
465                         w.AddAttribute ("version", se.Attribute ("version"));
466                         snip.FromXml (w);
467                         // doesn't even care of the class attribute presence
468                 }
469
470                 [Test]
471                 [ExpectedException (typeof (ArgumentException))]
472                 public void FromXml_WrongVersion ()
473                 {
474                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None);
475                         SecurityElement se = snip.ToXml ();
476                         se.Attributes.Remove ("version");
477                         se.Attributes.Add ("version", "2");
478                         snip.FromXml (se);
479                 }
480
481                 [Test]
482                 public void FromXml_NoVersion ()
483                 {
484                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None);
485                         SecurityElement se = snip.ToXml ();
486
487                         SecurityElement w = new SecurityElement (se.Tag);
488                         w.AddAttribute ("class", se.Attribute ("class"));
489                         snip.FromXml (w);
490                 }
491
492                 [Test]
493                 public void FromXml_NameEmpty ()
494                 {
495                         StrongNameIdentityPermission snip = new StrongNameIdentityPermission (PermissionState.None);
496                         SecurityElement se = snip.ToXml ();
497                         snip.FromXml (se);
498
499                         snip.PublicKey = new StrongNamePublicKeyBlob (ecma);
500                         snip.Version = new Version ("1.2.3.4");
501                         se = snip.ToXml ();
502                         snip.FromXml (se);
503                 }
504         }
505 }