Merge pull request #1542 from ninjarobot/UriTemplateMatchException
[mono.git] / mcs / class / System.Security / Test / System.Security.Cryptography.Pkcs / Pkcs9AttributeTest.cs
1 //
2 // Pkcs9AttributeTest.cs - NUnit tests for Pkcs9Attribute
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004-2005 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
31 using NUnit.Framework;
32
33 using System;
34 using System.Collections;
35 using System.Security.Cryptography;
36 using System.Security.Cryptography.Pkcs;
37
38 namespace MonoTests.System.Security.Cryptography.Pkcs {
39
40         [TestFixture]
41         public class Pkcs9AttributeObjectTest {
42
43                 static string defaultOid = "1.2.840.113549.1.7.1";
44                 static string defaultName = "PKCS 7 Data";
45
46                 [Test]
47                 public void ConstructorEmpty () 
48                 {
49                         Pkcs9AttributeObject a = new Pkcs9AttributeObject ();
50                         Assert.IsNull (a.Oid, "Oid");
51                         Assert.IsNull (a.RawData, "RawData");
52                 }
53
54                 [Test]
55                 [ExpectedException (typeof (ArgumentNullException))]
56                 public void ConstructorAsnEncodedDataNull () 
57                 {
58                         Pkcs9AttributeObject a = new Pkcs9AttributeObject (null);
59                 }
60
61                 [Test]
62                 public void ConstructorOidArray () 
63                 {
64                         Oid o = new Oid (defaultOid);
65                         Pkcs9AttributeObject a = new Pkcs9AttributeObject (o, new byte[0]);
66                         Assert.AreEqual (defaultName, a.Oid.FriendlyName, "Oid.FriendlyName");
67                         Assert.AreEqual (defaultOid, a.Oid.Value, "Oid.Value");
68                         Assert.AreEqual (0, a.RawData.Length, "RawData");
69                 }
70
71                 [Test]
72                 [ExpectedException (typeof (ArgumentNullException))]
73                 public void ConstructorOidNullArray ()
74                 {
75                         Oid o = null;
76                         Pkcs9AttributeObject a = new Pkcs9AttributeObject (o, new byte[0]);
77                 }
78
79                 [Test]
80                 [ExpectedException (typeof (ArgumentNullException))]
81                 public void ConstructorOidArrayNull ()
82                 {
83                         Oid o = new Oid (defaultOid);
84                         Pkcs9AttributeObject a = new Pkcs9AttributeObject (o, null);
85                 }
86
87                 [Test]
88                 public void ConstructorStringArray ()
89                 {
90                         Pkcs9AttributeObject a = new Pkcs9AttributeObject (defaultOid, new byte[0]);
91                         Assert.AreEqual (defaultName, a.Oid.FriendlyName, "Oid.FriendlyName");
92                         Assert.AreEqual (defaultOid, a.Oid.Value, "Oid.Value");
93                         Assert.AreEqual (0, a.RawData.Length, "RawData");
94                 }
95
96                 [Test]
97                 [ExpectedException (typeof (ArgumentNullException))]
98                 public void ConstructorStringNullArray ()
99                 {
100                         string s = null;
101                         Pkcs9AttributeObject a = new Pkcs9AttributeObject (s, new byte[0]);
102                 }
103
104                 [Test]
105                 [ExpectedException (typeof (ArgumentNullException))]
106                 public void ConstructorStringArrayNull ()
107                 {
108                         Pkcs9AttributeObject a = new Pkcs9AttributeObject (defaultOid, null);
109                 }
110
111                 [Test]
112                 [ExpectedException (typeof (ArgumentNullException))]
113                 public void CopyFrom_Null ()
114                 {
115                         new Pkcs9AttributeObject ().CopyFrom (null);
116                 }
117
118                 [Test]
119                 [ExpectedException (typeof (ArgumentException))]
120                 public void CopyFrom_SigningTime_Raw ()
121                 {
122                         Pkcs9SigningTime st = new Pkcs9SigningTime (DateTime.UtcNow);
123                         Pkcs9AttributeObject a = new Pkcs9AttributeObject ();
124                         a.CopyFrom (new AsnEncodedData (st.RawData));
125                 }
126
127                 [Test]
128                 [ExpectedException (typeof (ArgumentException))]
129                 public void CopyFrom_SigningTime_OidRaw ()
130                 {
131                         Pkcs9SigningTime st = new Pkcs9SigningTime (DateTime.UtcNow);
132                         Pkcs9AttributeObject a = new Pkcs9AttributeObject ();
133                         a.CopyFrom (new AsnEncodedData (st.Oid, st.RawData));
134                 }
135
136                 [Test]
137                 [ExpectedException (typeof (ArgumentException))]
138                 public void CopyFrom_Self ()
139                 {
140                         Pkcs9AttributeObject a = new Pkcs9AttributeObject ("1.2.3.4", new byte[2] { 0x05, 0x00 } );
141                         a.CopyFrom (new AsnEncodedData (a.Oid, a.RawData));
142                 }
143         }
144 }
145