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