Forum Discussion

PLandhage's avatar
PLandhage
New Contributor
11 years ago

[Res]How do I generate a MD5 hash based on the values flds

I use SoapUI Pro 4.5.1. See my SOAP envelope below.

The problem is that I want SoapUI to genererate this MD5 hash value based on all fields value except <pxor:hash> ( i e <pxor:accountNumber>,<pxor:purchaseOperation>,<pxor:price>,<pxor:priceArgList>,<pxor:currency>,<pxor:vat>,<pxor:orderID>,<pxor:productNumber>,<pxor:description>,<pxor:clientIPAddress>,<pxor:clientIdentifier>,<pxor:additionalValues>,<pxor:externalID>,<pxor:returnUrl>,<pxor:view>,<pxor:agreementRef>,<pxor:cancelUrl>).

Example och md5 hash: <pxor:hash>7C86B6D4CCD98C159882658ABFD838E6</pxor:hash>

Is there a SoapUI Pro tool support for this ?

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pxor="http://external.payex.com/PxOrder/">
<soapenv:Header/>
<soapenv:Body>
<pxor:Initialize8>
<pxor:accountNumber>11941141</pxor:accountNumber>
<pxor:purchaseOperation>AUTHORIZATION</pxor:purchaseOperation>
<pxor:price>1500</pxor:price>
<pxor:priceArgList xsi:nil="true" xmlns:xsi="xsi"/>
<pxor:currency>SEK</pxor:currency>
<pxor:vat>0</pxor:vat>
<pxor:orderID>0</pxor:orderID>
<pxor:productNumber>4</pxor:productNumber>
<pxor:description>SoapUI Authorization</pxor:description>
<pxor:clientIPAddress>1.1.1.1</pxor:clientIPAddress>
<pxor:clientIdentifier xsi:nil="true" xmlns:xsi="xsi"/>
<pxor:additionalValues xsi:nil="true" xmlns:xsi="xsi"/>
<pxor:externalID xsi:nil="true" xmlns:xsi="xsi"/>
<pxor:returnUrl></pxor:returnUrl>
<pxor:view>FACTORING</pxor:view>
<pxor:agreementRef xsi:nil="true" xmlns:xsi="xsi"/>
<pxor:cancelUrl></pxor:cancelUrl>
<pxor:hash>7C86B6D4CCD98C159882658ABFD838E6</pxor:hash>
</pxor:Initialize8>
</soapenv:Body>
</soapenv:Envelope>

2 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    You can achieve this but not out-of-the-box, unfortunately.

    Here's how I would proceed:


    • Create a TestCase-level property which will hold the hash value, say "request_hash".

    • In your XML request, let the value of your hash field be ${#TestCase#request_hash}. For example:
       <pxor:hash>${#TestCase#request_hash}</pxor:hash>

    • Add a Groovy test step to your testCase. It must be located before the actual request testStep as we will modify the value of the Test-Case property we've created in the previous step before sending it.

    • In the Groovy test step's editor, in SoapUI Pro, you can just right-click and select on "Get Data..." to get the value of any property, including properties in the request.... so give it a go and find all the data you need easily.

    • Hash the values using a Groovy function like this one: http://128bitstudios.com/2011/02/17/md5 ... nd-groovy/

    • Now, your script (in the Groovy Test Step) should just set the testCase property as follows:
      testRunner.testCase.setPropertyValue( "request_hash", hashValue )


    Let me know if this has solved the problem.

    Regards,

    Renato
    SmartBear Software
  • PLandhage's avatar
    PLandhage
    New Contributor
    Thank you for answer. I managed to fix this according to your instructions.

    Problem is that is I have to hard code the value ie

    digest.update("11941141".getBytes())
    digest.update("AUTHORIZATION".getBytes())
    ...

    Since I will use this code for many teststeps it would be much easier if I can loop the fields and get the values (and field name)
    Checked API documentation (and forum) and found this to get a reference to the test step but do not know how to go any further.

    This is the psedocode to explain what I want to do. The highlighted code in red needs to be replaced.

    import java.security.MessageDigest

    def digest = MessageDigest.getInstance("MD5")

    def testStep = context.testCase.getTestStepByName("Initialize8")
    def fields = testStep.getFields()

    fields.each() {

    name = fields.current.getName()

    if ( ! name == "pxor:hash" ) {

    def value = fields.current.getValue()

    digest.update( value.getBytes() )
    }

    }

    def hashValue = new BigInteger(1,digest.digest()).toString(16).padLeft(32,"0")
    testRunner.testCase.setPropertyValue( "request_hash", hashValue )