This is an automated email from the ASF dual-hosted git repository.
snoopdave pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/roller.git
The following commit(s) were added to refs/heads/master by this push:
new 59aeab100 Format LDAP comment form values consistently (#191)
59aeab100 is described below
commit 59aeab100bb94dd4258957c7fc03603b650a4fa0
Author: David M. Johnson <[email protected]>
AuthorDate: Thu Sep 17 15:52:28 2026 -0400
Format LDAP comment form values consistently (#191)
* Format LDAP comment form values consistently
* Render the LDAP comment password field without a value attribute
The password input is returned with no value, so a submitted password is
not written into the markup sent back to the browser. The locals that
carried it through getHtml go with it. Authentication reads the parameter
from the request, so signing in is unchanged.
Test assertions carry supplier messages, so a failure names the expected
markup and prints the actual HTML rather than reporting only true/false.
omitsSubmittedPasswordFromMarkup covers the rendering.
Claude-Session: https://claude.ai/code/session_015X69HHQ5XnjRkJP8ymzwFf
---
.../plugins/comments/LdapCommentAuthenticator.java | 9 +-
.../comments/LdapCommentAuthenticatorTest.java | 96 ++++++++++++++++++++++
2 files changed, 99 insertions(+), 6 deletions(-)
diff --git
a/app/src/main/java/org/apache/roller/weblogger/ui/rendering/plugins/comments/LdapCommentAuthenticator.java
b/app/src/main/java/org/apache/roller/weblogger/ui/rendering/plugins/comments/LdapCommentAuthenticator.java
index 27a5e1e47..b851048ff 100644
---
a/app/src/main/java/org/apache/roller/weblogger/ui/rendering/plugins/comments/LdapCommentAuthenticator.java
+++
b/app/src/main/java/org/apache/roller/weblogger/ui/rendering/plugins/comments/LdapCommentAuthenticator.java
@@ -29,6 +29,7 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.commons.text.StringEscapeUtils;
import org.apache.roller.weblogger.config.WebloggerConfig;
import org.apache.roller.weblogger.util.I18nMessages;
import org.springframework.util.StringUtils;
@@ -62,7 +63,6 @@ public class LdapCommentAuthenticator implements
CommentAuthenticator {
@Override
public String getHtml(HttpServletRequest request) {
String ldapUser = "";
- String ldapPass = "";
HttpSession session = request.getSession(true);
if (session.getAttribute("ldapUser") == null) {
session.setAttribute("ldapUser", "");
@@ -70,9 +70,7 @@ public class LdapCommentAuthenticator implements
CommentAuthenticator {
} else {
// preserve user data
String ldapUserTemp = request.getParameter("ldapUser");
- String ldapPassTemp = request.getParameter("ldapPass");
ldapUser = ldapUserTemp != null ? ldapUserTemp : "";
- ldapPass = ldapPassTemp != null ? ldapPassTemp : "";
}
Locale locale = CommentAuthenticatorUtils.getLocale(request);
@@ -84,14 +82,13 @@ public class LdapCommentAuthenticator implements
CommentAuthenticator {
sb.append("</p>");
sb.append("<p>");
sb.append("<input name=\"ldapUser\" value=\"");
- sb.append(ldapUser + "\">");
+
sb.append(StringEscapeUtils.escapeHtml4(ldapUser)).append("\">");
sb.append("</p>");
sb.append("<p>");
sb.append(messages.getString("comments.ldapAuthenticatorPassword"));
sb.append("</p>");
sb.append("<p>");
- sb.append("<input type=\"password\" name=\"ldapPass\"
value=\"");
- sb.append(ldapPass + "\">");
+ sb.append("<input type=\"password\" name=\"ldapPass\">");
sb.append("</p>");
return sb.toString();
diff --git
a/app/src/test/java/org/apache/roller/weblogger/ui/rendering/plugins/comments/LdapCommentAuthenticatorTest.java
b/app/src/test/java/org/apache/roller/weblogger/ui/rendering/plugins/comments/LdapCommentAuthenticatorTest.java
new file mode 100644
index 000000000..08e25cfc1
--- /dev/null
+++
b/app/src/test/java/org/apache/roller/weblogger/ui/rendering/plugins/comments/LdapCommentAuthenticatorTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.roller.weblogger.ui.rendering.plugins.comments;
+
+import java.util.Locale;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+class LdapCommentAuthenticatorTest {
+
+ @Test
+ void rendersEmptyFieldsOnFirstVisit() {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpSession session = mock(HttpSession.class);
+ when(request.getSession(true)).thenReturn(session);
+ String html = render(request);
+ assertFields(html, "");
+ verify(session).setAttribute("ldapUser", "");
+ verify(session).setAttribute("ldapPass", "");
+ }
+
+ @Test
+ void rendersMissingValuesAsEmpty() {
+ assertFields(renderReturningVisit(null, null), "");
+ }
+
+ @Test
+ void preservesOrdinaryFormValues() {
+ assertFields(renderReturningVisit("reader", "sample-pass"), "reader");
+ }
+
+ @Test
+ void omitsSubmittedPasswordFromMarkup() {
+ String html = renderReturningVisit("reader", "sample-pass");
+ assertFalse(html.contains("sample-pass"), () -> "password written into
markup: " + html);
+ }
+
+ @Test
+ void formatsPunctuationInFormValues() {
+ String value = "A&B \"quoted\" <label> 'name'";
+ String formatted = "A&B "quoted" <label> 'name'";
+ assertFields(renderReturningVisit(value, value), formatted);
+ }
+
+ @Test
+ void preservesLiteralEntityText() {
+ assertFields(renderReturningVisit(""", """), "&quot;");
+ }
+
+ private String renderReturningVisit(String user, String password) {
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpSession session = mock(HttpSession.class);
+ when(request.getSession(true)).thenReturn(session);
+ when(session.getAttribute("ldapUser")).thenReturn("");
+ when(request.getParameter("ldapUser")).thenReturn(user);
+ when(request.getParameter("ldapPass")).thenReturn(password);
+ return render(request);
+ }
+
+ private String render(HttpServletRequest request) {
+ try (MockedStatic<CommentAuthenticatorUtils> locales =
mockStatic(CommentAuthenticatorUtils.class)) {
+ locales.when(() ->
CommentAuthenticatorUtils.getLocale(request)).thenReturn(Locale.ENGLISH);
+ return new LdapCommentAuthenticator().getHtml(request);
+ }
+ }
+
+ private void assertFields(String html, String user) {
+ String userField = "<input name=\"ldapUser\" value=\"" + user + "\">";
+ assertTrue(html.contains(userField), () -> "expected " + userField + "
in " + html);
+ String passwordField = "<input type=\"password\" name=\"ldapPass\">";
+ assertTrue(html.contains(passwordField), () -> "expected " +
passwordField + " in " + html);
+ }
+}