Service Virtualization

  • 1.  "Token Parsing Error: Lexical error" while reading encrypted data

    Posted Jul 16, 2018 04:42 PM

    I am getting the "Token Parsing Error: Lexical error" when trying to access the encrypted data using JSR223 step.

     

    Below is the code in JSR223 step.

     

    String text = "{{NEW_DDA}}";

    return text;

     

    ============================================================================
    | Error in Script
    ============================================================================
    | Step: Execute script (JSR-223)~1
    ----------------------------------------------------------------------------
    | Message: bsh.EvalError: Sourced file: inline evaluation of: ``String text = "eyJhbGciOiJub25lIn0.eyJzdWIiOiIyYmU0NDU5YjQ2YjJkNDRlMGJkZGQ2MjFiN . . . '' Token Parsing Error: Lexical error at line 1, column 203. Encountered: "\r" (13), after : "\"eyJhbGciOiJub25lIn0.eyJzdWIiOiIyYmU0NDU5YjQ2YjJkNDRlMGJkZGQ2MjFiNDFhMDJkYWZhMGUzMjE5MjhhMmE3NjA4ZDkyNDQ1MmFmODg1NDVkIiwiaXNzIjoiY29tLnBuYy5yZXRhaWwuZGVwb3NpdC1hY2NvdW50IiwiZW5jIjp0cnVlfQ.": <at unknown location>
    in <unknown file>
    ----------------------------------------------------------------------------
    | Trapped Exception: bsh.EvalError: Sourced file: inline evaluation of: ``String text = "eyJhbGciOiJub25lIn0.eyJzdWIiOiIyYmU0NDU5YjQ2YjJkNDRlMGJkZGQ2MjFiN . . . '' Token Parsing Error: Lexical error at line 1, column 203. Encountered: "\r" (13), after : "\"eyJhbGciOiJub25lIn0.eyJzdWIiOiIyYmU0NDU5YjQ2YjJkNDRlMGJkZGQ2MjFiNDFhMDJkYWZhMGUzMjE5MjhhMmE3NjA4ZDkyNDQ1MmFmODg1NDVkIiwiaXNzIjoiY29tLnBuYy5yZXRhaWwuZGVwb3NpdC1hY2NvdW50IiwiZW5jIjp0cnVlfQ.": <at unknown location>
    in <unknown file>
    | Trapped Message: javax.script.ScriptException: bsh.EvalError: Sourced file: inline evaluation of: ``String text = "eyJhbGciOiJub25lIn0.eyJzdWIiOiIyYmU0NDU5YjQ2YjJkNDRlMGJkZGQ2MjFiN . . . '' Token Parsing Error: Lexical error at line 1, column 203. Encountered: "\r" (13), after : "\"eyJhbGciOiJub25lIn0.eyJzdWIiOiIyYmU0NDU5YjQ2YjJkNDRlMGJkZGQ2MjFiNDFhMDJkYWZhMGUzMjE5MjhhMmE3NjA4ZDkyNDQ1MmFmODg1NDVkIiwiaXNzIjoiY29tLnBuYy5yZXRhaWwuZGVwb3NpdC1hY2NvdW50IiwiZW5jIjp0cnVlfQ.": <at unknown location>
    in <unknown file>
    ----------------------------------------------------------------------------
    STACK TRACE
    javax.script.ScriptException: bsh.EvalError: Sourced file: inline evaluation of: ``String text = "eyJhbGciOiJub25lIn0.eyJzdWIiOiIyYmU0NDU5YjQ2YjJkNDRlMGJkZGQ2MjFiN . . . '' Token Parsing Error: Lexical error at line 1, column 203. Encountered: "\r" (13), after : "\"eyJhbGciOiJub25lIn0.eyJzdWIiOiIyYmU0NDU5YjQ2YjJkNDRlMGJkZGQ2MjFiNDFhMDJkYWZhMGUzMjE5MjhhMmE3NjA4ZDkyNDQ1MmFmODg1NDVkIiwiaXNzIjoiY29tLnBuYy5yZXRhaWwuZGVwb3NpdC1hY2NvdW50IiwiZW5jIjp0cnVlfQ.": <at unknown location>
    in <unknown file>
    at bsh.BshScriptEngine.evalSource(BshScriptEngine.java:102)
    at bsh.BshScriptEngine.eval(BshScriptEngine.java:61)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
    at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:674)
    at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:427)
    at com.itko.lisa.test.UserScriptNode._execute(UserScriptNode.java:210)
    at com.itko.lisa.test.UserScriptNode.execute(UserScriptNode.java:175)
    at com.itko.lisa.test.TestNode.executeNode(TestNode.java:984)
    at com.itko.lisa.test.TestCase.execute(TestCase.java:1297)
    at com.itko.lisa.test.TestCase.execute(TestCase.java:1198)
    at com.itko.lisa.test.TestCase.executeNextNode(TestCase.java:1183)
    at com.itko.lisa.editor.WalkThruPanel.prepAndExecNode(WalkThruPanel.java:1085)
    at com.itko.lisa.editor.WalkThruPanel.access$900(WalkThruPanel.java:72)
    at com.itko.lisa.editor.WalkThruPanel$10.doCallback(WalkThruPanel.java:992)
    at com.itko.util.swing.panels.ProcessingDialog$2.run(ProcessingDialog.java:194)
    at java.lang.Thread.run(Thread.java:745)
    ============================================================================



  • 2.  Re: "Token Parsing Error: Lexical error" while reading encrypted data

    Broadcom Employee
    Posted Jul 16, 2018 05:09 PM

    What version of DevTest are you using?

    What is in the value {{NEW_DDA}}?



  • 3.  Re: "Token Parsing Error: Lexical error" while reading encrypted data

    Posted Jul 16, 2018 05:13 PM

    We are using Devtest v10.2.

     

    value of the variable is 

     

    eyJhbGciOiJub25lIn0.eyJzdWIiOiIyYmU0NDU5YjQ2YjJkNDRlMGJkZGQ2MjFiNDFhMDJkYWZhMGUzMjE5MjhhMmE3NjA4ZDkyNDQ1MmFmODg1NDVkIiwiaXNzIjoiY29tLnBuYy5yZXRhaWwuZGVwb3NpdC1hY2NvdW50IiwiZW5jIjp0cnVlfQ.



  • 4.  Re: "Token Parsing Error: Lexical error" while reading encrypted data

    Broadcom Employee
    Posted Jul 16, 2018 05:19 PM

    What you have there is a set of multiple base-64 encoded values

    eyJhbGciOiJub25lIn0

    and

    eyJzdWIiOiIyYmU0NDU5YjQ2YjJkNDRlMGJkZGQ2MjFiNDFhMDJkYWZhMGUzMjE5MjhhMmE3NjA4ZDkyNDQ1MmFmODg1NDVkIiwiaXNzIjoiY29tLnBuYy5yZXRhaWwuZGVwb3NpdC1hY2NvdW50IiwiZW5jIjp0cnVlfQ

     

    I reckon the characters represented as full stops are unprintable, and therefore make the object / array / value not a string

     

    What are you trying to do with the JSON objects in the base-64 encoding?



  • 5.  Re: "Token Parsing Error: Lexical error" while reading encrypted data

    Broadcom Employee
    Posted Jul 16, 2018 05:14 PM

    Is there any guarantee that encrypted data can be represented as a string? I suggest that it's lexically incorrect to try, in this case.

     

    var notText = testExec.getStateValue("NEW_DDA");

    //do something interesting to decrypt the value

    //return the decrypted value



  • 6.  Re: "Token Parsing Error: Lexical error" while reading encrypted data

    Posted Jul 17, 2018 10:39 AM

    I just want to use this encrypted value in a JSON virtual service image response. I am getting the json response for the virtual service with the encrypted value, but it contain a newline(\r\n) character at the end of encrypted value makes the response json formatted.

     

    So i was trying to assign this encrypted value in to a string and perform the string replace function to remove the newlines /spaces.  But i am getting this error when trying to assign to a String variable.

     

    The encrypted value looks like below in my service response. My intention is to remove the \r\n at the end.

     

     "accountId": "eyJhbGciOiJub25lIn0.eyJzdWIiOiJmMGI5OTk4ZWE5N2Q1MzVlMWUyNjU1NTQ2NjZlMmUzYWRhZjdlMjU3ODAzMjlhMjRlNjc3MzM5OWY5NTNmNDFjIiwiaXNzIjoiY29tLnBuYy5yZXRhaWwuZGVwb3NpdC1hY2NvdW50IiwiZW5jIjp0cnVlfQ.\r\n",



  • 7.  Re: "Token Parsing Error: Lexical error" while reading encrypted data

    Broadcom Employee
    Posted Jul 17, 2018 02:51 PM

    A couple of things ...

     

    1. the string you posted is a valid string, and works fine in DevTest. I still presume that the full stops are representing unprintable characters, so return a byte array from "NEW_DDA" in your script and run it in ITR to see what the non-printable characters are.

    2. The value isn't encrypted. It's just base-64 encoded, and can be decoded. When this is done (using whatever the full stops are marking as delimiters), you get:

    {"alg":"none"}

     

    {"sub":"f0b9998ea97d535e1e265554666e2e3adaf7e25780329a24e6773399f953f41c","iss":"com.pnc.retail.deposit-account","enc":true}

    I would expect that your client requires a unique value for "sub", or perhaps that value is used for correlation? In either case, you should add a response-side scriptable DPH to decode the base-64 encoding during record and encode the values during replay, concatenating the base-64-encoded values with your unprintable character.

     

    Rick



  • 8.  Re: "Token Parsing Error: Lexical error" while reading encrypted data
    Best Answer

    Broadcom Employee
    Posted Jul 17, 2018 03:21 PM

    Here is how I would start to look at dealing with this (assuming the full stops are actual full stops):

    import org.apache.commons.codec.binary.Base64;


    String encodedTextString = testExec.getStateValue("accountId");

    byte[] encodedText = encodedTextString.getBytes("US-ASCII");

    String firstString = encodedTextString.substring(0,encodedTextString.indexOf("."));
    String secondString = encodedTextString.substring(encodedTextString.indexOf(".") + 1, encodedTextString.lastIndexOf(".") );

    //decoding byte array into base64
    byte[] decodedFirstString = Base64.decodeBase64(firstString);
    byte[] decodedSecondString = Base64.decodeBase64(secondString);
    //testExec.setStateValue("Base 64 Decoded String : ", new String(decodedFirstString));
    String newJSON = "{ \"accountId\": " + new String(decodedFirstString) + new String(decodedSecondString) + "}";

    return newJSON;