Forum Discussion

Bill_In_Irvine's avatar
Bill_In_Irvine
Contributor
8 years ago

Where would I put a Groovy Script to set the KEYSTORE and KEYSTORE_PASSWORD?

I have spent two days searching the community and also outside web search engines for where to set the keystore password. I know the code that does it. I want to know where. Because I tried adding a script  it in a Test Case just above a REST request. I would get a failure on handshake when trying the SSL connection.

 

I tried it in a Test Suite "Setup Script" too. Same problem.

Here is my code for my groovy script and I've seen this similarly before dozens of times but without property expansion:

 

 

 

import com.eviware.soapui.settings.SSLSettings
import com.eviware.soapui.SoapUI

 

def location = context.expand( '${#Project#CPLocationKeys} ')
def keypass = context.expand( '${#Project#CPkeystorePaswd} ' )

// set

/SoapUI.settings.setString( SSLSettings.KEYSTORE_PASSWORD, context.expand( '${#Project#CPkeystorePaswd} ' ) )
SoapUI.settings.setString( SSLSettings.KEYSTORE, context.expand( '${#Project#CPLocationKeys} ' ) )

// get
SoapUI.settings.getString( SSLSettings.KEYSTORE, "value to return if there is no such setting set" )
//SoapUI.settings.getString( SSLSettings.KEYSTORE_PASSWORD, "no password")
log.info location
log.info keypass

 

 [edit: I decided to put this script in the TestSuite "Setup Script" place instead of as a groovy script within the Test Case. I changed the above code to hardcode a password but use groovyUtils.projectPath in place of the property expansion for the path. This makes it relative - based on where I store the project xml file. Also I was running test runner with those property expansions set to values already. So I think that is why I was also getting a message that keystore password was tampered. I noticed that after doing this my formerly blank SSL setting for keystore and password got set. So I assume now this is what I need to make it  work:

 

import com.eviware.soapui.settings.SSLSettings
import com.eviware.soapui.SoapUI

//mport com.eviware.soapui.impl.wsdl.support.wss.crypto.CryptoType

def location = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue('${#Project#CPLocationKeys} ')

def keypass = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue( '${#Project#CPkeystorePaswd} ' )

//testRunner.testCase.testSuite.project.wssContainer.addCrypto(location,keypass,CryptoType.KEYSTORE)


// set
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

groovyUtils.projectPath + "/certs/DDAKM.keystore"


SoapUI.settings.setString( SSLSettings.KEYSTORE_PASSWORD, context.expand( 'password' ) )
SoapUI.settings.setString( SSLSettings.KEYSTORE, groovyUtils.projectPath + "/mytest.keystore" )

//SoapUI.settings.setString( SSLSettings.KEYSTORE, context.expand( '${#Project#CPLocationKeys} ' ) )
log.info "project groovy script"
// get
//SoapUI.settings.getString( SSLSettings.KEYSTORE, "value to return if there is no such setting set" )
//SoapUI.settings.getString( SSLSettings.KEYSTORE_PASSWORD, "no password")
log.info location
log.info keypass

SoapUI.saveSettings();

 

I have only been able to run this setup script, as the API I want to connect to was shut down for the evening.

 

 

---------

 

Thanks

 

Bill

  • The solution I have finally got working is to put the script in the Test Suite Setup Script tag window (see attached - sorry if the screen shot is too small). I need to work it a bit more to do a teardown script to delete the keystore and password because I use my Ready API to run other tests. Also this stuff will run in testrunner as an automatic script, so the test suite must do everything from running regression tests.

     

    Note I decided I don't need property expansions for my password or keystore. And I also found that I cannot get log.info to print out anything from the Setup Script in the Test Suite level.

    • Bill_In_Irvine's avatar
      Bill_In_Irvine
      Contributor

      The solution I have finally got working is to put the script in the Test Suite Setup Script tag window (see attached - sorry if the screen shot is too small). I need to work it a bit more to do a teardown script to delete the keystore and password because I use my Ready API to run other tests. Also this stuff will run in testrunner as an automatic script, so the test suite must do everything from running regression tests.

       

      Note I decided I don't need property expansions for my password or keystore. And I also found that I cannot get log.info to print out anything from the Setup Script in the Test Suite level.

      • Bill_In_Irvine's avatar
        Bill_In_Irvine
        Contributor

        Better yet, property expansions work well with the above script, so I will use them. 

        So From the Environments icon at the top of Ready! API I open the Environments window, select my environment, then select "Custom Properties." I add name / values:

        CPLocationKeys      /certs/mykeyandcerts.keystore

        CPkeystorePaswd     password

         

        Then my groovy script in the test suite Setup Script:  

        -----------------------------

        import com.eviware.soapui.settings.SSLSettings
        import com.eviware.soapui.SoapUI


        // set
        def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)


        SoapUI.settings.setString( SSLSettings.KEYSTORE_PASSWORD, context.expand( '${#Project#CPkeystorePaswd}' ) )


        SoapUI.settings.setString( SSLSettings.KEYSTORE, groovyUtils.projectPath + context.expand( '${#Project#CPLocationKeys}' ))


        // get
        SoapUI.settings.getString( SSLSettings.KEYSTORE, "value to return if there is no such setting set" )


        SoapUI.saveSettings();

         

        ----------------

        Hope this helps others

         

        Bill