{
JsonFactory factory = new JsonFactory();
ObjectMapper mp = new ObjectMapper(factory);
FakeRequest request = new FakeRequest(getMethod(), getRouteAddress());
request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
Result result = routeAndCall(request);
JsonNode configuration = null;
try{
configuration = mp.readTree(contentAsString(result));
}catch(Exception e){
}
originalValue = findInConfigurationDump(configuration,"Push","push","profile1.sandbox.ios.certificate.password");
//load settings
request = new FakeRequest(PUT, getRouteAddress("Push/profile1.sandbox.ios.certificate.password/fromquerystring"));
request = request.withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
result = routeAndCall(request);
assertRoute(result, "Set configuration with QS", OK, "data\":\"You provided key and value in the query string.In order to prevent security issue consider moving those value into the body of the request.\"", true);
//Verify value has changed
request = new FakeRequest(getMethod(), getRouteAddress());
request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
result = routeAndCall(request);
assertRoute(result, "LoadConfigurationAsJSON", OK,
"profile1.sandbox.ios.certificate.password\":\"fromquerystring\"", true);
//Write value with body
request = new FakeRequest(PUT, getRouteAddressWithoutQS());
request = request.withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
JsonNode node = null;
try{
node = mp.readTree("{\"value\":\"frombodyparams\"}");
}catch(Exception e){
fail("Unable to parse");
}
request = request.withJsonBody(node,PUT);
result = routeAndCall(request);
assertRoute(result, "Set configuration with Request Body", OK, null, false);
request = new FakeRequest("GET", "/admin/configuration/dump.json");
request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
result = routeAndCall(request);
assertRoute(result, "LoadConfigurationAsJSON", OK,
"profile1.sandbox.ios.certificate.password\":\"frombodyparams\"", true);
request = new FakeRequest(PUT, getRouteAddressWithoutQS());
request = request.withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
node = null;
try{
node = mp.readTree("{\"value\":\""+originalValue+"\"}");
}catch(Exception e){
fail("Unable to parse");
}
request = request.withJsonBody(node,PUT);
result = routeAndCall(request);
assertRoute(result, "Set Original configuration with Request Body", OK, null, false);
}