/
/
/
1"""Tests for the streamserver publish address selection."""
2
3from music_assistant.controllers.streams.controller import _get_publish_addresses
4
5ALL_ADDRESSES = ("192.168.1.10", "10.0.0.5", "172.17.0.1", "fd00::10")
6
7
8def test_wildcard_bind_publishes_every_address() -> None:
9 """A wildcard bind publishes every detected address, best candidate first."""
10 assert _get_publish_addresses("0.0.0.0", None, ALL_ADDRESSES) == [
11 "192.168.1.10",
12 "10.0.0.5",
13 "172.17.0.1",
14 "fd00::10",
15 ]
16 assert _get_publish_addresses("::", None, ALL_ADDRESSES) == list(ALL_ADDRESSES)
17 assert _get_publish_addresses("", None, ALL_ADDRESSES) == list(ALL_ADDRESSES)
18
19
20def test_specific_bind_publishes_only_that_address() -> None:
21 """Binding to one specific address publishes only that address."""
22 assert _get_publish_addresses("192.168.1.10", None, ALL_ADDRESSES) == ["192.168.1.10"]
23 assert _get_publish_addresses("fd00::10", None, ALL_ADDRESSES) == ["fd00::10"]
24
25
26def test_configured_publish_ip_is_authoritative() -> None:
27 """An explicitly configured publish IP is published on its own, never widened."""
28 assert _get_publish_addresses("0.0.0.0", "10.0.0.5", ALL_ADDRESSES) == ["10.0.0.5"]
29 # ...even when it is not an address of this host at all (NAT/port forward setups)
30 assert _get_publish_addresses("0.0.0.0", "203.0.113.7", ALL_ADDRESSES) == ["203.0.113.7"]
31 # ...and it outranks a specific bind IP, matching how publish_ip itself resolves
32 assert _get_publish_addresses("192.168.1.10", "203.0.113.7", ALL_ADDRESSES) == ["203.0.113.7"]
33
34
35def test_single_homed_host_is_unchanged() -> None:
36 """The common single-address host keeps publishing exactly that one address."""
37 assert _get_publish_addresses("0.0.0.0", None, ("192.168.1.10",)) == ["192.168.1.10"]
38