Home servers over plain HTTP, on the home network only
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m1s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m58s

Ported from release 0.108.43.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-06 03:51:15 +00:00
co-authored by Claude Opus 5.5
parent 7835703cb2
commit c1d985ed5e
8 changed files with 153 additions and 25 deletions
@@ -0,0 +1,58 @@
package tv.orbit.classic
import org.junit.After
import org.junit.Assert.*
import org.junit.Test
import java.net.InetAddress
import java.net.URI
/** Home servers over plain HTTP (Paul, 6 November 2026): private addresses only, checked on every connection; HTTPS everywhere else. */
class HomeServerTest {
@After fun reset() { EmbyServer.origin = EmbyServer.DEFAULT }
private fun ip(text: String) = InetAddress.getByName(text)
@Test fun plainHttpOnlyForAHomeAddress() {
assertEquals("http://192.168.1.20:8096", EmbyServer.normalise("http://192.168.1.20:8096"))
assertEquals("http://10.0.0.5:8096", EmbyServer.normalise("http://10.0.0.5:8096/emby"))
assertEquals("http://172.20.1.2", EmbyServer.normalise("HTTP://172.20.1.2:80/"))
assertEquals("http://nas.local:8096", EmbyServer.normalise("http://NAS.local:8096"))
assertEquals("http://media.home.arpa:8096", EmbyServer.normalise("http://media.home.arpa:8096"))
assertEquals("http://[fd12::5]:8096", EmbyServer.normalise("http://[fd12::5]:8096"))
// Public addresses, ordinary names and the edges of the private ranges: refused.
listOf("http://8.8.8.8:8096", "http://emby.example.com", "http://172.32.0.1", "http://172.15.0.1", "http://192.169.0.1", "http://127.0.0.1:8096",
"http://169.254.1.1", "http://local", "http://example.com.local.evil.com", "http://[2001:db8::1]")
.forEach { assertNull(it, EmbyServer.normalise(it)) }
// A bare address still means HTTPS.
assertEquals("https://192.168.1.20:8096", EmbyServer.normalise("192.168.1.20:8096"))
}
@Test fun everyConnectionChecksTheNameStillLeadsHome() {
EmbyServer.checkHomeConnection("http://nas.local:8096") { listOf(ip("192.168.0.9")) }
assertThrows(EmbyCheckException::class.java) { EmbyServer.checkHomeConnection("http://nas.local:8096") { listOf(ip("192.168.0.9"), ip("93.184.216.34")) } }
assertThrows(EmbyCheckException::class.java) { EmbyServer.checkHomeConnection("http://nas.local:8096") { listOf(ip("93.184.216.34")) } }
assertThrows(EmbyCheckException::class.java) { EmbyServer.checkHomeConnection("http://nas.local:8096") { emptyList() } }
// HTTPS servers aren't touched by this check.
EmbyServer.checkHomeConnection(EmbyServer.DEFAULT) { throw AssertionError("not resolved") }
}
@Test fun mediaUsesPlainHttpOnlyToTheHomeServerItself() {
val home = "http://192.168.1.20:8096"
assertTrue(PlaybackUrls.isProvider(URI("$home/emby/Videos/1/stream.mkv"), home))
assertFalse(PlaybackUrls.isProvider(URI("https://192.168.1.20:8096/emby/Videos/1/stream.mkv"), home))
assertFalse(PlaybackUrls.isProvider(URI("http://192.168.1.21:8096/v"), home))
assertEquals("$home/emby/Videos/1/stream.mkv", PlaybackUrls.resolve("/emby/Videos/1/stream.mkv?api_key=t", "$home/emby/", "t", home))
// Plain HTTP anywhere else is refused, home server or not.
assertThrows(EmbyCheckException::class.java) { PlaybackUrls.resolve("http://cdn.example.com/v.mkv", "$home/emby/", "t", home) }
assertThrows(EmbyCheckException::class.java) { PlaybackUrls.resolve("http://cdn.example.com/v.mkv", "${EmbyServer.DEFAULT}/emby/", "t", EmbyServer.DEFAULT) }
assertThrows(EmbyCheckException::class.java) { PlaybackUrls.resolve("/emby/v.mkv", "http://192.168.1.20:8096/emby/", "t", EmbyServer.DEFAULT) }
// A session on a home server sends its token to that server only.
val session = EmbySampleSession(HttpsEmbyTransport("fixture-device", home), "fixture-token", "fixture-user", EmbySample(emptyList(), 0))
assertEquals(mapOf("X-Emby-Token" to "fixture-token"), session.mediaHeaders("$home/emby/Videos/1/stream.mkv"))
assertTrue(session.mediaHeaders("http://192.168.1.21:8096/v").isEmpty())
}
@Test fun aHomeServerSignInIsSavedAndItsWorkspaceIsItsOwn() {
assertTrue(Workspaces.keyOf("http://192.168.1.20:8096") != Workspaces.keyOf("https://192.168.1.20:8096"))
assertEquals("http://192.168.1.20:8096", EmbyServer.normalise("http://192.168.1.20:8096"))
}
}