Skip to content

fix: use 127.0.0.1 instead of localIP in LockdownModeTaskTestCase#605

Open
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-lockdown-mode-task-test
Open

fix: use 127.0.0.1 instead of localIP in LockdownModeTaskTestCase#605
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-lockdown-mode-task-test

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 31, 2026

  • Add "Portions copyright 2026 3A Systems, LLC." to the copyright header of modified file LockdownModeTaskTestCase.java
Original prompt

Problem

The CI job for OpenIdentityPlatform/OpenDJ is failing in org.opends.server.tasks.LockdownModeTaskTestCase#testLockdownModeTasks with:

java.lang.AssertionError: expected [0] but found [91]
System.err: The LDAP search request failed: 91 (Connect Error) - No route to host

The failure occurs at line 102 of opendj-server-legacy/src/test/java/org/opends/server/tasks/LockdownModeTaskTestCase.java.

Root Cause

The test calls InetAddress.getLocalHost() to get the machine's primary IP address and uses that IP to connect to the embedded test LDAP server. In CI environments (e.g., macOS GitHub Actions runners), InetAddress.getLocalHost() returns a non-loopback IP address, but the embedded test server only listens on 127.0.0.1. This causes a "No route to host" / connect error (LDAP result code 91).

The first assertion at line 102:

assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);

uses localIP (from InetAddress.getLocalHost().getHostAddress()) as the -h argument, which fails when localIP is not 127.0.0.1.

The final assertion at line 273 also uses localIP for the same reason.

Fix

In opendj-server-legacy/src/test/java/org/opends/server/tasks/LockdownModeTaskTestCase.java, make the following changes:

1. Line ~95 — change -h from localIP to "127.0.0.1" for the initial unauthenticated search

Before:

String[] args =
{
  "-h", localIP,
  "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
  "-b", "",
  "-s", "base",
  "--noPropertiesFile",
  "(objectClass=*)"
};
assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);

After:

String[] args =
{
  "-h", "127.0.0.1",
  "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
  "-b", "",
  "-s", "base",
  "--noPropertiesFile",
  "(objectClass=*)"
};
assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);

2. Lines ~265–273 — change -h from localIP to "127.0.0.1" for the final post-lockdown-exit search

Before:

args = new String[]
{
  "-h", localIP,
  "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
  "-b", "",
  "-s", "base",
  "--noPropertiesFile",
  "(objectClass=*)"
};
assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);

After:

args = new String[]
{
  "-h", "127.0.0.1",
  "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
  "-b", "",
  "-s", "base",
  "--noPropertiesFile",
  "(objectClass=*)"
};
assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);

The localIP and isLoopback variables are still needed for the conditional checks in the middle of the test (lines 134–183) and should be kept.

File to Modify

  • opendj-server-legacy/src/test/java/org/opends/server/tasks/LockdownModeTaskTestCase.java

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Assistant: Let me fetch the job logs to analyze the failure.

Assistant: ## Root Cause

The failing test is LockdownModeTaskTestCase#testLockdownModeTasks, and the key error is:

java.lang.AssertionError: expected [0] but found [91]
System.err contents: The LDAP search request failed: 91 (Connect Error) - No route to host

Error code 91 is an LDAP "Connect Error". The failure occurs at line 102:

assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);

The test resolves InetAddress.getLocalHost() and uses the resulting IP (which, in the CI/macOS runner, is not the loopback address 127.0.0.1). It then tries to connect to the LDAP server on that non-loopback IP — but the server is only listening on localhost/127.0.0.1, causing a "No route to host" error.

Solution

The fix is to always use 127.0.0.1 for the initial unauthenticated search (line 90–102) instead of localIP, since the test server only binds to the loopback interface. The localIP/isLoopback logic is still needed for the conditional checks further in the test, but the very first search should be safe and unconditional.

Change lines 90–102 from:

InetAddress localAddress = InetAddress.getLocalHost();
String localIP = localAddress.getHostAddress();
boolean isLoopback = localAddress.isLoopbackAddress();
String[] args =
{
  "-h", localIP,   // ← this fails when localIP is not 127.0.0.1
  "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
  "-b", "",
  "-s", "base",
  "--noPropertiesFile",
  "(objectClass=*)"
};
assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args)...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

Copilot AI changed the title [WIP] Fix LockdownModeTaskTestCase to use loopback IP fix: use 127.0.0.1 instead of localIP in LockdownModeTaskTestCase Mar 31, 2026
Copilot AI requested a review from vharseko March 31, 2026 07:26
@vharseko vharseko requested a review from maximthomas March 31, 2026 09:36
@vharseko vharseko marked this pull request as ready for review March 31, 2026 14:37
Copilot AI requested a review from vharseko March 31, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants