2 // SymmetricDecryptionKeyTest.cs - NUnit Test Cases for SymmetricDecryptionKey
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
10 using NUnit.Framework;
11 using Microsoft.Web.Services.Security;
13 using System.Security.Cryptography;
14 using System.Web.Services.Protocols;
17 namespace MonoTests.MS.Web.Services.Security {
20 public class SymmetricDecryptionKeyTest : Assertion {
22 private void UnsupportedAlgorithm (string algo)
24 SymmetricAlgorithm sa = SymmetricAlgorithm.Create (algo);
26 SymmetricDecryptionKey sdk = new SymmetricDecryptionKey (sa);
27 Fail (algo + " - Expected SecurityFault but got none");
29 catch (SoapHeaderException she) {
30 // this is expected (but not documented)
31 // SecurityFault isn't public so we catch it's ancestor
32 // worse you can create SymmetricEncryptionKey with those algorithms
33 if (she.ToString ().StartsWith ("Microsoft.Web.Services.Security.SecurityFault")) {
37 Fail ("Expected SecurityFault but got " + she.ToString ());
40 Fail (algo + " - Expected SecurityFault but got " + e.ToString ());
45 public void UnsupportedAlgorithms ()
47 UnsupportedAlgorithm ("DES");
48 UnsupportedAlgorithm ("RC2");
51 private void SupportedAlgorithm (string algo)
53 SymmetricAlgorithm sa = SymmetricAlgorithm.Create (algo);
54 SymmetricDecryptionKey sdk = new SymmetricDecryptionKey (sa);
58 public void SupportedAlgorithms ()
60 SupportedAlgorithm ("Rijndael");
61 SupportedAlgorithm ("TripleDES");
65 public void NullAlgoConstructor ()
68 SymmetricDecryptionKey sdk = new SymmetricDecryptionKey (null);
69 Fail ("Expected SecurityFault but got none");
71 catch (SoapHeaderException she) {
72 // this is expected (from WSE)
73 // should be ArgumentNullException
74 // SecurityFault isn't public so we catch it's ancestor
75 // worse you can create SymmetricEncryptionKey with those algorithms
76 if (she.ToString ().StartsWith ("Microsoft.Web.Services.Security.SecurityFault")) {
80 Fail ("Expected SecurityFault but got " + she.ToString ());
83 Fail ("Expected SecurityFault but got " + e.ToString ());
88 public void AlgoWithKeyConstructor ()
90 SymmetricAlgorithm sa = SymmetricAlgorithm.Create ("TripleDES");
91 byte[] key = new byte [32];
92 SymmetricDecryptionKey sdk = new SymmetricDecryptionKey (sa, key);
93 AssertNull ("Name", sdk.Name);
97 [ExpectedException (typeof (ArgumentNullException))]
98 public void Constructor_NullValue ()
100 SymmetricAlgorithm sa = SymmetricAlgorithm.Create ("TripleDES");
101 SymmetricDecryptionKey sdk = null;
102 sdk = new SymmetricDecryptionKey (sa, null);
106 public void Constructor_NullAlgorithm ()
108 SymmetricDecryptionKey sdk = null;
109 byte[] key = new byte [32];
111 sdk = new SymmetricDecryptionKey (null, key);
112 Fail ("Expected SecurityFault but got none");
114 catch (SoapHeaderException she) {
115 // this is expected (from WSE)
116 // should be ArgumentNullException
117 // SecurityFault isn't public so we catch it's ancestor
118 // worse you can create SymmetricEncryptionKey with those algorithms
119 if (she.ToString ().StartsWith ("Microsoft.Web.Services.Security.SecurityFault")) {
123 Fail ("Expected SecurityFault but got " + she.ToString ());
125 catch (Exception e) {
126 Fail ("Expected SecurityFault but got " + e.ToString ());