Forum Discussion

SankarB's avatar
SankarB
Occasional Contributor
7 years ago

How to trim the string content in the body of the certificate creation

Hi All,

 

I need to validate the response of the certificate created based on the request.

 

In the request i send "------BeginCertificate ------XXXXXXXXXXXXXXXXXXXXXX ------EndCertificate----"

 

I need to trim the text before and after XXXX.   length  "-----Begincertificate---" & ------EndCertificate----"may vary.

 

basically i am using it for assertion.

 

Thanks in advance. 

1 Reply

  • StevenColon's avatar
    StevenColon
    SmartBear Alumni (Retired)

    Thank you for posting to our Community Forum.

     

    You can pull the request information in the script assertion, modify it with groovy string manipulation, and assert it against the response. Here is a sample script based on the sample :

     

    def request = context.expand( '${REST Request#Request}' )
    //Cut Start of Response
    certStart = "------BeginCertificate ------"
    certStartLength= certStart.length()+1
    
    trimmedRequest = request.substring(certStartLength)
    //cut end of response
    certEnd="------EndCertificate----"
    certEndIndex = trimmedRequest.indexOf(certEnd)
    trimmedRequest = trimmedRequest.substring(0, certEndIndex)
    
    //need to define response
    assert response == trimmedRequest
    

    Here is some documentation for you to explore:

    Have a great day!