DisscCoder
DisscCoder

Reputation: 599

Setting up HTTP Basic Authentication for all requests

Is there a way to set up HTTP Basic Authentication for all requests in a SoapUI project?

I know it can be done for all requests within a TestSuite but I cant figure out how to do it for all requests in all TestSuites.

Upvotes: 52

Views: 67049

Answers (4)

goku_da_master
goku_da_master

Reputation: 4317

In SOAPUI 5.0 or higher, you can set it on the basicHttpBinding of your service from the Navigation window on the left (I think it's the interface) (it's the parent of all your methods and direct child of the project).

Right click on the interface name and choose "Show Interface Viewer". Then go to the "Service Endpoints" tab. Put your authentication info there. Now you don't have to specify authentication for every method in your service.

After entering the credentials, you need to assign to your requests. (Button "Assign" below the tabs)

Upvotes: 76

Stevelot
Stevelot

Reputation: 159

If you use rest services in soapUI, first do the following, as goku_da_master described:

Right click on the service name and choose "Show Service Viewer". Then go to the "Service Endpoints" tab. Put your authentication info there.

Since I can't find a way to apply these settings in bulk to all the requests, the easiest workaround is to apply the settings to 1 request, save the project (as xml), and do a simple find replace in your code editor 😎

Open a random Request 1, in the request tab click on the Auth button in the bottom left corner. At Authorization: select 'Add new authorisation...' and select Basic. Maybe you also need to enable the Allow pre-emptively setting. You can test this request now.

Now save the project and open it with your code editor, I use vsCode since it allows multi-line find-replace and has an xml format function (or plugin). So my find and replace looked like this:

                <con:credentials>
                    <con:username>***</con:username>
                    <con:password>******</con:password>
                    <con:domain xsi:nil="true"/>
                </con:credentials>
------------------------------------------------------------------------
                <con:credentials>
                    <con:username>***</con:username>
                    <con:password>******</con:password>
                    <con:domain xsi:nil="true"/>
                    <con:selectedAuthProfile>Basic</con:selectedAuthProfile>
                    <con:addedBasicAuthenticationTypes>Basic</con:addedBasicAuthenticationTypes>
                    <con:preemptive>true</con:preemptive>
                    <con:authType>Preemptive</con:authType>
                </con:credentials>

Upvotes: 0

A.Joly
A.Joly

Reputation: 2387

In ReadyAPI (SOAP UI Pro) version 2.2.0:

In Projects Tab, in the upper part, there is a Auth Manager

In this manager, create an authentication profile in the Auth Repository tab, with proper username and password. Leave Domain blank and set Authenticate Pre-emptively

In the Auth Manager tab, select the required upper level from which you want to apply your credentials (I used the top one) and, in the authorization method column, select your profile. On the 'extension to children' request say 'yes', they all should switch to the state 'Inherit From Parent'.

When you generate the TestSuite from your project, all your requests will inherit from the parent and apply the credentials you set in the profile.

Upvotes: 0

Magnus Blomstedt
Magnus Blomstedt

Reputation: 99

There is a few ways to do this:

  1. Set credentials on the Endpoint level. Of course this is then used for all Test Steps where that Endpoint is used.

  2. Set credentials on Test Case level (click on the key icon). The credentials propagate down to each Test Step.

  3. Use Custom Project Properties to store the credentials, then use Property Expansion in the Auth tab on each Test Step to grab your Custom Properties (username/password) http://www.soapui.org/Scripting-Properties/working-with-properties.html
    http://www.soapui.org/Scripting-Properties/property-expansion.html

Upvotes: 9

Related Questions