New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML comments before root element skip validation #85

Closed
toschneck opened this Issue Mar 16, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@toschneck
Collaborator

toschneck commented Mar 16, 2016

If client sends to citrus-server an XML which starts with an comment tag before the root XML tag, citrus will skip the complete XML validation and accepts all content as valid content:

Citrus version: 2.5

client message:

<?xml version="1.0" encoding="UTF-8"?>
<!-- some content -->
<request>
    <fields>test</fields>
</request>

validation code:

http().server(httpserver)
                      .post("/request-endpoint/xml")
                      .payload(getResource("/request.xml"))
                      .timeout(10000)
<?xml version="1.0" encoding="UTF-8"?>
<not-valid-request>
    <fields>test</fields>
</not-valid-request>

As far as our debugging is possible the responsible code is in the class DomXmlMessageValidator:

 private void validateXmlTree(Node received, Node source, 
            XmlMessageValidationContext validationContext, NamespaceContext namespaceContext, TestContext context) {
        switch(received.getNodeType()) {
            case Node.DOCUMENT_TYPE_NODE:
                doDocumentTypeDefinition(received, source, validationContext, namespaceContext, context);
                break;
            case Node.DOCUMENT_NODE:
                //FIXME: firstChild is the comment tag, the next tag and his child elements will be ignored 
                validateXmlTree(received.getFirstChild(), source.getFirstChild(),
                        validationContext, namespaceContext, context);
                break;
            case Node.ELEMENT_NODE:
                doElement(received, source, validationContext, namespaceContext, context);
                break;
            case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE:
                doText(received, source);
                break;
            case Node.ATTRIBUTE_NODE:
                throw new IllegalStateException();
            case Node.COMMENT_NODE:
                doComment(received);
                break;
            case Node.PROCESSING_INSTRUCTION_NODE:
                doPI(received);
                break;
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment