Author: atsushi
Date: 2006-12-07 06:42:30 -0500 (Thu, 07 Dec 2006)
New Revision: 69176

Added:
   
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/MessagePartSpecificationTest.cs
Modified:
   trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChannelProtectionRequirements.cs
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/MessagePartSpecification.cs
   
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ScopedMessagePartSpecification.cs
   trunk/olive/class/System.ServiceModel/System.ServiceModel_test.dll.sources
   
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
   
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ScopedMessagePartSpecificationTest.cs
Log:
2006-12-07  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * MessagePartSpecificationTest.cs : new test.
        * ScopedMessagePartSpecificationTest.cs : added AddParts() tests.

        * MessagePartSpecification : implemented Union().
        * ScopedMessagePartSpecification.cs : AddParts() is now implemented
          correctly (it merges into existing parts).
        * ChannelProtectionRequirements.cs : cosmetic comment.



Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog    
    2006-12-07 11:41:41 UTC (rev 69175)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChangeLog    
    2006-12-07 11:42:30 UTC (rev 69176)
@@ -1,3 +1,10 @@
+2006-12-07  Atsushi Emomoto  <[EMAIL PROTECTED]>
+
+       * MessagePartSpecification : implemented Union().
+       * ScopedMessagePartSpecification.cs : AddParts() is now implemented
+         correctly (it merges into existing parts).
+       * ChannelProtectionRequirements.cs : cosmetic comment.
+
 2006-12-06  Atsushi Emomoto  <[EMAIL PROTECTED]>
 
        * WSSecurityTokenSerializer.cs : several improvements to read and

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChannelProtectionRequirements.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChannelProtectionRequirements.cs
 2006-12-07 11:41:41 UTC (rev 69175)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ChannelProtectionRequirements.cs
 2006-12-07 11:42:30 UTC (rev 69176)
