import java.io.FileInputStream;
import java.io.InputStream;
import java.security.KeyStore;
import com.jayway.restassured.RestAssured;
public class RestAssuredUtil
{
public static final void setup() throws Exception
{
RestAssured.baseURI = "myRESTAPIURL";
RestAssured.keystore("pathToKeyStoreJKSFile", "Paswd");
String trustStorePath ="pathToTrustStoreJKSFile";
String trustStorePassword="Paswd";
KeyStore truststore = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream truststoreInput = new FileInputStream(trustStorePath);
truststore.load(truststoreInput, trustStorePassword.toCharArray());
System.out.println("Truststore has " + truststore.size() + " keys");
RestAssured.trustStore(truststore);
}
}
import static com.jayway.restassured.RestAssured.given;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class LanguageWSTest
{
@BeforeTest
public void setup() throws Exception
{
RestAssuredUtil.setup();
}
@Test
public void testRead()
{
given()
.auth().basic("username","password")
.expect()
.statusCode(200)
.log().everything()
.when()
.get ("/enpoint");
}
}
Truststore has 3 keys
FAILED: testRead
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
My questions:
1. Is my way to implement it correct? Or do I need it use some other packages/methods?
2. If I am doing it right, what's causing the error? I googled but couldn't find a solution that would fix it.
I'm at my wit's end trying to figure the solution. Kindly help.
Thanks,
OR