add integration test

This commit is contained in:
sebastien blanc 2016-11-03 14:24:32 +01:00
parent d98c375495
commit ee8c986e8e
3 changed files with 34 additions and 4 deletions

View file

@ -40,7 +40,13 @@ public class CustomerDatabaseServlet extends HttpServlet {
pw.println("Bill Burke"); pw.println("Bill Burke");
pw.print("</body></html>"); pw.print("</body></html>");
pw.flush(); pw.flush();
}
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.logout();
PrintWriter pw = resp.getWriter();
pw.println("servlet logout from database ok");
pw.flush();
} }
} }

View file

@ -43,16 +43,38 @@ public class CustomerServlet extends HttpServlet {
@Override @Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PrintWriter pw = resp.getWriter(); PrintWriter pw = resp.getWriter();
KeycloakSecurityContext context = (KeycloakSecurityContext) req.getAttribute(KeycloakSecurityContext.class.getName());
if (req.getRequestURI().endsWith("logout")) { if (req.getRequestURI().endsWith("logout")) {
resp.setStatus(200); resp.setStatus(200);
pw.println("servlet logout ok"); pw.println("servlet logout ok");
//Clear principal form database-service by calling logout
StringBuilder result = new StringBuilder();
String urlBase;
if (System.getProperty("app.server.ssl.required", "false").equals("true")) {
urlBase = System.getProperty("app.server.ssl.base.url", "https://localhost:8643");
} else {
urlBase = System.getProperty("app.server.base.url", "http://localhost:8280");
}
URL url = new URL(urlBase + "/customer-db/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("DELETE");
conn.setRequestProperty(HttpHeaders.AUTHORIZATION, "Bearer " + context.getTokenString());
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
result.append(line);
}
rd.close();
pw.println(result.toString());
// Call logout before pw.flush // Call logout before pw.flush
req.logout(); req.logout();
pw.flush(); pw.flush();
return; return;
} }
KeycloakSecurityContext context = (KeycloakSecurityContext) req.getAttribute(KeycloakSecurityContext.class.getName());
//try { //try {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();

View file

@ -387,7 +387,9 @@ public abstract class AbstractDemoServletsAdapterTest extends AbstractServletsAd
// test logout // test logout
driver.navigate().to(customerPortal + "/logout"); driver.navigate().to(customerPortal + "/logout");
assertTrue(driver.getPageSource().contains("servlet logout ok")); pageSource = driver.getPageSource();
assertTrue(pageSource.contains("servlet logout ok"));
assertTrue(pageSource.contains("servlet logout from database ok"));
customerPortal.navigateTo(); customerPortal.navigateTo();
assertCurrentUrlStartsWithLoginUrlOf(testRealmPage); assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);