1
votes

I am getting below exception whenever trying to call JavaScript Function using below code:

Assertion failure message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``vars.put("FinalData", decode64(PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiI . . . '' : illegal use of undefined variable, class, or 'void' literal

Below is the BSFPostProcess:

function decode64(input) {
     var output = "";
     var chr1, chr2, chr3 = "";
     var enc1, enc2, enc3, enc4 = "";
     var i = 0;

     // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
     var base64test = /[^A-Za-z0-9\+\/\=]/g;
     if (base64test.exec(input)) {
        alert("There were invalid base64 characters in the input text.\n" +
              "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +
              "Expect errors in decoding.");
     }
     input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

     do {
        enc1 = keyStr.indexOf(input.charAt(i++));
        enc2 = keyStr.indexOf(input.charAt(i++));
        enc3 = keyStr.indexOf(input.charAt(i++));
        enc4 = keyStr.indexOf(input.charAt(i++));

        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;

        output = output + String.fromCharCode(chr1);

        if (enc3 != 64) {
           output = output + String.fromCharCode(chr2);
        }
        if (enc4 != 64) {
           output = output + String.fromCharCode(chr3);
        }

        chr1 = chr2 = chr3 = "";
        enc1 = enc2 = enc3 = enc4 = "";

     } while (i < input.length);
     return output;
}

I am trying to call this under BSF Assertion Sampler using below code.

vars.put("FinalData", decode64(${Data}));

OR

vars.put("FinalData", decode64(vars.get("Data")));

Data is variable and stores value:

PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9InllcyI/Pgo8UmVxdWVzdFBhcnRzUmVzcG9uc2UgeG1sbnM9Imh0dHA6Ly9zZXJ2aWNlcy5teWNjY3BvcnRhbC5jb20vQWx0ZXJuYXRlUGFydFNvdXJjaW5nL0FsdGVybmF0ZVBhcnRTb3VyY2luZyI+CiAgICA8UGFydFJlcXVlc3RJZGVudGlmaWVyPjQwNTM4MTU8L1BhcnRSZXF1ZXN0SWRlbnRpZmllcj4KPC9SZXF1ZXN0UGFydHNSZXNwb25zZT4=

FinalData is predefined variable.

1

1 Answers

1
votes

It's not how preprocessor works, you have 2 options:

Anyway you would remove the function declaration in preprocessor