Home > Blockchain >  How to create malformed XML (SOAP request) in nodejs
How to create malformed XML (SOAP request) in nodejs

Time:05-09

I have been given a task to generate malformed SOAP Request and checking for what kind of error response I receive.

For example:

const payload = `
    <?xml version="1.0" encoding="utf-8"?>
        <soap:Envelope 
            xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                                      
            xmlns:test="urn:TEST"
        >
            <soap:Body>
                <test:GetOperatingDataValues 
                    xmlns:test="urn:TEST"                                            
                >
                    <test:ListId>1</test:ListId>
                </test:GetOperatingDataValues>
            </soap:Body>
       </soap:Envelope>`

Now, if I send the above request body to the backend server like :

const result = axios.post("backendServer", payload)

console.log(result) will give the response from backend (in this case, response from GetOperatingDataValues function for listId 1)

Now, I have to modify that payload in different ways like, removing the end tag, different opening and closing tag names, deleting '<' from any tag, or removing '/' from end tags, different method name, etc and send that payload and check for the error response.

Is there any way to modify the correctly formed xml to malformed xml (in node js). I have gone through different packages such as xml2js, fast-xml-parser. But these packages just form the correct xml.

Any help would be highly appreciated.

CodePudding user response:

I would have thought it fairly obvious that to create a non-XML file, you don't want to use an XML tool. Just treat the XML as a character string and apply a regular expression, for example replacing </ by <.

  • Related