SmartBear / soapui

SoapUI is a free and open source cross-platform functional testing solution for APIs and web services.
http://www.soapui.org
Other
1.56k stars 607 forks source link

Compressed data logged by SoapUIWire is invalid #746

Open Gu32r0z opened 2 years ago

Gu32r0z commented 2 years ago

The change introduced by SOAPUI-OS-575 (since SOAPUI 5.6.1) has resulted in invalid compressed data being logged on the log file or HTTP log panel. Indeed if there is any carriage or line return character in the compressed data it will not be printed out. Decompressing data with any library (e.g. zlib and Python) will result in the following type of error:

Error -3 while decompressing data: invalid literal/lengths set, [python:3.9.12 (tags/v3.9.12:b28265d, Mar 23 2022, 23:52:46) [MSC v.1929 64 bit (AMD64)]/zlib:1.2.11-runtime:1.2.11

A quick fix would be to change the wire method of the [SoapUIWire] (https://github.com/SmartBear/soapui/blob/next/soapui/src/main/java/com/eviware/soapui/impl/wsdl/support/http/SoapUIWire.java#L26-L51) class as follows:

    private void wire(boolean request, final InputStream instream)
            throws IOException {
        final StringBuilder buffer = new StringBuilder();
        int ch;
        while ((ch = instream.read()) != -1) {
            if (ch == 13) {
                buffer.append("[\\r]");
            } else if (ch == 10) {
                //log if line feed
                buffer.append("[\\n]");
                String line = buffer.toString();
                log.debug(appendMarkerIfNeeded(request, line), line);
                buffer.setLength(0);
            } else if ((ch < 32) || (ch > 127)) {
                // to hex if control code
                buffer.append("[0x");
                buffer.append(Integer.toHexString(ch));
                buffer.append("]");
            } else {
                buffer.append((char) ch);
            }
        }
        if (buffer.length() > 0) {
            String line = buffer.toString();
            log.debug(appendMarkerIfNeeded(request, line), line);
        }
    }

The only drawback is that carriage and end of line return will be printed out in the UI:

HTTP/1.1 200 OK[\r][\n]