You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by GitBox <gi...@apache.org> on 2022/11/03 21:03:33 UTC
[GitHub] [shiro] bmarwell commented on a diff in pull request #522: [SHIRO-889] Provide Jakarta jar modules
bmarwell commented on code in PR #522:
URL: https://github.com/apache/shiro/pull/522#discussion_r1012273162
##########
samples/web-jakarta/src/test/java/org/apache/shiro/test/web/jakarta/JakartaAbstractContainerIT.java:
##########
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.shiro.test.web.jakarta;
+
+import com.gargoylesoftware.htmlunit.WebClient;
+import org.apache.logging.log4j.util.Strings;
+import org.apache.shiro.lang.codec.Base64;
+//import org.eclipse.jetty.http.HttpVersion;
+//import org.eclipse.jetty.server.Connector;
+//import org.eclipse.jetty.server.HttpConfiguration;
+//import org.eclipse.jetty.server.HttpConnectionFactory;
+//import org.eclipse.jetty.server.SecureRequestCustomizer;
+//import org.eclipse.jetty.server.Server;
+//import org.eclipse.jetty.server.ServerConnector;
+//import org.eclipse.jetty.server.SslConnectionFactory;
+//import org.eclipse.jetty.util.resource.Resource;
+//import org.eclipse.jetty.util.ssl.SslContextFactory;
+//import org.eclipse.jetty.webapp.Configuration;
+//import org.eclipse.jetty.webapp.FragmentConfiguration;
+//import org.eclipse.jetty.webapp.JettyWebXmlConfiguration;
+//import org.eclipse.jetty.webapp.MetaInfConfiguration;
+//import org.eclipse.jetty.webapp.WebAppContext;
+//import org.eclipse.jetty.webapp.WebInfConfiguration;
+//import org.eclipse.jetty.webapp.WebXmlConfiguration;
Review Comment:
to be removed
##########
samples/web-jakarta/src/test/java/org/apache/shiro/test/web/jakarta/JakartaAbstractContainerIT.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.shiro.test.web.jakarta;
+
+import com.gargoylesoftware.htmlunit.WebClient;
+import org.apache.meecrowave.Meecrowave;
+import org.apache.shiro.lang.codec.Base64;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+
+import static org.junit.Assert.assertEquals;
+
+public abstract class JakartaAbstractContainerIT {
+
+ protected static Meecrowave meecrowave;
+
+ protected static int tlsPort;
+
+ protected final WebClient webClient = new WebClient();
+
+ protected static final File TEST_KEYSTORE_PATH = setupKeyStore();
+ protected static final String TEST_KEYSTORE_PASSWORD = "password";
+
+ protected static final String classpath = ".";
+
+ @BeforeClass
+ public static void startContainer() {
+ final File root = new File(getWarDir());
+ try {
+ meecrowave = new Meecrowave(new Meecrowave.Builder().randomHttpPort());
+ meecrowave.getConfiguration().addGlobalContextCustomizer(ctx -> ctx.setJarScanner(new org.apache.tomcat.util.scan.StandardJarScanner()));
+ meecrowave.start();
+ meecrowave.deployWebapp("/", root);
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ protected static String getBaseUri() {
+ return "http://localhost:" + meecrowave.getConfiguration().getHttpPort() + "/";
+ }
+
+ protected static String getWarDir() {
+ File[] warFiles = new File("target").listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".war");
+ }
+ });
+
+ assertEquals("Expected only one war file in target directory, run 'mvn clean' and try again", 1, warFiles.length);
+
+ return warFiles[0].getAbsolutePath().replaceFirst("\\.war$", "");
+ }
+
+ protected static String getBasicAuthorizationHeaderValue(String username, String password) throws UnsupportedEncodingException {
+ String authorizationHeader = username + ":" + password;
+ byte[] valueBytes;
+ valueBytes = authorizationHeader.getBytes(StandardCharsets.UTF_8);
+ authorizationHeader = new String(Base64.encode(valueBytes));
+ return "Basic " + authorizationHeader;
+ }
+
+ @Before
+ public void beforeTest() {
+ webClient.getOptions().setThrowExceptionOnFailingStatusCode(true);
+ }
+
+ @AfterClass
+ public static void stopContainer() {
+ if (meecrowave != null) {
+ meecrowave.close();
+ }
+ }
+
+ // Dealing with a keystore is NOT fun, it's easier to script one with the keytool
+ // see src/main/resources/createKeyStore.sh for more info
+ private static File setupKeyStore() {
Review Comment:
This can be removed, as this test now uses http which is sufficient
##########
samples/web-jakarta/src/test/resources/createKeyStore.sh:
##########
@@ -0,0 +1,65 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+set -e
+
+# This script will generate a self signed certificate, store it in a Java keystore and PEM format.
+# The generated certificate is good for 10 years, and should NOT need to be recreated until then (unless
+# changes to the certificate are needed).
+# Last run with Java 1.8.0_252
+#
+# Usage: For JVM based applications, the resulting keystore MUST be configured to in order for clients to accept TLS
+# connections. Typical usage requires setting of the Java system property 'javax.net.ssl.trustStore' to the file path
+# of the keystore. Either by adding a command line parameter: `-Djavax.net.ssl.trustStore=/path/to/keystore` or
+# programmatically: `System.setProperty("javax.net.ssl.trustStore", "/path/to/keystore")`
+
+dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
Review Comment:
This entire script can be removed, http
##########
samples/web-jakarta/src/test/java/org/apache/shiro/test/web/jakarta/WebContainerTest.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.shiro.test.web.jakarta;
+
+import com.gargoylesoftware.htmlunit.ElementNotFoundException;
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import jakarta.ws.rs.client.Client;
+import jakarta.ws.rs.client.ClientBuilder;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static jakarta.ws.rs.core.MediaType.TEXT_HTML_TYPE;
+import static org.junit.Assert.assertTrue;
+
+public class WebContainerTest extends JakartaAbstractContainerIT {
+
+ protected final WebClient webClient = new WebClient();
+
+ @Before
+ public void startup() throws IOException {
+
+ // Make sure we are logged out
+ final HtmlPage homePage = webClient.getPage(getBaseUri());
+ try {
+ // todo fix it
+ //homePage.getAnchorByHref("/logout").click();
+ }
+ catch (ElementNotFoundException e) {
+ //Ignore
+ }
+ }
+
+ @Test
+ public void logIn() throws IOException {
+ final Client client = ClientBuilder.newClient();
+ final String html = client.target("http://localhost:" + meecrowave.getConfiguration().getHttpPort())
+ .path("/")
+ .request(TEXT_HTML_TYPE)
+ .get(String.class);
+ HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp");
+ HtmlForm form = page.getFormByName("loginform");
+ form.getInputByName("username").setValueAttribute("root");
+ form.getInputByName("password").setValueAttribute("secret");
+ page = form.getInputByName("submit").click();
+ // This'll throw an exception if not logged in
+ // todo fix it
+ //page.getAnchorByHref("/logout");
Review Comment:
Don't include this please
##########
samples/web-jakarta/src/test/resources/test-keystore.pem:
##########
@@ -0,0 +1,22 @@
+-----BEGIN CERTIFICATE-----
Review Comment:
Can be removed
##########
samples/web-jakarta/src/test/java/org/apache/shiro/test/web/jakarta/WebContainerTest.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.shiro.test.web.jakarta;
+
+import com.gargoylesoftware.htmlunit.ElementNotFoundException;
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import jakarta.ws.rs.client.Client;
+import jakarta.ws.rs.client.ClientBuilder;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static jakarta.ws.rs.core.MediaType.TEXT_HTML_TYPE;
+import static org.junit.Assert.assertTrue;
+
+public class WebContainerTest extends JakartaAbstractContainerIT {
+
+ protected final WebClient webClient = new WebClient();
+
+ @Before
+ public void startup() throws IOException {
+
+ // Make sure we are logged out
+ final HtmlPage homePage = webClient.getPage(getBaseUri());
+ try {
+ // todo fix it
+ //homePage.getAnchorByHref("/logout").click();
Review Comment:
Log out or remove
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@shiro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org