cancel
Showing results for 
Search instead for 
Did you mean: 

Set SSL Keystore using Groovy on Test Step level

SOLVED
Highlighted
Occasional Contributor

Set SSL Keystore using Groovy on Test Step level

On the Project Level i have setup the Keystore.

image.png

 

Now i want to be able to Select this on Test Step Level using Groovy.

image.png

 

In the Step : Select SSL on Test Step i wrote a groovy to do the same but it is failing.

 

import com.eviware.soapui.impl.rest.RestMethod
import com.eviware.soapui.impl.rest.RestRequestInterface.HttpMethod
import com.eviware.soapui.impl.rest.RestResource
import com.eviware.soapui.impl.wsdl.support.wss.WssCrypto
import com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep
import com.eviware.soapui.impl.wsdl.support.wss.crypto.CryptoType

 

def step = testRunner.testCase.testSteps['GET - TEST'].testRequest

log.info step.getSslKeystore() // This step works fine and reads the Keystore Selected on the Test Step (if any)


step.setSslKeystore( 'keystore.jks') // This step does not work and gives error message

 

 

Error : 


groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.teststeps.RestTestRequest.setSslKeystore() is applicable for argument types: (java.lang.String) values: [keystore.jks] Possible solutions: setSslKeystore(com.eviware.soapui.impl.wsdl.support.wss.WssCrypto), getSslKeystore() error at line: 13

 

 

 

 

 

Please note that my tests require for me to be able to select & deselect the SSL Keystore for a test step dynamically (through groovy) based on the environment i am running my tests on .. (for ex : QA , UAT etc)

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: Set SSL Keystore using Groovy on Test Step level

Hi @ashutosh,

 

Looks like the below code line works for unsetting the keystore. You can give it a try.

testRunner.testCase.testSteps['Step Name'].testRequest.setSslKeystore(new EmptyWssCrypto())

 

Natalie
Customer Care Team

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓

View solution in original post

8 REPLIES 8
Highlighted
Community Manager

Re: Set SSL Keystore using Groovy on Test Step level

Community, do you have any ideas regarding this? 

@richie@nmrao@jsheph01@SiKing.   


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Occasional Contributor

Re: Set SSL Keystore using Groovy on Test Step level

Hi , 

 

Quick Update. 

I got the solution after i put in 3 hours into this thing.

Here it goes for the community.

 

 

import com.eviware.soapui.impl.wsdl.support.wss.crypto.CryptoType
import com.eviware.soapui.impl.rest.RestMethod
import com.eviware.soapui.impl.rest.RestRequestInterface.HttpMethod
import com.eviware.soapui.impl.rest.RestResource
import com.eviware.soapui.impl.wsdl.support.wss.WssCrypto
import com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep
import com.eviware.soapui.impl.wsdl.support.wss.crypto.CryptoType

def myList = testRunner.testCase.testSuite.project.wssContainer.getCryptoList()

if (myList.isEmpty()) //if no key store is defined on this project, create a keystore
{
log.info "No Keystore is Defined for this Project. Creating a Keystore First"
testRunner.testCase.testSuite.project.wssContainer.addCrypto(context.expand( '${#Project#KeystorePath}' ),context.expand( '${#Project#KeystorePassword}' ),CryptoType.KEYSTORE) //path, password, cryptoType
}

//Once the Keystore is Created , Apply it to whichever tests you want to apply it to
myList = testRunner.testCase.testSuite.project.wssContainer.getCryptoList()
log.info myList

def step = testRunner.testCase.testSteps['GET - TEST'].testRequest
step.setSslKeystore(myList[0])

Highlighted
Community Expert

Re: Set SSL Keystore using Groovy on Test Step level


Please note that my tests require for me to be able to select & deselect the SSL Keystore for a test step dynamically (through groovy) based on the environment i am running my tests on .. (for ex : QA , UAT etc)

If you use environments, then just define the keystore in a custom property.

Highlighted
Community Manager

Re: Set SSL Keystore using Groovy on Test Step level

Great hint SiKing! Thank you.

@ashutosh were you able to solve the issue? Please share your progress Smiley Happy


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Highlighted
Occasional Contributor

Re: Set SSL Keystore using Groovy on Test Step level

The use of variable keystores in "custom" properties was broken since ReadyApi 2.5.

Today I received a message from Smartbear's dev-team that they've fixed it in their upcoming release (planned in February 2020).

 

More info: https://community.smartbear.com/t5/SoapUI-Pro/Variable-keystore-for-each-single-teststep-based-on-en...

Highlighted
Occasional Contributor

Re: Set SSL Keystore using Groovy on Test Step level

Hi All ,

 

The original issue was that we have to test our API's for Swagger Endpoints and Apigee Endpoints 

Swagger uses TLS

Apigee uses Ping Fed tokens.

 

Since i wanted to  write the tests only 1 time and  then reuse them for multiple environments (like Swagger QA , Swagger UAT , Apigee QA, Apigee UAT)  I wanted a capability to Programmatically (through Groovy) Setup the TLS and Assign it to  test Steps.

 

