SecureConversationSecurityTokenParametersTest.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // SecureConversationSecurityTokenParametersTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2006 Novell, Inc. http://www.novell.com
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Collections.ObjectModel;
  31. using System.Net;
  32. using System.Net.Security;
  33. using System.IdentityModel.Selectors;
  34. using System.ServiceModel;
  35. using System.ServiceModel.Channels;
  36. using System.ServiceModel.Description;
  37. using System.ServiceModel.Security;
  38. using System.ServiceModel.Security.Tokens;
  39. using NUnit.Framework;
  40. using Parameters = System.ServiceModel.Security.Tokens.SecureConversationSecurityTokenParameters;
  41. namespace MonoTests.System.ServiceModel
  42. {
  43. [TestFixture]
  44. public class SecureConversationSecurityTokenParametersTest
  45. {
  46. class MyParameters : Parameters
  47. {
  48. public MyParameters ()
  49. {
  50. }
  51. public MyParameters (SecurityBindingElement element)
  52. : base (element)
  53. {
  54. }
  55. public MyParameters (SecurityBindingElement element,
  56. bool cancel,
  57. ChannelProtectionRequirements requirements)
  58. : base (element, cancel, requirements)
  59. {
  60. }
  61. public bool Asym {
  62. get { return HasAsymmetricKey; }
  63. }
  64. public bool Client {
  65. get { return SupportsClientAuthentication; }
  66. }
  67. public bool Win {
  68. get { return SupportsClientWindowsIdentity; }
  69. }
  70. public bool Server {
  71. get { return SupportsServerAuthentication; }
  72. }
  73. public void InitRequirement (SecurityTokenRequirement r)
  74. {
  75. InitializeSecurityTokenRequirement (r);
  76. }
  77. }
  78. [Test]
  79. public void DefaultValues ()
  80. {
  81. MyParameters p = new MyParameters ();
  82. Assert.IsNull (p.BootstrapSecurityBindingElement, "#1-1");
  83. Assert.IsNotNull (p.BootstrapProtectionRequirements, "#1-2");
  84. Assert.AreEqual (true, p.RequireCancellation, "#1-3");
  85. Assert.AreEqual (false, p.Asym, "#1-4");
  86. // they cause NRE on winfx, likely a bug.
  87. //Assert.AreEqual (true, p.Client, "#1-5");
  88. //Assert.AreEqual (true, p.Win, "#1-6");
  89. //Assert.AreEqual (true, p.Server, "#1-7");
  90. p = new MyParameters (new AsymmetricSecurityBindingElement ());
  91. Assert.IsNotNull (p.BootstrapSecurityBindingElement, "#2-1");
  92. Assert.IsNotNull (p.BootstrapProtectionRequirements, "#2-2");
  93. Assert.AreEqual (true, p.RequireCancellation, "#2-3");
  94. Assert.AreEqual (false, p.Asym, "#2-4"); // regardless of binding element.
  95. Assert.AreEqual (false, p.Client, "#2-5");
  96. Assert.AreEqual (false, p.Win, "#2-6");
  97. Assert.AreEqual (false, p.Server, "#2-7");
  98. ChannelProtectionRequirements r =
  99. p.BootstrapProtectionRequirements;
  100. Assert.IsTrue (r.IncomingSignatureParts.ChannelParts.IsBodyIncluded, "#3-1");
  101. Assert.IsTrue (r.OutgoingSignatureParts.ChannelParts.IsBodyIncluded, "#3-2");
  102. Assert.IsTrue (r.IncomingEncryptionParts.ChannelParts.IsBodyIncluded, "#3-3");
  103. Assert.IsTrue (r.OutgoingEncryptionParts.ChannelParts.IsBodyIncluded, "#3-4");
  104. }
  105. [Test]
  106. public void NullArgs ()
  107. {
  108. new Parameters ((SecurityBindingElement) null);
  109. new Parameters (null, false, null);
  110. }
  111. [Test]
  112. [Ignore ("winfx bug")]
  113. public void InitializeSecurityTokenRequirement ()
  114. {
  115. ServiceModelSecurityTokenRequirement r =
  116. new InitiatorServiceModelSecurityTokenRequirement ();
  117. SymmetricSecurityBindingElement sbe =
  118. // new SymmetricSecurityBindingElement ();
  119. new WSHttpBinding ().CreateBindingElements ().Find<SymmetricSecurityBindingElement> ();
  120. sbe.ProtectionTokenParameters = new X509SecurityTokenParameters ();
  121. // MyParameters p = new MyParameters (sbe);
  122. // NRE occurs on winfx (likely a bug).
  123. // p.InitRequirement (r);
  124. }
  125. }
  126. }