diff --git a/testsuite/integration-arquillian/test-apps/servlets/src/main/java/org/keycloak/testsuite/adapter/servlet/CustomerServletNoConf.java b/testsuite/integration-arquillian/test-apps/servlets/src/main/java/org/keycloak/testsuite/adapter/servlet/CustomerServletNoConf.java new file mode 100644 index 0000000000..c353532dc5 --- /dev/null +++ b/testsuite/integration-arquillian/test-apps/servlets/src/main/java/org/keycloak/testsuite/adapter/servlet/CustomerServletNoConf.java @@ -0,0 +1,95 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.keycloak.testsuite.adapter.servlet; + +import org.keycloak.KeycloakSecurityContext; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.core.HttpHeaders; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.HttpURLConnection; +import java.net.URL; + +/** + * @author Bill Burke + * @version $Revision: 1 $ + */ +@WebServlet("/customer-portal-noconf") +public class CustomerServletNoConf extends HttpServlet { + private static final String LINK = "%s"; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + PrintWriter pw = resp.getWriter(); + if (req.getRequestURI().endsWith("logout")) { + resp.setStatus(200); + pw.println("servlet logout ok"); + + // Call logout before pw.flush + req.logout(); + pw.flush(); + return; + } + KeycloakSecurityContext context = (KeycloakSecurityContext) req.getAttribute(KeycloakSecurityContext.class.getName()); + + //try { + 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("GET"); + 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(); + resp.setContentType("text/html"); + pw.println(result.toString()); + pw.flush(); +// +// Response response = target.request().get(); +// if (response.getStatus() != 401) { // assert response status == 401 +// throw new AssertionError("Response status code is not 401."); +// } +// response.close(); +// String html = target.request() +// .header(HttpHeaders.AUTHORIZATION, "Bearer " + context.getTokenString()) +// .get(String.class); +// pw.println(html); +// pw.flush(); +// } finally { +// client.close(); +// } + } +} diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/adapter/page/CustomerPortalNoConf.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/adapter/page/CustomerPortalNoConf.java new file mode 100644 index 0000000000..ab17aa7685 --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/adapter/page/CustomerPortalNoConf.java @@ -0,0 +1,39 @@ +/* + * Copyright 2016 Red Hat, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.keycloak.testsuite.adapter.page; + +import org.jboss.arquillian.container.test.api.OperateOnDeployment; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.keycloak.testsuite.page.AbstractPageWithInjectedUrl; + +import java.net.URL; + +public class CustomerPortalNoConf extends AbstractPageWithInjectedUrl { + + public static final String DEPLOYMENT_NAME = "customer-portal-noconf"; + + @ArquillianResource + @OperateOnDeployment(DEPLOYMENT_NAME) + private URL url; + + @Override + public URL getInjectedUrl() { + return url; + } + +} diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractDemoServletsAdapterTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractDemoServletsAdapterTest.java index e742b91cb3..ebe38d9fdb 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractDemoServletsAdapterTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/AbstractDemoServletsAdapterTest.java @@ -85,6 +85,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import org.keycloak.testsuite.adapter.page.CustomerPortalNoConf; import static org.keycloak.testsuite.auth.page.AuthRealm.DEMO; import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals; import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWith; @@ -101,6 +102,8 @@ public abstract class AbstractDemoServletsAdapterTest extends AbstractServletsAd @Page private CustomerPortal customerPortal; @Page + private CustomerPortalNoConf customerPortalNoConf; + @Page private CustomerPortalSubsystem customerPortalSubsystem; @Page private SecurePortal securePortal; @@ -129,6 +132,11 @@ public abstract class AbstractDemoServletsAdapterTest extends AbstractServletsAd protected static WebArchive customerPortal() { return servletDeployment(CustomerPortal.DEPLOYMENT_NAME, CustomerServlet.class, ErrorServlet.class); } + + @Deployment(name = CustomerPortalNoConf.DEPLOYMENT_NAME) + protected static WebArchive customerPortalNoConf() { + return servletDeployment(CustomerPortalNoConf.DEPLOYMENT_NAME, CustomerServletNoConf.class, ErrorServlet.class); + } @Deployment(name = CustomerPortalSubsystem.DEPLOYMENT_NAME) protected static WebArchive customerPortalSubsystem() { @@ -829,6 +837,13 @@ public abstract class AbstractDemoServletsAdapterTest extends AbstractServletsAd log.info("Checking app server log on app-server: \"" + System.getProperty("app.server") + "\" is not supported."); } } + + @Test + public void testWithoutKeycloakConf() { + customerPortalNoConf.navigateTo(); + String pageSource = driver.getPageSource(); + assertTrue(pageSource.contains("Forbidden") || pageSource.contains("HTTP Status 401")); + } } diff --git a/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/customer-portal-noconf/META-INF/context.xml b/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/customer-portal-noconf/META-INF/context.xml new file mode 100644 index 0000000000..8d1c0d63e9 --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/customer-portal-noconf/META-INF/context.xml @@ -0,0 +1,20 @@ + + + + + \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/customer-portal-noconf/WEB-INF/jetty-web.xml b/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/customer-portal-noconf/WEB-INF/jetty-web.xml new file mode 100644 index 0000000000..8c59313878 --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/customer-portal-noconf/WEB-INF/jetty-web.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/customer-portal-noconf/WEB-INF/web.xml b/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/customer-portal-noconf/WEB-INF/web.xml new file mode 100644 index 0000000000..71fd5cdb32 --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/test/resources/adapter-test/customer-portal-noconf/WEB-INF/web.xml @@ -0,0 +1,76 @@ + + + + + + customer-portal-noconf + + + Servlet + org.keycloak.testsuite.adapter.servlet.CustomerServletNoConf + + + Error Servlet + org.keycloak.testsuite.adapter.servlet.ErrorServlet + + + + Servlet + /* + + + + Error Servlet + /error.html + + + + + Users + /* + + + user + + + + + Errors + /error.html + + + + + KEYCLOAK + demo + + /error.html + /error.html + + + + + admin + + + user + +