ServiceAuthorizationBehaviorTest.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // ServiceAuthorizationBehaviorTest.cs
  3. //
  4. // Author:
  5. // Atsushi Enomoto <[email protected]>
  6. //
  7. // Copyright (C) 2005 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. #if USE_DEPRECATED
  29. // This class is not deprecated, but most of members and depending classes
  30. // have changed, so most of the code is not reusable.
  31. using System;
  32. using System.Collections.ObjectModel;
  33. using System.ServiceModel;
  34. using System.ServiceModel.Channels;
  35. using System.ServiceModel.Description;
  36. using System.ServiceModel.Dispatcher;
  37. using NUnit.Framework;
  38. namespace MonoTests.System.ServiceModel.Description
  39. {
  40. [TestFixture]
  41. public class ServiceAuthorizationBehaviorTest
  42. {
  43. [Test]
  44. public void DefaultValues ()
  45. {
  46. ServiceAuthorizationBehavior b =
  47. new ServiceAuthorizationBehavior ();
  48. Assert.IsNull (b.AuthorizationDomain, "#1");
  49. Assert.IsFalse (b.ImpersonateCallerForAllServiceOperations,
  50. "#2");
  51. Assert.IsNull (b.OperationRequirement, "#3");
  52. Assert.AreEqual (PrincipalPermissionMode.UseWindowsGroups,
  53. b.PrincipalPermissionMode, "#4");
  54. }
  55. [Test]
  56. public void ApplyBehavior ()
  57. {
  58. ServiceHost host = new ServiceHost (typeof (object));
  59. EndpointDispatcher d = new EndpointDispatcher (host, "a", "");
  60. DispatchRuntime db = d.Behavior;
  61. EndpointDispatcher d2 = new EndpointDispatcher (host, "a", "");
  62. DispatchRuntime db2 = d2.Behavior;
  63. ServiceAuthorizationBehavior b =
  64. new ServiceAuthorizationBehavior ();
  65. b.ImpersonateCallerForAllServiceOperations = true;
  66. b.OperationRequirement = new MyRequirement ();
  67. b.PrincipalPermissionMode = PrincipalPermissionMode.None;
  68. Collection<DispatchRuntime> c =
  69. new Collection<DispatchRuntime> (
  70. new DispatchRuntime [] {db, db2});
  71. Collection<BindingParameterCollection> pc =
  72. new Collection<BindingParameterCollection> (
  73. new BindingParameterCollection [] {
  74. new BindingParameterCollection ()});
  75. ((IServiceBehavior) b).ApplyBehavior (null, host, c, pc);
  76. Assert.IsNull (db.AuthorizationDomain, "#1-1");
  77. Assert.IsTrue (db.ImpersonateCallerForAllServiceOperations, "#1-2");
  78. Assert.AreEqual (typeof (MyRequirement),
  79. db.OperationRequirement.GetType (), "#1-3");
  80. Assert.AreEqual (PrincipalPermissionMode.None,
  81. db.PrincipalPermissionMode, "#1-4");
  82. Assert.IsNull (db2.AuthorizationDomain, "#2-1");
  83. Assert.IsTrue (db2.ImpersonateCallerForAllServiceOperations, "#2-2");
  84. /*
  85. Assert.AreEqual (typeof (MyRequirement),
  86. db2.OperationRequirement.GetType (), "#2-3");
  87. Assert.AreEqual (PrincipalPermissionMode.None,
  88. db2.PrincipalPermissionMode, "#2-4");
  89. */
  90. }
  91. /*
  92. class MyRequirement : OperationRequirement
  93. {
  94. public override bool AccessCheck (OperationContext ctx)
  95. {
  96. return true;
  97. }
  98. }
  99. */
  100. }
  101. }
  102. #endif