Forum Discussion

PaFi's avatar
PaFi
New Contributor
5 years ago

Problem when setting authorization profile with Groovy script

Hi,

 

SoapUI 5.5.0

 

I want to use my test project for different environments so I have an initialization script for each environment where I set the correct endpoints and authorization profile, like this:

 

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

//set endpoints

testRunner.testCase.testSuite.project.setPropertyValue( "ztc_endpoint", "https://xxxx" )
testRunner.testCase.testSuite.project.setPropertyValue( "zrc_endpoint", "https://xxxx" )
testRunner.testCase.testSuite.project.setPropertyValue( "drc_endpoint", "https://xxxx" )

 

//set authorization profile for all REST requests
testRunner.testCase.testSuite.project.testSuiteList.each {testSuite ->
testSuite.testCaseList.each { testCase ->
testCase.testStepList.each { testStep ->
if( testStep instanceof RestTestRequestStep ) {
testStep.testRequest.setSelectedAuthProfileAndAuthType("Test",null)
}}}}

 

Now, this seems to work ok. When I check the project after running this script properties and authorization profiles have the correct values, BUT...

 

When I run the tests on project, testsuite or testcase level, ALL REST requests fail with status 401, complaining that no authorization token is present. This is confirmed by looking at the RAW requests:

GET https://xxxx HTTP/1.1
Accept-Encoding: gzip,deflate
Host: xxxxx
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

 

If, on the other hand, I run each REST request manually, on test step level, all REST requests run perfectly and contain an authorization header:

GET https://xxxxx HTTP/1.1
Accept-Encoding: gzip,deflate
Authorization: Bearer xxxxx
Host: xxxxx
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

 

After running a REST request manually once, it will work again on project / testsuite /test case level.

So I need to run each REST request manually like this before everything will work again on project / testsuite / testcase level. Obviously not what I hope to accomplish...

 

Any suggestions?

  • Already figured it out:

     

    testStep.testRequest.setSelectedAuthProfileAndAuthType("Test", com.eviware.soapui.config.CredentialsConfig.AuthType.O_AUTH_2_0)

     

    instead of

    testStep.testRequest.setSelectedAuthProfileAndAuthType("Test", null)

  • PaFi's avatar
    PaFi
    New Contributor

    Already figured it out:

     

    testStep.testRequest.setSelectedAuthProfileAndAuthType("Test", com.eviware.soapui.config.CredentialsConfig.AuthType.O_AUTH_2_0)

     

    instead of

    testStep.testRequest.setSelectedAuthProfileAndAuthType("Test", null)