So I was able to write the Script as i mentioned above.

So now if my tests are running against Swagger URL , i am able to set the TLS Certificate (through groovy)

However , when i want to run the same test for Apigee URLs (which only accept Pink Fed tokens and fails if TLS is supplied) my tests fail since i dont know how to Programatically Delete the TLS Setup.

 

 

//SSL is only used for Swagger tests. Before running this test , make sure the jks certificate is saved on Local on Location : {ProjectDir}\CompositeFolderName\ZGV0Dependencies
//Also make sure to define 3 Project Propertiesunder Default Environment as : a) KeystoreFolder b) KeystorePassword c)KeystoreFileName

import com.eviware.soapui.impl.wsdl.support.wss.crypto.CryptoType
import com.eviware.soapui.impl.rest.RestMethod
import com.eviware.soapui.impl.rest.RestRequestInterface.HttpMethod
import com.eviware.soapui.impl.rest.RestResource
import com.eviware.soapui.impl.wsdl.support.wss.WssCrypto
import com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep
import com.eviware.soapui.impl.wsdl.support.wss.crypto.CryptoType

def JenkinsEnv = testRunner.getTestCase().getTestSuite().getProject().getActiveEnvironmentName()
log.info 'The Test Environment on which the Script is executing is : ' +JenkinsEnv

def TestEnv

if (JenkinsEnv.contains('Apigee'))
TestEnv = "Apigee Env"
else if (JenkinsEnv.contains('Default'))
TestEnv = "Default Env"
else if (!JenkinsEnv.contains('Apigee'))
TestEnv = "Swagger Env"

log.info 'Alias name of this env is : ' +TestEnv

if (TestEnv.contains('Swagger'))
{
def GetCertificateList = testRunner.testCase.testSuite.project.wssContainer.getCryptoList()

if (GetCertificateList.isEmpty()) //if no key store is defined on this project, create a keystore
{
log.info "No Keystore is Defined for this Project. Creating a Keystore First"

//Flip the Environment to Default to get the Values below
context.getTestCase().getTestSuite().getProject().setActiveEnvironment('Default environment')
log.info 'Flipping the Env to : ' +testRunner.getTestCase().getTestSuite().getProject().getActiveEnvironmentName() + " to fetch some Custom Project Properties"

//Get the Values of Certificate location and Certificate Password ( these values are Setup for Default environment)


def RelativePath = testRunner.testCase.testSuite.project.getPath()
def KeystoreFolder = context.expand( '${#Project#KeystoreFolder}' )
def KeystoreFileName = context.expand( '${#Project#KeystoreFileName}' )
def KeystorePassword= context.expand( '${#Project#KeystorePassword}' )
def KeystorePath = RelativePath+"\\"+KeystoreFolder+"\\"+KeystoreFileName
log.info "Keystore is Stored on Location " + KeystorePath

//Re-Flip the Env back  to jenkins Env ( Jenkins sends a Trigger to run the Tests against diff env like Swagger QA or Apigee QA)


context.getTestCase().getTestSuite().getProject().setActiveEnvironment(JenkinsEnv)
log.info 'The Environment is flipped Back to : ' + testRunner.getTestCase().getTestSuite().getProject().getActiveEnvironmentName()

//Set the TLS
testRunner.testCase.testSuite.project.wssContainer.addCrypto(KeystorePath,KeystorePassword,CryptoType.KEYSTORE) //path, password, cryptoType
}
else
{
log.info "Certificate is already defined : " +GetCertificateList
}

GetCertificateList = testRunner.testCase.testSuite.project.wssContainer.getCryptoList()
def step = testRunner.testCase.testSteps['GET - TEST'].testRequest
step.setSslKeystore(GetCertificateList[0])
log.info "Selecting the Keystore for the test before running the API as : " +GetCertificateList[0]
}
else
{

log.info "Since the Test is running on Apigee , no need to setup TLS"

// I need a Script here to Delete the TLS Certificate since if i dont do this , my Test Fails as Apigee does not expect TLS cert when i am hitting their end point

}

 

 

I am almost there but i am just missing the last piece of the puzzle.

Hope i can get some help

 

Highlighted
Moderator

Re: Set SSL Keystore using Groovy on Test Step level

Hi @ashutosh,

 

Looks like the below code line works for unsetting the keystore. You can give it a try.

testRunner.testCase.testSteps['Step Name'].testRequest.setSslKeystore(new EmptyWssCrypto())

 

Natalie
Customer Care Team

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓

View solution in original post

Occasional Contributor

Re: Set SSL Keystore using Groovy on Test Step level

Hi , 

 

Sorry but what i am trying to do is Delete any existing Keystores through Groovy each time the test case runs .

What is happening currently is that i am able to define the TLS through groovy but then it keeps adding below the already existing certificate. Can you please help me with Delleting the Certificate fromt he Keystore Tab (using Groovy)

 

image.png

New Here?
Join us and watch the welcome video:
Announcements