diff --git a/src/Sustainsys.Saml2/Metadata/MetadataSerializer.EntityDescriptor.cs b/src/Sustainsys.Saml2/Metadata/MetadataSerializer.EntityDescriptor.cs index 281bbc7c1..53e18e31d 100644 --- a/src/Sustainsys.Saml2/Metadata/MetadataSerializer.EntityDescriptor.cs +++ b/src/Sustainsys.Saml2/Metadata/MetadataSerializer.EntityDescriptor.cs @@ -93,11 +93,6 @@ protected virtual void ReadElements(XmlTraverser source, EntityDescriptor entity break; } } - else - { - // TODO: Test case for this. - wasRoleDescriptor = false; - } } while (wasRoleDescriptor && source.MoveNext(true)); } } \ No newline at end of file diff --git a/src/Sustainsys.Saml2/Samlp/SamlpSerializer.AuthnRequest.cs b/src/Sustainsys.Saml2/Samlp/SamlpSerializer.AuthnRequest.cs index 955419736..7b327e86b 100644 --- a/src/Sustainsys.Saml2/Samlp/SamlpSerializer.AuthnRequest.cs +++ b/src/Sustainsys.Saml2/Samlp/SamlpSerializer.AuthnRequest.cs @@ -16,7 +16,7 @@ public AuthnRequest ReadAuthnRequest(XmlTraverser source) /// public virtual XmlDocument Write(AuthnRequest authnRequest) { - var xmlDoc = CreateXmlDocument(); + var xmlDoc = new XmlDocument(); Append(xmlDoc, authnRequest); diff --git a/src/Sustainsys.Saml2/Xml/SerializerBase.cs b/src/Sustainsys.Saml2/Xml/SerializerBase.cs index bd17b349f..ac7f2196b 100644 --- a/src/Sustainsys.Saml2/Xml/SerializerBase.cs +++ b/src/Sustainsys.Saml2/Xml/SerializerBase.cs @@ -6,6 +6,9 @@ namespace Sustainsys.Saml2.Xml; +// TODO: Separate and rename to SamlReaderBase/SamlWriterBase - SamlpReader/SamlpWriter +// Make XmlTraverser a property of the reader - enforces being transient + /// /// Shared interface for all serializers /// @@ -67,11 +70,6 @@ public abstract class SerializerBase protected virtual void ThrowOnErrors(XmlTraverser source) => source.ThrowOnErrors(); - /// - /// Creates an Xml document with good settings. - /// - protected virtual XmlDocument CreateXmlDocument() => new() { PreserveWhitespace = true }; - /// /// Append an element using the serializers default and . /// diff --git a/src/Tests/Sustainsys.Saml2.Tests/Metadata/MetadataSerializerTests.EntityDescriptor.cs b/src/Tests/Sustainsys.Saml2.Tests/Metadata/MetadataSerializerTests.EntityDescriptor.cs index 4ad647b1a..2771c5798 100644 --- a/src/Tests/Sustainsys.Saml2.Tests/Metadata/MetadataSerializerTests.EntityDescriptor.cs +++ b/src/Tests/Sustainsys.Saml2.Tests/Metadata/MetadataSerializerTests.EntityDescriptor.cs @@ -176,4 +176,15 @@ public void ReadEntityDescriptor_ADFS() .Invoking(s => s.ReadEntityDescriptor(xmlTraverser)) .Should().NotThrow(); } + + [Fact] + public void ReadEntityDescriptor_WrongNamespaceRoleDescriptor() + { + var xmlTraverser = GetXmlTraverser(); + + new MetadataSerializer() + .Invoking(s => s.ReadEntityDescriptor(xmlTraverser)) + .Should().Throw() + .WithErrors(ErrorReason.UnexpectedNamespace); + } } diff --git a/src/Tests/Sustainsys.Saml2.Tests/Metadata/MetadataSerializerTests/ReadEntityDescriptor_WrongNamespaceRoleDescriptor.xml b/src/Tests/Sustainsys.Saml2.Tests/Metadata/MetadataSerializerTests/ReadEntityDescriptor_WrongNamespaceRoleDescriptor.xml new file mode 100644 index 000000000..db6094b2a --- /dev/null +++ b/src/Tests/Sustainsys.Saml2.Tests/Metadata/MetadataSerializerTests/ReadEntityDescriptor_WrongNamespaceRoleDescriptor.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file