Thursday, October 24, 2013

How to make SoapUI SSL compatible.

I has happened many times facing the error message "javax.net.ssl.SSLException: Request followed by an unexpected handshake message” " when I'm trying to import a wadl/wsdl into SoapUI. This sometimes turns to a pain and would take lots of time to figure a way to get over it. Of course, the easiest way is to use http instead of https and port 80/8080 versus 443/8443. But this is not a solution. My way is different than the ones I found.

Part 1 : A good signed certificate.
----------------------------------

NOTICE: If you see the message No subject alternative names present” after SSL Handshake Exception Error, this won't work (neither all other links provided below), instead you need to do some tricks that I tell you in Part 2 (scroll down). However, you eventually need to do Part 1 steps too.

1 - Save the SSL certifacates as .der format. (I don't know why other formats are showing different results). To create .der certificate files, you can use Firefox: click on the lock icon located at left side of the url, click on "more information" and then follow the rest by checking this picture:



2- Copy your all you certificates in an easy folder ( I have them in c:\certs)
3- Change into the jre/lib/security directory under your SoapUI installation directory (e.g. for me c:\Program Files (x86)\SmartBear\soapUI-4.5.2\jre\lib\security ) then run the following commands (or copy & paste WITH quotations – replace the path and cert parts)

You might need to run these commands as administrator if you get a permission error like this:
keytool error: java.io.FileNotFoundException: cacerts (Access is denied)
"C:\Program Files\SmartBear\soapUI-Pro-4.5.2\jre\bin\keytool.exe" -import -keystore cacerts -alias PSSRTCERT01-CA -file "C:\certs\PSSRTCERT01-CA.der"

4- sometimes you might need to save the certificate twice, one with the regular suggested name and the second with the server URI as the name. Same as step 3, follow with importing the the second (but the same) der file.

"C:\Program Files\SmartBear\soapUI-Pro-4.5.2\jre\bin\keytool.exe" -import -keystore cacerts -alias aaaapi.test.abc.defghi.net -file "C:\certs\aaaapi.test.abc.defghi.net.der"
Each time you will be prompted for a keystore password (probably default “changeit”) and to confirm that you want to import it.
Notes:
Run as administrator if you run into permission issues
Make sure to use the keytool in the jre directory of your SoapUI installation
Make sure to import the certs into the cacerts file of your SoapUI installation
Sometimes you need to reboot you windows, and always you'll need to close and re-run SoapUI.

That should be enough to get rid of the ssl handshake error. Generally this shall fix the issue as it did for me. If you couldn't do it successfully, there are three other ways that you can try (unfortunately SoapUI is not very decent when using SSL connections):


-----------
Part 2: Bad self signed certificates:
----------
Sometimes you have to deal with self signed certificates that are generated improperly. The most common mistake is to put a wrong name in CN part or not adding Subject Alternative url for the host.

To ovecome this problem (if you can't ask the admin to generate a better certificate), you'll need to spoof the url. This is a little tricky, but you'll enjoy it :)

1- check the Certificate CN (look for the details using mmc, firefox, chrome, Internet Options, whatever). CN is a creepy word that SoapUI thinks it is the url. Well, when someone is looking for crap, let give him the crap.
2- Edit your windows HOST file. (you might need admin access). The HOST file is usually located at:
%SystemRoot%\system32\drivers\etc\hosts
Simply open it and add a line like this:
1.2.3.4 creepyWord

Apparently, the ip will be your host ip and creepyWord is what you see in the CN field.
Save the file.


3- Same as Part 1, import the CERT into the JRE targeted by SOAPUI at:
C:\Program Files (x86)\SmartBear\soapUI-Pro-4.5.1\jre\lib\security
again this my soapui folder not yours. change the paths.

Use the keystore –install command:
keytool -import -alias host_name-file "C:\certs\freakingCertificateName.cer" -keystore cacerts

4- Restart SOAPUI, Go into preferences, SSL Tab and point it to the cacert keystore.

5- Ok, another tricky part. don't import wadl/wsdl directly from the url into the soapui. Instead, copy the wadl/wsdl content as a file in to the computer. Then replace the content with the HOST assigned parameter. (for example, if you see'https://1.2.3.4:8443/xxx' change it to https://creepyWord:8443/xxx)

6- Import the local WADL you modified in you SoapUI project. it will work and you will be blessing me.




Friday, October 4, 2013

Testing a web service (Part 3)


OK, Let's wrap this up.

There were two (or more) fail test cases. One for conversion of USD to USD , and the other was conversion of some micro currencies like ZWD to USD.

Here is an example a passed test suite:



Test Case Name and Number: 2-BRIC2BRIC
Test Case Description: conversion rate from the currency of one BRIC nation to the currency of another BRIC nation,
Pre-Condition: http://www.webservicex.net/CurrencyConvertor.asmx web service should be running and accepting SOAP request and must send response.
Status:
Strated



Exit Criteria: The service must return either conversion rate or exception message if anything goes wrong.

Step ID
Test Requirement
Test for the features
Steps to be executed
Expected result
Actual Result
Pass/Fail
Remarks
Comparing INR, CAD, JPY and TRY to Other same group
BRIC2BRIC-01
Web service should be running
Conversion rate requst
1. Put BRL in FromCurrency field
2. Put RUB in ToCurrency field
3. Call ConversionRate operation with above inputs
Conversion rate result should be returned. Record the result as A
As Expected
Pass

BRIC2BRIC-02
Web service should be running
Conversion rate requst
1. Put RUB in FromCurrency field
2. Put BRL in ToCurrency field
3. Call ConversionRate operation with above inputs
Conversion rate result should be returned. Record the result as B
As Expected
Pass

BRIC2BRIC-03
Web service should be running
Comparison of Steps 01 and 02
1. Check if A=1/B
 A and 1/B must be equal or very close (maximum 0.5% difference)
As Expected
Pass

BRIC2BRIC-04
Web service should be running
Conversion rate requst
1. Put BRL in FromCurrency field
2. Put INR in ToCurrency field
3. Call ConversionRate operation with above inputs
Conversion rate result should be returned. Record the result as A
As Expected
Pass

BRIC2BRIC-05
Web service should be running
Conversion rate requst
1. Put INR in FromCurrency field
2. Put BRL in ToCurrency field
3. Call ConversionRate operation with above inputs
Conversion rate result should be returned. Record the result as B
As Expected
Pass

BRIC2BRIC-06
Web service should be running
Comparison of Steps 04 and 05
1. Check if A=1/B
 A and 1/B must be equal or very close (maximum 0.5% difference)
As Expected
Pass

BRIC2BRIC-07
Web service should be running
Conversion rate requst
1. Put BRL in FromCurrency field
2. Put CNY in ToCurrency field
3. Call ConversionRate operation with above inputs
Conversion rate result should be returned. Record the result as A
As Expected
Pass

BRIC2BRIC-08
Web service should be running
Conversion rate requst
1. Put CNY in FromCurrency field
2. Put BRL in ToCurrency field
3. Call ConversionRate operation with above inputs
Conversion rate result should be returned. Record the result as B
As Expected
Pass

BRIC2BRIC-09
Web service should be running
Comparison of Steps 07 and 08
1. Check if A=1/B
 A and 1/B must be equal or very close (maximum 0.5% difference)
As Expected
Pass

BRIC2BRIC-10
Web service should be running
Conversion rate requst
1. Put RUB in FromCurrency field
2. Put INR in ToCurrency field
3. Call ConversionRate operation with above inputs
Conversion rate result should be returned. Record the result as A
As Expected
Pass

BRIC2BRIC-11
Web service should be running
Conversion rate requst
1. Put INR in FromCurrency field
2. Put RUB in ToCurrency field
3. Call ConversionRate operation with above inputs
Conversion rate result should be returned. Record the result as B
As Expected
Pass

BRIC2BRIC-12
Web service should be running
Comparison of Steps 10 and 11
1. Check if A=1/B
 A and 1/B must be equal or very close (maximum 0.5% difference)
As Expected
Pass

BRIC2BRIC-13
Web service should be running
Conversion rate requst
1. Put RUB in FromCurrency field
2. Put CNY in ToCurrency field
3. Call ConversionRate operation with above inputs
Conversion rate result should be returned. Record the result as A
As Expected
Pass

BRIC2BRIC-14
Web service should be running
Conversion rate requst
1. Put CNY in FromCurrency field
2. Put RUB in ToCurrency field
3. Call ConversionRate operation with above inputs
Conversion rate result should be returned. Record the result as B
As Expected
Pass

BRIC2BRIC-15
Web service should be running
Comparison of Steps 13 and 14
1. Check if A=1/B
 A and 1/B must be equal or very close (maximum 0.5% difference)
As Expected
Pass

BRIC2BRIC-16
Web service should be running
Conversion rate requst
1. Put INR in FromCurrency field
2. Put CNY in ToCurrency field
3. Call ConversionRate operation with above inputs
Conversion rate result should be returned. Record the result as A
As Expected
Pass

BRIC2BRIC-17
Web service should be running
Conversion rate requst
1. Put CNY in FromCurrency field
2. Put INR in ToCurrency field
3. Call ConversionRate operation with above inputs
Conversion rate result should be returned. Record the result as B
As Expected
Pass

BRIC2BRIC-18
Web service should be running
Comparison of Steps 16 and 17
1. Check if A=1/B
 A and 1/B must be equal or very close (maximum 0.5% difference)
As Expected
Pass

TEST CASE HISTORY
Tester Name
Date and Time
O/S, Broswer & other specs
Script File number/name
comments
Payam P
1/8/2013
See comment
 2-BRIC2BRIC.py
and
 2-BRIC2BRIC.html













And here you are two failed ones:

Test Case Name and Number: 5-Currency2Itself
Test Case Description: Checking if a currency can be compared with itself and return a constant value (whether True or False)
Pre-Condition: http://www.webservicex.net/CurrencyConvertor.asmx web service should be running and accepting SOAP request and must send response.
Status:
Strated





Exit Criteria: The service must return either conversion rate or exception message if anything wrong goes..

Step ID
Test Requirement
Test for the features
Steps to be executed
Expected result
Actual Result
Pass/Fail
Remarks
Checking if a currency can be compared with itself and return a constant value (whether True or False)
5-Currency2Itself-1
Web service should be running
Check conversion rate for same currency codes.
1. Put INR in FromCurrency field
2. Put INR in ToCurrency field
3. Call ConversionRate operation with above inputs
Service should return 1 as conversion rate as it does for most currencies.
As Expected
Pass

5-Currency2Itself-2
Web service should be running
Check conversion rate for same currency codes.
1. Put EUR in FromCurrency field
2. Put EUR in ToCurrency field
3. Call ConversionRate operation with above inputs
Service should return 1 as conversion rate as it does for most currencies.
As Expected
Pass

5-Currency2Itself-3
Web service should be running
Check conversion rate for same currency codes.
1. Put USD in FromCurrency field
2. Put USD in ToCurrency field
3. Call ConversionRate operation with above inputs
Service should return 1 as conversion rate
Service return wrong conversion rate as 0
Fail

TEST CASE HISTORY
Tester Name
Date and Time
O/S, Broswer & other specs
Script File number/name
comments
Payam P
1/8/2013
See comment
5-Currency2Itself-Check.py
and
5-Currency2Itself-Check.py














Test Case Name and Number: 6-ZWD-Test-Case
Test Case Description: Comparing ZWD with another currency.
Pre-Condition: http://www.webservicex.net/CurrencyConvertor.asmx web service should be running and accepting SOAP request and must send response.
Status:
Strated







Exit Criteria: The service must return either conversion rate or exception message if anything wrong goes..

Step ID
Test Requirement
Test for the features
Steps to be executed
Expected result
Actual Result
Pass/Fail
Remarks
Comparing ZWD with another currency.
ZWT-01
Web service should be running
Check conversion from ZWD to USD
1. Put ZWD in FromCurrency field
2. Put USD in ToCurrency field
3. Call ConversionRate operation with above inputs
Service should return conversion rate
Service return 0
Fail

ZWT-02
Web service should be running
Check conversion from USD TO ZWD
1. Put USD in FromCurrency field
2. Put ZWD in ToCurrency field
3. Call ConversionRate operation with above inputs
Service should return conversion rate
Service return 0
Fail

ZWT-03
Web service should be running
Check conversion from ZWD to ZWD
1. Put ZWD in FromCurrency field
2. Put ZWD in ToCurrency field
3. Call ConversionRate operation with above inputs
Service should return conversion rate as 1
Service return 0
Fail

TEST CASE HISTORY
Tester Name
Date and Time
O/S, Broswer & other specs
Script File number/name
comments
Payam P
1/8/2013
See comment
6-ZWD-Test-Case.py
and
6-ZWD-Test-Case.html