Forum Discussion

GCushman's avatar
GCushman
Occasional Contributor
10 years ago

Need help with REST authentication - Unable to switch user authentication

 

This is my first project with SOAPUI (recently upgraded to Ready! API 1.3.1) and I think I must be missing something simple but cannot figure it out for the life of me.

 

I created an Authorization Profile for my REST project containing valid credentials for my user.  I have been assigning this profile (via the 'Auth' tab) to all of my teststeps and everything has worked fine (regardless if I use pre-emptive auth or not). 

 

The problem is I now want to create a teststep that uses creds for a different user (specifically a user that either doesn't exist or doesn't have access to my REST resource).  I want to verify our API returns proper error for these cases.  However, no matter what I try, the teststep keeps returning data from my valid user.  Seems as if it is caching the valid creds from my Auth Profile.  I've tried the following methods without any luck:

  1. Create new Authentication Profiles with both valid user with bad pw and totally bogus user/pw.  Then assigned this profile to the Teststep via the Auth tab.
  2. Set the Auth tab to 'No Authorization' and created a groovy script that assigned the user/pw to this teststep.  Script appears to run correctly.  I included it below.
  3. Set the Auth Tab to 'Basic' authentication and explicitly entered bogus username and pw.

 

When I look in the HTTP log, I see the Authorization token and regardless of which user I am trying to use, the token is always the same as that of my valid user.

 

Here's my groovy script (copied and tweaked from this forum):

def password = "ILuvCarrots"
def username = "Bugs.Bunny@mydomain.com"

def testStep = testRunner.testCase.testSteps["Invalid User"]

testStep.setPropertyValue("Password",password)
testStep.setPropertyValue("Username",username)
log.info testStep.name +" password has been set to "+testStep.getPropertyValue("Password")
log.info testStep.name +" username has been set to "+ testStep.getPropertyValue("Username")

 

Any help or tips greatly appreciated.

 

Regards,

Greg

 

  • Jeshtha from support solved my problem in 2 minutes.  I had my user creds stored in my Environment and those override everything.  Once I removed them from the environment and reloaded the project everything worked as expected.

     

    Thanks to SmartBear support for a speedy and succesful outcome!

     

    Greg

  • GCushman's avatar
    GCushman
    Occasional Contributor

    One more thing to add, being a newbie didn't think of checking this yesterday.  Looking at the xml for the testcase, I see the credentials are set to my dummy user:

     

    -<con:credentials>
    
    <con:username>Bugs.Bunny@scribesoft.com</con:username>
    
    <con:password>ILuvCarrots</con:password>
    
    <con:domain xsi:nil="true"/>
    
    <con:selectedAuthProfile>Basic</con:selectedAuthProfile>
    
    <con:preemptive>true</con:preemptive>
    
    <con:authType>Preemptive</con:authType>
    
    </con:credentials>

     

    so for some reason something in my config is causing them to be overridden.

     

    Greg

    • GCushman's avatar
      GCushman
      Occasional Contributor

      Jeshtha from support solved my problem in 2 minutes.  I had my user creds stored in my Environment and those override everything.  Once I removed them from the environment and reloaded the project everything worked as expected.

       

      Thanks to SmartBear support for a speedy and succesful outcome!

       

      Greg