@@ -30,6 +30,8 @@
 
 namespace System.ServiceModel.Security
 {
+       // Represents sp:SignedParts and sp:EncryptedParts in
+       // sp:SupportingTokens/ws:Policy/.
        public class ChannelProtectionRequirements
        {
                bool is_readonly;

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/MessagePartSpecification.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/MessagePartSpecification.cs
      2006-12-07 11:41:41 UTC (rev 69175)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/MessagePartSpecification.cs
      2006-12-07 11:42:30 UTC (rev 69176)
@@ -33,6 +33,7 @@
 
 namespace System.ServiceModel.Security
 {
+       // Represents WS-SecurityPolicy SignedParts or EncryptedParts.
        public class MessagePartSpecification
        {
                static XmlQualifiedName [] empty = new XmlQualifiedName [0];
@@ -94,10 +95,17 @@
                                header_types = new 
ReadOnlyCollection<XmlQualifiedName> (header_types);
                }
 
-               [MonoTODO]
                public void Union (MessagePartSpecification other)
                {
-                       throw new NotImplementedException ();
+                       if (other == null)
+                               throw new ArgumentNullException ("other");
+                       if (header_types.IsReadOnly)
+                               throw new InvalidOperationException ("This 
MessagePartSpecification is read-only.");
+                       body |= other.body;
+                       foreach (XmlQualifiedName q in other.header_types)
+                               // Sigh. It could be much better here.
+                               //if (!header_types.Contains (q))
+                                       header_types.Add (q);
                }
        }
 }

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ScopedMessagePartSpecification.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ScopedMessagePartSpecification.cs
        2006-12-07 11:41:41 UTC (rev 69175)
+++ 
trunk/olive/class/System.ServiceModel/System.ServiceModel.Security/ScopedMessagePartSpecification.cs
        2006-12-07 11:42:30 UTC (rev 69176)
@@ -69,16 +69,28 @@
 
                public void AddParts (MessagePartSpecification parts)
                {
-                       AddParts (parts, null);
+                       if (parts == null)
+                               throw new ArgumentNullException ("parts");
+                       if (IsReadOnly)
+                               throw new InvalidOperationException ("This 
ScopedMessagePartSpecification is read-only.");
+                       ChannelParts.Union (parts);
                }
 
                public void AddParts (MessagePartSpecification parts,
                        string action)
                {
+                       if (parts == null)
+                               throw new ArgumentNullException ("parts");
+                       if (action == null)
+                               throw new ArgumentNullException ("action");
                        if (IsReadOnly)
                                throw new InvalidOperationException ("This 
ScopedMessagePartSpecification is read-only.");
 
-                       table.Add (action, parts);
+                       MessagePartSpecification existing;
+                       if (table.TryGetValue (action, out existing))
+                               existing.Union (parts);
+                       else
+                               table.Add (action, parts);
                }
 
                public void MakeReadOnly ()

Modified: 
trunk/olive/class/System.ServiceModel/System.ServiceModel_test.dll.sources
===================================================================
--- trunk/olive/class/System.ServiceModel/System.ServiceModel_test.dll.sources  
2006-12-07 11:41:41 UTC (rev 69175)
+++ trunk/olive/class/System.ServiceModel/System.ServiceModel_test.dll.sources  
2006-12-07 11:42:30 UTC (rev 69176)
@@ -63,6 +63,7 @@
 System.ServiceModel.Security.Tokens/X509ListedCertificateValidator.cs
 System.ServiceModel.Security.Tokens/X509SecurityTokenParametersTest.cs
 System.ServiceModel.Security/ChannelProtectionRequirementsTest.cs
+System.ServiceModel.Security/MessagePartSpecificationTest.cs
 System.ServiceModel.Security/ScopedMessagePartSpecificationTest.cs
 System.ServiceModel.Security/SecurityAlgorithmSuiteTest.cs
 System.ServiceModel.Security/SecurityMessagePropertyTest.cs

Modified: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
   2006-12-07 11:41:41 UTC (rev 69175)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ChangeLog
   2006-12-07 11:42:30 UTC (rev 69176)
@@ -1,3 +1,8 @@
+2006-12-07  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * MessagePartSpecificationTest.cs : new test.
+       * ScopedMessagePartSpecificationTest.cs : added AddParts() tests.
+
 2006-12-06  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * WSSecurityTokenSerializerTest.cs : added test for reading

Added: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/MessagePartSpecificationTest.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/MessagePartSpecificationTest.cs
     2006-12-07 11:41:41 UTC (rev 69175)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/MessagePartSpecificationTest.cs
     2006-12-07 11:42:30 UTC (rev 69176)
@@ -0,0 +1,88 @@
+//
+// MessagePartSpecificationTest.cs
+//
+// Author:
+//     Atsushi Enomoto <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2006 Novell, Inc.  http://www.novell.com
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Collections.ObjectModel;
+using System.Net;
+using System.Net.Security;
+using System.ServiceModel;
+using System.ServiceModel.Channels;
+using System.ServiceModel.Security;
+using System.ServiceModel.Security.Tokens;
+using System.Xml;
+using NUnit.Framework;
+
+namespace MonoTests.System.ServiceModel
+{
+       [TestFixture]
+       public class MessagePartSpecificationTest
+       {
+               [Test]
+               public void DefaultValues ()
+               {
+                       MessagePartSpecification s =
+                               new MessagePartSpecification ();
+                       Assert.IsFalse (s.IsBodyIncluded, "#1");
+                       Assert.AreEqual (0, s.HeaderTypes.Count, "#2");
+
+                       s = new MessagePartSpecification (new XmlQualifiedName 
[] {new XmlQualifiedName ("foo", "urn:foo")});
+                       Assert.IsFalse (s.IsBodyIncluded, "#3");
+                       Assert.AreEqual (1, s.HeaderTypes.Count, "#4");
+               }
+
+               [Test]
+               public void Union ()
+               {
+                       XmlQualifiedName q1, q2, q3;
+                       q1 = new XmlQualifiedName ("foo");
+                       q2 = new XmlQualifiedName ("bar");
+                       q3 = new XmlQualifiedName ("baz");
+                       MessagePartSpecification p1 =
+                               new MessagePartSpecification (false, new 
XmlQualifiedName [] {q1, q2});
+                       MessagePartSpecification p2 =
+                               new MessagePartSpecification (true, new 
XmlQualifiedName [] {q3, q2});
+                       p1.Union (p2);
+                       Assert.IsTrue (p1.IsBodyIncluded, "#1");
+                       // Sigh. It does not exclude duplicates.
+                       Assert.AreEqual (4, p1.HeaderTypes.Count, "#1-2");
+                       Assert.IsTrue (p1.HeaderTypes.Contains (q1), "#2");
+                       Assert.IsTrue (p1.HeaderTypes.Contains (q2), "#3");
+                       Assert.IsTrue (p1.HeaderTypes.Contains (q3), "#4");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void UnionReadOnlyPart ()
+               {
+                       MessagePartSpecification s =
+                               new MessagePartSpecification ();
+                       s.MakeReadOnly ();
+                       Assert.AreEqual (true, s.IsReadOnly, "#1");
+                       s.Union (new MessagePartSpecification ());
+               }
+       }
+}


Property changes on: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/MessagePartSpecificationTest.cs
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ScopedMessagePartSpecificationTest.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ScopedMessagePartSpecificationTest.cs
       2006-12-07 11:41:41 UTC (rev 69175)
+++ 
trunk/olive/class/System.ServiceModel/Test/System.ServiceModel.Security/ScopedMessagePartSpecificationTest.cs
       2006-12-07 11:42:30 UTC (rev 69176)
@@ -26,14 +26,12 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 using System;
+using System.Collections.Generic;
 using System.Collections.ObjectModel;
-using System.Net;
-using System.Net.Security;
 using System.ServiceModel;
 using System.ServiceModel.Channels;
 using System.ServiceModel.Security;
-using System.ServiceModel.Security.Tokens;
-using System.Security.Cryptography.Xml;
+using System.Xml;
 using NUnit.Framework;
 
 namespace MonoTests.System.ServiceModel
@@ -51,6 +49,62 @@
                }
 
                [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void AddPartsNull ()
+               {
+                       ScopedMessagePartSpecification s =
+                               new ScopedMessagePartSpecification ();
+                       s.AddParts (null);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void AddPartsNull2 ()
+               {
+                       ScopedMessagePartSpecification s =
+                               new ScopedMessagePartSpecification ();
+                       s.AddParts (null, "urn:foo");
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void AddPartsNull3 ()
+               {
+                       ScopedMessagePartSpecification s =
+                               new ScopedMessagePartSpecification ();
+                       s.AddParts (new MessagePartSpecification (), null);
+               }
+
+               [Test]
+               public void AddParts ()
+               {
+                       ScopedMessagePartSpecification s =
+                               new ScopedMessagePartSpecification ();
+                       Assert.IsFalse (s.ChannelParts.IsBodyIncluded, "#1");
+                       s.AddParts (new MessagePartSpecification (true));
+                       Assert.AreEqual (0, s.Actions.Count, "#2");
+                       Assert.IsTrue (s.ChannelParts.IsBodyIncluded, "#3");
+
+                       XmlQualifiedName foo = new XmlQualifiedName ("foo");
+                       XmlQualifiedName bar = new XmlQualifiedName ("bar");
+
+                       s.AddParts (new MessagePartSpecification (new 
XmlQualifiedName [] {foo}), "urn:foo");
+                       Assert.AreEqual (1, s.Actions.Count, "#4");
+                       MessagePartSpecification m;
+                       s.TryGetParts ("urn:foo", out m);
+                       Assert.IsNotNull (m, "#5");
+                       Assert.AreEqual (1, m.HeaderTypes.Count, "#6");
+
+                       s.AddParts (new MessagePartSpecification (true, new 
XmlQualifiedName [] {bar}), "urn:foo");
+                       Assert.AreEqual (1, s.Actions.Count, "#7");
+                       s.TryGetParts ("urn:foo", out m);
+                       Assert.IsNotNull (m, "#8");
+                       List<XmlQualifiedName> l = new List<XmlQualifiedName> 
(m.HeaderTypes);
+                       Assert.AreEqual (2, m.HeaderTypes.Count, "#9");
+                       Assert.IsTrue (m.IsBodyIncluded, "#10");
+               }
+
+               [Test]
                [ExpectedException (typeof (InvalidOperationException))]
                public void AddToReadOnlyCollection ()
                {

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to