nick-boss-tech commented on code in PR #4996:
URL: https://github.com/apache/solr/pull/4996#discussion_r4160951510


##########
solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java:
##########
@@ -255,19 +257,47 @@ public void doTestHandlerPathUnchanged() {
 
   @Test
   public void testUrlAllowList() throws Exception {
-    // Run another test with URL allow-list enabled and allow-list is empty.
-    // Expect an exception because the leader URL is not allowed.
+    // Allow-list denial during doTestDetails() is not reliably a 
SolrException (SOLR-18280).
     System.setProperty(AllowListUrlChecker.ENABLE_URL_ALLOW_LIST, "true");
-    SolrException e = expectThrows(SolrException.class, this::doTestDetails);
-    assertTrue(
-        e.getMessage()
-            .contains("nor in the configured '" + 
AllowListUrlChecker.URL_ALLOW_LIST + "'"));
-
-    // Set the allow-list to allow the leader URL.
-    // Expect the same test to pass now.
-    System.setProperty(
-        TEST_URL_ALLOW_LIST, leaderJetty.getBaseUrl() + "," + 
followerJetty.getBaseUrl());
-    doTestDetails();
+    try {
+      leaderJetty.stop();
+      leaderJetty = createAndStartJetty(leader);
+      leaderClient.close();
+      leaderClient =
+          ReplicationTestHelper.createNewSolrClient(
+              buildUrl(leaderJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
+
+      AllowListUrlChecker checker = 
leaderJetty.getCoreContainer().getAllowListUrlChecker();
+      assertTrue(checker.isEnabled());
+      SolrException denied =
+          expectThrows(
+              SolrException.class,
+              () -> 
checker.checkAllowList(List.of("http://127.0.0.1:7574/solr/collection1";)));
+      assertThat(denied.getMessage(), 
containsString(AllowListUrlChecker.URL_ALLOW_LIST));
+
+      System.setProperty(TEST_URL_ALLOW_LIST, 
buildUrl(leaderJetty.getLocalPort()));
+      follower.setTestPort(leaderJetty.getLocalPort());
+      follower.copyConfigFile(CONF_DIR + "solrconfig-follower.xml", 
"solrconfig.xml");
+      followerJetty.stop();
+      followerJetty = createAndStartJetty(follower);
+      followerClient.close();
+      followerClient =
+          ReplicationTestHelper.createNewSolrClient(
+              buildUrl(followerJetty.getLocalPort()), DEFAULT_TEST_CORENAME);
+
+      followerJetty
+          .getCoreContainer()
+          .getAllowListUrlChecker()
+          .checkAllowList(List.of(buildUrl(leaderJetty.getLocalPort())));
+
+      index(leaderClient, "id", "allow-list-1", "name", "allowed");
+      leaderClient.commit();
+      pullFromTo(leaderJetty, followerJetty);
+      rQuery(1, "id:allow-list-1", followerClient);
+    } finally {
+      System.clearProperty(TEST_URL_ALLOW_LIST);

Review Comment:
   🤖 *AI text below* 🤖 *(posted on behalf of Nick Shanin)*
   
   Good question — there are actually two clears: this finally block and the 
same pair in tearDown(). Before this PR, nothing cleared these properties at 
all. setUp sets the flag to "false", the old test flipped it to "true", and a 
failure mid-test would leak that into whatever ran next in the same JVM.
   
   The tearDown clear is the one that matters: it runs after every test even on 
failure. The finally block here is redundant with it — JUnit always runs 
tearDown, so the finally can't do anything tearDown wouldn't already do.
   
   Want me to remove the finally block and keep just the tearDown clear, or 
keep both?



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to