use of io.restassured.http.Header in project knox by apache.
the class GatewayBasicFuncTest method testServiceTestAPI.
@Test(timeout = TestUtils.MEDIUM_TIMEOUT)
public void testServiceTestAPI() throws Exception {
LOG_ENTER();
String user = "kminder";
String password = "kminder-password";
String queryString = "?username=" + user + "&password=" + password;
String clusterUrl = driver.getClusterUrl();
String testUrl = clusterUrl + "/service-test";
// XML Response
setupResources();
given().header(new Header("Accept", MediaType.APPLICATION_XML)).then().contentType(MediaType.APPLICATION_XML).statusCode(HttpStatus.SC_OK).body(not(containsString("<httpCode>401"))).body(not(containsString("<httpCode>404"))).body(not(containsString("<httpCode>403"))).body(containsString("<httpCode>200")).when().get(testUrl + queryString);
// .prettyPrint();
driver.assertComplete();
// JSON Response
setupResources();
given().header(new Header("Accept", MediaType.APPLICATION_JSON)).then().statusCode(HttpStatus.SC_OK).contentType(MediaType.APPLICATION_JSON).body(not(containsString("\"httpCode\" : 401"))).body(not(containsString("\"httpCode\" : 404"))).body(not(containsString("\"httpCode\" : 403"))).body(containsString("\"httpCode\" : 200")).when().get(testUrl + queryString);
// .prettyPrint();
driver.assertComplete();
// Test authorization with a header instead
setupResources();
given().header(new Header("Accept", MediaType.APPLICATION_JSON)).auth().preemptive().basic("kminder", "kminder-password").then().statusCode(HttpStatus.SC_OK).contentType(MediaType.APPLICATION_JSON).body(not(containsString("\"httpCode\" : 401"))).body(not(containsString("\"httpCode\" : 404"))).body(not(containsString("\"httpCode\" : 403"))).body(containsString("\"httpCode\" : 200")).when().get(testUrl);
// .prettyPrint();
driver.assertComplete();
// Authorize as a different (invalid) user
setupResources();
given().header(new Header("Accept", MediaType.APPLICATION_JSON)).then().statusCode(HttpStatus.SC_OK).contentType(MediaType.APPLICATION_JSON).body(not(containsString("\"httpCode\" : 200"))).body(not(containsString("\"httpCode\" : 404"))).body(not(containsString("\"httpCode\" : 403"))).body(containsString("\"httpCode\" : 401")).when().get(testUrl + "?username=bad-user&password=bad-password");
// .prettyPrint();
driver.assertNotComplete("WEBHDFS");
driver.assertNotComplete("OOZIE");
driver.assertNotComplete("RESOURCEMANAGER");
driver.assertNotComplete("WEBHCAT");
driver.assertNotComplete("STORM");
driver.assertNotComplete("WEBHBASE");
driver.assertNotComplete("FALCON");
// Authorize as a different (valid) user
setupResources();
given().header(new Header("Accept", MediaType.APPLICATION_JSON)).then().statusCode(HttpStatus.SC_OK).contentType(MediaType.APPLICATION_JSON).body(not(containsString("\"httpCode\" : 401"))).body(not(containsString("\"httpCode\" : 404"))).body(not(containsString("\"httpCode\" : 403"))).when().get(testUrl + "?username=mapred&password=mapred-password");
// .prettyPrint();
driver.assertComplete();
LOG_EXIT();
}
use of io.restassured.http.Header 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);
}
use of io.restassured.http.Header in project devonfw-testing by devonfw.
the class SessionManager method initBuilder.
/*
* (non-Javadoc)
* @see com.capgemini.ntc.security.ISessionManager#initBuilder(com.capgemini.ntc.security.SessionEnum)
*/
@Override
public RequestSpecBuilder initBuilder(SessionEnum session) {
Preconditions.checkNotNull(session);
if (!authData.containsKey(session)) {
return initBuilder();
}
RequestSpecBuilder result = new RequestSpecBuilder();
for (Header header : authData.get(session).asList()) {
result.addHeader(header.getName(), header.getValue());
}
return result;
}
use of io.restassured.http.Header in project spring-cloud-netflix by spring-cloud.
the class WireMockRestAssuredRequestAdapter method getAllHeaderKeys.
@Override
public Set<String> getAllHeaderKeys() {
Set<String> headers = new LinkedHashSet<>();
for (Header header : request.getHeaders()) {
String value = header.getValue();
if ("accept".equals(header.getName().toLowerCase()) && "*/*".equals(value)) {
continue;
}
headers.add(header.getName());
}
return headers;
}
use of io.restassured.http.Header in project spring-cloud-netflix by spring-cloud.
the class WireMockRestAssuredRequestAdapter method addResponseHeaders.
private void addResponseHeaders(ResponseDefinitionBuilder definition, Response input) {
for (Header header : input.getHeaders().asList()) {
String name = header.getName();
definition.withHeader(name, input.getHeader(name));
}
}
Aggregations