snoopdave commented on code in PR #191:
URL: https://github.com/apache/roller/pull/191#discussion_r4040830256


##########
app/src/main/java/org/apache/roller/weblogger/ui/rendering/plugins/comments/LdapCommentAuthenticator.java:
##########
@@ -84,14 +85,14 @@ public String getHtml(HttpServletRequest request) {
                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(StringEscapeUtils.escapeHtml4(ldapPass)).append("\">");

Review Comment:
   🤖Claude: fixed by removing the `value` attribute from the password input 
entirely, so the submitted password is no longer written into the rendered 
markup. The now-unused `ldapPass`/`ldapPassTemp` locals in `getHtml` were 
dropped with it; `authenticate()` still reads the parameter straight off the 
request, so sign-in is unaffected. Added `omitsSubmittedPasswordFromMarkup` as 
a regression test, and updated `preservesOrdinaryFormValues` (and the shared 
`assertFields` helper) which previously asserted the round-trip. Verified 
red/green on JDK 11: restoring the `value` attribute fails the new test.



##########
app/src/test/java/org/apache/roller/weblogger/ui/rendering/plugins/comments/LdapCommentAuthenticatorTest.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.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", 
"sample-pass");
+    }
+
+    @Test
+    void formatsPunctuationInFormValues() {
+        String value = "A&B \"quoted\" <label> 'name'";
+        String formatted = "A&amp;B &quot;quoted&quot; &lt;label&gt; 'name'";
+        assertFields(renderReturningVisit(value, value), formatted, formatted);
+    }
+
+    @Test
+    void preservesLiteralEntityText() {
+        assertFields(renderReturningVisit("&quot;", "&#34;"), "&amp;quot;", 
"&amp;#34;");
+    }
+
+    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 password) {
+        assertTrue(html.contains("<input name=\"ldapUser\" value=\"" + user + 
"\">"));

Review Comment:
   🤖Claude: fixed by giving both assertions the supplier-message overload, so a 
failure now names the expected markup and prints the actual HTML instead of 
just `expected: <true> but was: <false>`. Confirmed against a deliberately 
broken build — the failure now reads `password written into markup: 
<p>...<input type="password" name="ldapPass" value="sample-pass"></p>`, which 
identifies the offending field directly.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to