kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Add new device saves this device when given its localhost address

Open rtibblesbot opened this issue 1 week ago • 1 comments

❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Target branch: develop

Observed behavior

  • Add new device with localhost:8000, on a device serving on port 8000, saves this device at http://localhost:8000/.
  • 127.0.0.1:8000 and the LAN address get the field error "Could not connect to this device".
  • NetworkClient.discover_from_address skips only the URLs get_urls() returns, and localhost is never one of them: client.py#L154-L157.
  • Once saved, the same address is returned from the saved device without a request: client.py#L109-L125.

Expected behavior

An address that answers /api/public/info/ with this device's own instance ID is refused like 127.0.0.1:8000.

User-facing consequences

Select device lists this device as a source for its own channel and facility imports.

Steps to reproduce

  1. Sign in as a super admin on a device serving on port 8000.
  2. Device > Channels > Import > Local network or internet > Continue > Add new device.
  3. Enter localhost:8000 as Full network address, fill in Name, select Add.
  4. Select device shows the new device.

The same result without a browser, in kolibri/core/discovery/test/test_network_utils.py's NetworkClientTestCase; this passes on develop:

@mock.patch.object(
    requests.Session, "request", mock_happy_request("http://localhost:8000/")
)
def test_discover_from_address__returns_own_instance_at_localhost(self):
    own_instance_id = InstanceIDModel.get_or_create_current_instance()[0].id
    with mock.patch.dict(mock_device_info, {"instance_id": own_instance_id}):
        client = NetworkClient.discover_from_address("localhost:8000")
    self.assertEqual(client.base_url, "http://localhost:8000/")

Context

  • Kolibri develop at 758605b764, Linux, no URL_PATH_PREFIX.
  • The browser steps ran on #16072's branch at 2d9c5f6274, which returns the same result as develop for this address.

Acceptance Criteria

  • [ ] Add new device with localhost:<port> of this device shows "Could not connect to this device" and saves nothing.
  • [ ] A saved device whose instance ID is this device's is not returned by discover_from_address.
  • [ ] When the entered address reports this device's instance ID, no device at another port or scheme of that host is saved in its place.
  • [ ] A different Kolibri at an address get_urls() does not list is still added in one request.

AI usage

Written by rtibblesbot, an LLM-based coding agent running Claude Code, from its browser QA of #16072 and a run of discover_from_address on develop.

rtibblesbot avatar Nov 27 '26 11:11 rtibblesbot

Hi! 👋

Thanks so much for your interest! This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues. If there are no unassigned 'help wanted' issues available, please wait until new ones are added.

We really appreciate your willingness to help. 😊

Are you preparing for Google Summer of Code? See our GSoC guidelines.

learning-equality-bot avatar Nov 27 '26 15:11 learning-equality-bot