Forum Discussion

deggial's avatar
deggial
Occasional Contributor
12 years ago

Parameterizing WS Security header and request body

Hello,

I am working on a test where I need to create virtual users with unique values in WS Security header which should simulate different users accessing the system with different privileges. In other words login and password for each virtual user should be different (as well as some parameters in the request body, but that's other story).

Can you please advise if it's possible in Soap UI? Is there may be an API for that?

I checked with trial license for pro version and couldn't find relevant functionality as well as in open source version. Did I miss something? Please help.

4 Replies

  • tjdurden's avatar
    tjdurden
    Frequent Contributor
    Hi deggial,

    Yes, this should be possible. In short, once the WS-Security header is applied to an XML message, you can then use dynamic properties (using replacers) to replace the specific 'user'/'password' combinations as you need them. You could also use dynamic properties to generate any other values in WS-Security header (timestamps etc).

    For example, you might choose to create a Properties step (called Properties in this example) that has 5 users in it... User1, Password1, User2, Password2, etc. In your SOAP request, you could then do something like:

    <soapenv:Envelope xmlns:qa="XXXXXXXXX" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <wsse:UsernameToken wsu:Id="UsernameToken-1">
    <wsse:Username>${Properties#User1}</wsse:Username>
    <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">${Properties#Password1}</wsse:Password>
    </wsse:UsernameToken>
    </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
    <qa:StartProcess>
    <ScriptedResponses>?</ScriptedResponses>
    </qa:StartProcess>
    </soapenv:Body>
    </soapenv:Envelope>


    You could also look at creating a Groovy step that dynamically creates user/pass Property combinations for you (either imported, or as part of a hard-coded array) and then iterate over the list that way. There's some useful bits for this here: http://www.loadui.org/forum/viewtopic.p ... 500#p37045

    Kind regards,
    Tim
  • deggial's avatar
    deggial
    Occasional Contributor
    Thanks for ideas.

    I've done some research in terms what I am trying to achieve and it looks like the best way to go ahead is by using imported properties (I need to customize at least 5 of them, 2 in the security header). I would like to use excel file to store data (export from db) and then values for each iteration will be set using groovy scripts (separate script for parameter). Can I specify column for excel file in groovy or should I split data in separate files (for example *.txt), then each script would build its own array which will be used for setting values? How can I ensure that sets of values do not overlap during load testing and each set of values is unique for each running thread?
  • deggial's avatar
    deggial
    Occasional Contributor
    import com.eviware.soapui.impl.wsdl.teststeps.*

    for( testCase in testSuite.getTestCaseList() ) {
    for( testStep in testCase.getTestStepList() ) {
    if( testStep instanceof WsdlTestRequestStep ) {
    testStep.getTestRequest().setUsername(testSuite.getPropertyValue("username"))
    testStep.getTestRequest().setPassword(testSuite.getPropertyValue("password"))
    }
    }
    }


    Can you please advise how can I adopt this code on the test case level as groovy script? (it works on test suite level as setup script - http://thewonggei.wordpress.com/2010/08/05/configure-http-basic-auth-once-for-soapui-test-suties)

    I removed testSuite related part and added imports missing on test case level, but get

    groovy.lang.MissingMethodException: No signature of method: static com.eviware.soapui.model.testsuite.TestSuite.getTestCaseList() is applicable for argument types: () values: []
  • deggial's avatar
    deggial
    Occasional Contributor
    It looks like part of the problem related to setting credentials is solved with this code:

    import com.eviware.soapui.impl.wsdl.teststeps.*

    for( testStep in testRunner.testCase.getTestStepList() ) {
    if( testStep instanceof WsdlTestRequestStep ) {
    testStep.getTestRequest().setUsername(testRunner.testCase.testSuite.getPropertyValue("username"))
    testStep.getTestRequest().setPassword(testRunner.testCase.testSuite.getPropertyValue("password"))
    }
    }


    Still need to:
    1. Address test case properties instead of test suite, should be trivial.
    2. Apply this code only to WS steps meeting certain criteria, anyone knows how to get full wsdl pathes in groovy script?
    3. Being able to get values from different rows of excel document, so far it looks like there is no built in functionality in groovy. Any suggestions?