use of io.restassured.specification.RequestSpecification in project IPK-BrAPI-Validator by plantbreeding.
the class TestItemRunner method connect.
/**
* Connect to an endpoint and store the server response.
*
* @return server response
*/
private ValidatableResponse connect() {
LOGGER.info("New Request. URL: " + this.url);
RestAssured.useRelaxedHTTPSValidation();
try {
URL u = new URL(url);
if ((Config.get("advancedMode") != null && Config.get("advancedMode").equals("true")) && u.getPort() != 80 && u.getPort() != -1) {
throw new IllegalArgumentException();
}
RequestSpecification rs = given().contentType("application/json");
List<Param> params = this.item.getParameters();
if (this.method.equals("GET")) {
if (params != null) {
for (Param p : params) {
String value = RunnerService.replaceVariablesUrl(p.getValue(), this.variables);
rs.param(p.getParam(), value);
}
}
} else if (this.method.equals("POST") || this.method.equals("PUT")) {
ObjectNode bodyParams = (new ObjectMapper()).createObjectNode();
if (params != null) {
for (Param p : params) {
String value = RunnerService.replaceVariablesUrl(p.getValue(), this.variables);
bodyParams.put(p.getParam(), value);
}
}
rs.body(bodyParams.toString());
}
ValidatableResponse vr = rs.request(this.method, this.url).then();
return vr;
} catch (AssertionError e) {
LOGGER.info("Connection error");
LOGGER.info("== cause ==");
LOGGER.info(e.getMessage());
} catch (IllegalArgumentException e) {
LOGGER.info("Connection error. Invalid port");
LOGGER.info("== cause ==");
LOGGER.info(e.getMessage());
} catch (Exception e) {
if (e.getClass().equals(SSLHandshakeException.class)) {
LOGGER.info("Connection error");
LOGGER.info("== cause ==");
LOGGER.info(e.getMessage());
}
}
return null;
}
use of io.restassured.specification.RequestSpecification in project devonfw-testing by devonfw.
the class XXssProtectionTest method testHeader.
@Test
@Parameters(method = "addParameters")
public void testHeader(SessionEnum session, EnvironmentParam origin, SubUrlEnum path) {
RequestSpecification rs = getSessionManager().initBuilder(session).setBaseUri(origin.getValue()).setBasePath(path.getValue()).build();
given(rs).when().get().then().statusCode(200).header("X-XSS-Protection", "1; mode=block");
}
use of io.restassured.specification.RequestSpecification in project devonfw-testing by devonfw.
the class AuthRequiredTest method testHeader.
@Test
@Parameters(method = "addParameters")
public void testHeader(SessionEnum session, EnvironmentParam origin, SubUrlEnum path, String body, int statusCode) {
RequestSpecification rs = getSessionManager().initBuilder(session).setBaseUri(origin.getValue()).setBasePath(path.getValue()).addHeader("Content-Type", "application/json").setBody(body).build();
given(rs).when().request(Method.POST).then().statusCode(statusCode);
}
use of io.restassured.specification.RequestSpecification in project devonfw-testing by devonfw.
the class DriverManager method closeDriver.
public static void closeDriver() {
RequestSpecification driver = drivers.get();
if (driver == null) {
BFLogger.logDebug("closeDriver() was called but there was no driver for this thread.");
} else {
driver = null;
drivers.remove();
}
}
use of io.restassured.specification.RequestSpecification in project devonfw-testing by devonfw.
the class SessionManager method authenticateSession.
/**
* Authenticates a single user session and stores the session related identifiers (headers) localy.
*
* @param session
* Session name.
* @param user
* User name.
* @param password
* User password.
*/
private void authenticateSession(SessionEnum session, EnvironmentParam user, EnvironmentParam password) {
RestAssured.defaultParser = Parser.TEXT;
JSONObject request = new JSONObject();
request.put("username", user);
request.put("password", password);
RequestSpecification rs = new RequestSpecBuilder().setBody(request.toString()).setBaseUri(EnvironmentParam.SECURITY_SERVER_ORIGIN.getValue()).setBasePath(SubUrlEnum.LOGIN.getValue()).build();
Headers headers = given(rs).when().post().getHeaders();
if (!headers.hasHeaderWithName(AUTHORIZATION_HEADER)) {
throw new RuntimeException("No authorization header found. " + "Expected a header 'Authorization' holding a Bearer token.");
}
Header authHeader = headers.get(AUTHORIZATION_HEADER);
Headers authHeaders = new Headers(authHeader);
authData.put(session, authHeaders);
}
Aggregations