add integration test
This commit is contained in:
parent
d98c375495
commit
ee8c986e8e
3 changed files with 34 additions and 4 deletions
|
@ -40,7 +40,13 @@ public class CustomerDatabaseServlet extends HttpServlet {
|
|||
pw.println("Bill Burke");
|
||||
pw.print("</body></html>");
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,16 +43,38 @@ public class CustomerServlet extends HttpServlet {
|
|||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
PrintWriter pw = resp.getWriter();
|
||||
KeycloakSecurityContext context = (KeycloakSecurityContext) req.getAttribute(KeycloakSecurityContext.class.getName());
|
||||
if (req.getRequestURI().endsWith("logout")) {
|
||||
resp.setStatus(200);
|
||||
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
|
||||
req.logout();
|
||||
pw.flush();
|
||||
return;
|
||||
}
|
||||
KeycloakSecurityContext context = (KeycloakSecurityContext) req.getAttribute(KeycloakSecurityContext.class.getName());
|
||||
|
||||
|
||||
//try {
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
|
|
@ -387,7 +387,9 @@ public abstract class AbstractDemoServletsAdapterTest extends AbstractServletsAd
|
|||
// test 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();
|
||||
assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
|
||||
|
|
Loading…
Reference in a new issue