2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / Microsoft.Web.Services / Test / Microsoft.Web.Services.Security / SignatureKeyTest.cs
1 //
2 // SignatureKeyTest.cs - NUnit Test Cases for SignatureKey
3 //
4 // Author:
5 //      Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
8 //
9
10 using NUnit.Framework;
11 using Microsoft.Web.Services.Security;
12 using System;
13 using System.Security.Cryptography;
14 using System.Web.Services.Protocols;
15
16 namespace MonoTests.MS.Web.Services.Security {
17
18         [TestFixture]
19         public class SignatureKeyTest : Assertion {
20
21                 [Test]
22                 [ExpectedException (typeof (ArgumentNullException))] 
23                 public void ConstructorAsymmetricNull () 
24                 {
25                         AsymmetricAlgorithm key = null; // resolve ambiguity
26                         SignatureKey aek = new SignatureKey (key);
27                 }
28
29                 [Test]
30                 [ExpectedException (typeof (ArgumentNullException))] 
31                 public void ConstructorSymmetricNull () 
32                 {
33                         SymmetricAlgorithm key = null; // resolve ambiguity
34                         SignatureKey aek = new SignatureKey (key);
35                 }
36
37                 [Test]
38                 [ExpectedException (typeof (ArgumentNullException))] 
39                 public void ComputeSignatureNull () 
40                 {
41                         DSA dsa = DSA.Create ();
42                         dsa.ImportParameters (AllTests.GetDSAKey (true));
43                         SignatureKey sk = new SignatureKey (dsa);
44                         sk.ComputeSignature (null);
45                 }
46
47                 [Test]
48                 public void ComputeSignatureDSA () 
49                 {
50                         DSA dsa = DSA.Create ();
51                         dsa.ImportParameters (AllTests.GetDSAKey (true));
52                         SignatureKey sk = new SignatureKey (dsa);
53
54                         SignedXml signedXml = new SignedXml ();
55                         Reference r = new Reference ("http://www.go-mono.com/");
56                         signedXml.AddReference (r);
57                         sk.ComputeSignature (signedXml);
58                 }
59
60                 [Test]
61                 public void ComputeSignatureRSA () 
62                 {
63                         RSA rsa = RSA.Create ();
64                         rsa.ImportParameters (AllTests.GetRSAKey (true));
65                         SignatureKey sk = new SignatureKey (rsa);
66
67                         SignedXml signedXml = new SignedXml ();
68                         Reference r = new Reference ("http://www.go-mono.com/");
69                         signedXml.AddReference (r);
70                         sk.ComputeSignature (signedXml);
71                 }
72
73                 [Test]
74                 public void ComputeSignatureSymmetricAlgo () 
75                 {
76                         // default (should be Rjindael)
77                         SymmetricAlgorithm sa = SymmetricAlgorithm.Create ();
78                         sa.Key = new byte [16]; // 128 bits (all zeros)
79                         SignatureKey sk = new SignatureKey (sa);
80
81                         SignedXml signedXml = new SignedXml ();
82                         Reference r = new Reference ("http://www.go-mono.com/");
83                         signedXml.AddReference (r);
84                         sk.ComputeSignature (signedXml);
85                 }
86         }
87 }