Forum Discussion

JimL's avatar
JimL
Contributor
15 years ago

Automatically populate "IssueInstant" outgoing SOAP request?

Hi,

It's been awhile since I've used SOAPUI, but I want to use SOAPUI to send a SOAP request into one of our webservices. The SOAP message will have a SAML assertion embedded.

I've been able to configure the server side to not require a signed assertion, but, at least so far, I haven't found a way to get it to disable checking the "IssueInstant" attribute (i.e., the assertion timestamp), so I'm wondering how I might be able to configure SOAPUI to automatically populate the IssueInstant with the proper date/timestamp before it sends the SOAP request out?

The IssueInstant attribute in the SOAP request looks like:

...IssueInstant="2011-07-07T03:57:40Z"...

In other words, I'd like to get SOAPUI to determine the current time ('now') and then reformat that into a date/timestamp string:

YYYY-MM-DDThh:mm:ssZ

and insert that string into the SOAP message before sending the request out to the webservice.

Can SOAPUI do this, and if so, how?

Thanks,
Jim

6 Replies

  • JimL's avatar
    JimL
    Contributor
    Hi,

    FYI, to start with, I have created a test suite with 3 test cases, each with a single test step.

    The requests in each test step are all the same SOAP message for now:


    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body>
    <samlp:AttributeQuery xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:x500="urn:oasis:names:tc:SAML:2.0:profiles:attribute:X500" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Destination="http://foo.whatever.com:7777/soap" ID="id-hN1ehKe8y0Wr-kpO23UHr3pqi5Q-"
    IssueInstant="${#TestSuite#suiteissueinstant}"
    Version="2.0"><saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
    Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">http://foo.whatever.com:7777/foo</saml:Issuer>
    <saml:Subject xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"><saml:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName">cn=test,cn=users,dc=whatever,dc=com</saml:NameID>
    </saml:Subject>
    </samlp:AttributeQuery>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>


    I have a test suite-wide property defined, "suiteissueinstant", and for now, I'm manually populating that property with the appropriate date/timestamp string, but I'd really like to know how to get SOAPUI to automatically populate that property with the date/timestamp for "now" in the format that I described earlier.

    Thanks,
    Jim
  • JimL's avatar
    JimL
    Contributor
    Hi,

    From what I can tell from reading the documents, it looks like a "datagen" step is needed to do what I'm looking for, but I have a couple of questions about that:

    1) It looks like the datagen step can only be applied to an individual testcase, rather than, for example, to an entire test suite. Is that correct?

    2) I'm using (non-pro) SOAPUI (the latest version). When I go into a test case, or even create a new test case, and click on create datagen step nothing happens. Is datagen supported in the non-pro version of SOAPUI? If so, why isn't anything happening when I try to create a datagen step?

    Thanks,
    Jim
  • JimL's avatar
    JimL
    Contributor
    Hi,

    I've done more reading on my part, and it looks like datagen step is only available in the pro version?

    Anyway, I found this thread:

    viewtopic.php?f=5&t=4388&p=14721&hilit=datagen+pro#p14721

    So, it seems like I can set the property in the test case by using Groovy in a setup script, even in the non-pro SOAPUI. Is that correct?

    If so, it's not clear to me how the Groovy script sets the property within the testcase?

    I'll admit that I'm not at all familiar with Groovy, but this:

    http://www.soapui.org/Functional-Testin ... rties.html

    has a datagen/Groovy example to return a formatted date string:

    def sdf = new java.text.SimpleDateFormat("yyyy-MM-dd")
    return sdf.format( new Date())


    I can modify that to get the format I need, i.e., something like:

    def sdf = new java.text.SimpleDateFormat("yyyy-MM-ddThh:mm:ssZ")
    return sdf.format( new Date())


    but it's not clear how to take the formatted string into the test case property?

    Thanks,
    Jim
  • Finan's avatar
    Finan
    Frequent Contributor
    Hi,

    You can set a testSuite property from the free version of soapUI.
    Use the following line in the setup script on testSuite level: runner.testSuite.setPropertyValue("date", new Date().format("yyyy-MM-dd'T'hh:mm:ssZ"))
    or use the following line in a setup script on testCase level or in a groovy script testStep: testRunner.testCase.testSuite.setPropertyValue("date", new Date().format("yyyy-MM-dd'T'hh:mm:ssZ"))

    to set a testCase property:
    Use the following line in the setup script on testSuite level: runner.testSuite.getTestCaseByName("name").setPropertyValue("date", new Date().format("yyyy-MM-dd'T'hh:mm:ssZ"))
    or use the following line in a setup script on testCase level or in a groovy script testStep: testRunner.testCase.setPropertyValue("date", new Date().fomrat("yyyy-MM-dd'T'hh:mm:ssZ"))

    You can retrieve these values from your test request parameters with either:
    ${#TestCase#date} (to access the testCase property)
    ${#TestSuite#date} (to access the testSuite property)
  • JimL's avatar
    JimL
    Contributor
    Hi Finan,

    Great!

    I ended up putting:

    testRunner.testCase.setPropertyValue("date", new Date().format("yyyy-MM-dd'T'hh:mm:ssZ"));


    in the testcase setup script. I also had to add a property to the testcase named 'date'.

    I can now run the testcase successfully, and also a load test that uses that testcase.

    The reason I put it in the testcase setup script was that I also have a load test that uses that testcase, and I wanted to be able to have this (inserting the IssueInstant automatically) working with both the testcase and the load test.

    Thanks!

    Jim
  • Hi,

    Another option is to use this method directly in the request

    <IssueInstant>${=(new Date().format("yyy-MM-dd'T'hh:mm:ssZ"))}</IssueInstant>

    Regards
    Irfan