Skip to content

Commit

Permalink
Another test
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersAbel committed Oct 16, 2023
1 parent a4d99fd commit a9d7d91
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
2 changes: 1 addition & 1 deletion src/Sustainsys.Saml2/Samlp/SamlpSerializer.AuthnRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public AuthnRequest ReadAuthnRequest(XmlTraverser source)
/// <inheritdoc/>
public virtual XmlDocument Write(AuthnRequest authnRequest)
{
var xmlDoc = CreateXmlDocument();
var xmlDoc = new XmlDocument();

Append(xmlDoc, authnRequest);

Expand Down
8 changes: 3 additions & 5 deletions src/Sustainsys.Saml2/Xml/SerializerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

/// <summary>
/// Shared interface for all serializers
/// </summary>
Expand Down Expand Up @@ -67,11 +70,6 @@ public abstract class SerializerBase
protected virtual void ThrowOnErrors(XmlTraverser source)
=> source.ThrowOnErrors();

/// <summary>
/// Creates an Xml document with good settings.
/// </summary>
protected virtual XmlDocument CreateXmlDocument() => new() { PreserveWhitespace = true };

/// <summary>
/// Append an element using the serializers default <see cref="Prefix"/> and <see cref="NamespaceUri"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Saml2XmlException>()
.WithErrors(ErrorReason.UnexpectedNamespace);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<EntityDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" entityID="https://stubidp.sustainsys.com/Metadata" >
<!--Need to put in something to fulfill non-empty requirement, but we're not parsing generic RoleDescriptors-->
<OtherElement xmlns="urn:something"/>
</EntityDescriptor>

0 comments on commit a9d7d91

Please sign in to comment.