0.126.0 (versionCode 323): no server built into the app
The address field starts empty on a new box, and its first server becomes its original. A box from before reads its original server once from its own saved sign-in and notes it beside its data; nothing else is moved or changed. Paul's own decisions by item are kept to his server by a SHA-256 of its address. The release gate refuses an APK that contains a server address. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,8 +9,8 @@ android {
|
||||
applicationId = "tv.orbit.classic"
|
||||
minSdk = 26
|
||||
targetSdk = 36
|
||||
versionCode = 322
|
||||
versionName = "0.125.0-taste2"
|
||||
versionCode = 323
|
||||
versionName = "0.126.0-noserver"
|
||||
}
|
||||
buildFeatures { compose = true }
|
||||
// The finished build for the TVs (Paul, 6 November 2026: the test build stuttered on the box). Not debuggable, so
|
||||
|
||||
@@ -99,7 +99,7 @@ internal data class ChannelProgramming(val number: Int, val name: String, val se
|
||||
/** Marathon (Create your own): this many episodes of a show back to back before the next takes over; 0 for none. */
|
||||
val marathon: Int = 0) {
|
||||
/** The items taken off this channel on the server signed in to: [withdrawnOnOriginal] there, none anywhere else. */
|
||||
val withdrawn: Set<String> get() = if (Workspaces.originalOpen) withdrawnOnOriginal else emptySet()
|
||||
val withdrawn: Set<String> get() = if (Workspaces.paulsServerOpen) withdrawnOnOriginal else emptySet()
|
||||
/** A show's weight here, by its tier (a show the brief doesn't name counts as supporting), scaled by [catalogueScaleHours]. */
|
||||
fun weightOf(show: PoolSeries): Double {
|
||||
val tier = tierWeights?.get(seriesKey(show.title)) ?: TIER_SUPPORTING
|
||||
|
||||
@@ -15,9 +15,8 @@ import java.net.URI
|
||||
* and every connection checks again that the name still leads to a private address. Never a public one.
|
||||
*/
|
||||
internal object EmbyServer {
|
||||
/** Paul's server: what a box signed in before addresses could be typed was always using. */
|
||||
const val DEFAULT = "https://bk2.appboxmanager.xyz"
|
||||
@Volatile var origin: String = DEFAULT
|
||||
/** The server in use: empty until one is signed in to. No server is built in (launch blocker, 10 November 2026). */
|
||||
@Volatile var origin: String = ""
|
||||
val host: String get() = URI(origin).host
|
||||
val port: Int get() = URI(origin).port
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ internal class PremiereCall(val itemId: String, val title: String, val premiere:
|
||||
val decidedOn: LocalDate = LocalDate.of(2026, 11, 5))
|
||||
|
||||
/** Paul's calls, by item on the original server: on any other server there are none, and its own Chair decides afresh. */
|
||||
internal val PremiereCalls: List<PremiereCall> get() = if (Workspaces.originalOpen) PaulsPremiereCalls else emptyList()
|
||||
internal val PremiereCalls: List<PremiereCall> get() = if (Workspaces.paulsServerOpen) PaulsPremiereCalls else emptyList()
|
||||
|
||||
private val PaulsPremiereCalls = listOf(
|
||||
PremiereCall("7789551", "Avatar: Fire and Ash", true, 303, true, "approved by Paul on 5 November 2026: Premiere debut, then Orbit Sci-Fi"),
|
||||
|
||||
@@ -74,6 +74,13 @@ internal class RememberedConnectionStore(path: File, private val alias: String,
|
||||
runCatching { android.util.Log.i("OrbitStartup", "saved sign-in keyMs=$keyMs openMs=$openMs decodeMs=${System.currentTimeMillis() - started - keyMs - openMs}") }
|
||||
}
|
||||
}
|
||||
/** The server a saved sign-in belongs to, whichever it is, or null if there's none or it can't be read. Reads only. */
|
||||
@Synchronized fun savedOrigin(): String? = runCatching {
|
||||
if (!file.baseFile.exists() && !File(file.baseFile.path + ".bak").exists()) return null
|
||||
file.openRead().use { input ->
|
||||
RememberedStateCodec.decode(ConnectionCipher.open(key(false), input.readBytesLimited(RememberedStateCodec.MAX_BYTES + 29))).origin
|
||||
}
|
||||
}.getOrNull()
|
||||
/** Opens the saved sign-in in the background as Orbit starts, so it's ready by the time the screen asks for it. */
|
||||
fun warm() { Thread({ runCatching { load() } }, "orbit-warm-signin").apply { isDaemon = true }.start() }
|
||||
@Synchronized fun save(state: RememberedState, ticket: Long): Boolean {
|
||||
|
||||
@@ -17,10 +17,14 @@ import java.security.MessageDigest
|
||||
* The data a box already has belongs to the original server (the only one Orbit could use before an address could be typed
|
||||
* in), and it stays exactly where it always was: nothing is moved, copied or rewritten, so an older Orbit still finds all of
|
||||
* it. Any other server's data lives under servers/<key>, where an older Orbit never looks.
|
||||
*
|
||||
* No server is built in (launch blocker, 10 November 2026): the original server is the one named in a small note,
|
||||
* original-server, beside its data. A box from before the note learns it once from its own saved sign-in; a new box's first
|
||||
* server signed in to becomes its original. Until then nothing is open and the sign-in's address field is empty.
|
||||
*/
|
||||
internal class ServerWorkspace(val origin: String, val root: File, val artworkDir: File, val keyAlias: String) {
|
||||
/** The server this box used before addresses could be typed in: its data is the box's existing data, where it was. */
|
||||
val original get() = origin == EmbyServer.DEFAULT
|
||||
internal class ServerWorkspace(val origin: String, val root: File, val artworkDir: File, val keyAlias: String,
|
||||
/** The box's first server, whose data sits at the top of no_backup where it always was (see [Workspaces.originalOrigin]). */
|
||||
val original: Boolean) {
|
||||
val connectionFile get() = File(root, "orbit-connection.v1")
|
||||
val catalogueFile get() = File(root, "catalogue.db")
|
||||
val scheduleDir get() = File(root, "schedule")
|
||||
@@ -38,30 +42,65 @@ internal object Workspaces {
|
||||
private const val ORIGINAL_ALIAS = "orbit-connection-key-v1"
|
||||
private const val ACTIVE_FILE = "active-server"
|
||||
private const val ORIGIN_FILE = "server"
|
||||
private const val ORIGINAL_FILE = "original-server"
|
||||
/**
|
||||
* Paul's own server, as a SHA-256 of its address, so the address itself isn't in the app: his decisions by item apply
|
||||
* there and nowhere else, and a box from before the note whose sign-in can't be read gives its data to that server only.
|
||||
*/
|
||||
private const val PAULS_SERVER_SHA256 = "8a2a645acebc3401b07585a214d4b7dd0f24e254b8377e4b59128931c2376e80"
|
||||
internal var isPaulsServer: (String) -> Boolean = { origin ->
|
||||
MessageDigest.getInstance("SHA-256").digest(origin.toByteArray(Charsets.UTF_8)).joinToString("") { "%02x".format(it) } == PAULS_SERVER_SHA256
|
||||
}
|
||||
|
||||
var current by mutableStateOf<ServerWorkspace?>(null)
|
||||
private set
|
||||
/** Whether the original server is the one open (or none is yet, as in tests): Paul's own decisions by item apply only there. */
|
||||
val originalOpen: Boolean get() = current?.original ?: true
|
||||
/** Whether Paul's server is the one open (or none is yet, as in tests): his own decisions by item apply only there. */
|
||||
val paulsServerOpen: Boolean get() = current?.origin?.let { isPaulsServer(it) } ?: true
|
||||
|
||||
/** A short, stable folder name for [origin]. */
|
||||
fun keyOf(origin: String): String = MessageDigest.getInstance("SHA-256").digest(origin.toByteArray(Charsets.UTF_8))
|
||||
.take(8).joinToString("") { "%02x".format(it) }
|
||||
|
||||
private fun readOrigin(file: File): String? = runCatching { file.takeIf { it.isFile && it.length() <= 300 }?.readText()?.trim() }.getOrNull()
|
||||
?.takeIf { EmbyServer.normalise(it) == it }
|
||||
|
||||
/** The box's original server, from its note; null on a new box, or a box from before the note until it learns it. */
|
||||
fun originalOrigin(noBackup: File): String? = readOrigin(File(noBackup, ORIGINAL_FILE))
|
||||
|
||||
private fun rootLayout(noBackup: File, cacheDir: File, origin: String) = ServerWorkspace(origin, noBackup, File(cacheDir, "artwork"), ORIGINAL_ALIAS, original = true)
|
||||
|
||||
/**
|
||||
* Whether [origin] would be the original server: the one in the note, or, with no note yet, the first server on a box with
|
||||
* no data of its own, or Paul's server on a box from before the note (the only server an older Orbit could use).
|
||||
*/
|
||||
private fun isOriginal(noBackup: File, cacheDir: File, origin: String): Boolean = originalOrigin(noBackup)?.let { it == origin }
|
||||
?: (!hasData(rootLayout(noBackup, cacheDir, origin)) || isPaulsServer(origin))
|
||||
|
||||
/** Where [origin]'s data lives under [noBackup] and [cacheDir]. Nothing is created here. */
|
||||
fun layout(noBackup: File, cacheDir: File, origin: String): ServerWorkspace =
|
||||
if (origin == EmbyServer.DEFAULT) ServerWorkspace(origin, noBackup, File(cacheDir, "artwork"), ORIGINAL_ALIAS)
|
||||
else keyOf(origin).let { key -> ServerWorkspace(origin, File(noBackup, "servers/$key"), File(cacheDir, "artwork-$key"), "$ORIGINAL_ALIAS-$key") }
|
||||
if (isOriginal(noBackup, cacheDir, origin)) rootLayout(noBackup, cacheDir, origin)
|
||||
else keyOf(origin).let { key -> ServerWorkspace(origin, File(noBackup, "servers/$key"), File(cacheDir, "artwork-$key"), "$ORIGINAL_ALIAS-$key", original = false) }
|
||||
|
||||
/** The server whose workspace was open last: the original server until another has been signed in to. */
|
||||
fun activeOrigin(noBackup: File): String {
|
||||
val saved = runCatching { File(noBackup, ACTIVE_FILE).takeIf { it.isFile && it.length() <= 300 }?.readText()?.trim() }.getOrNull() ?: return EmbyServer.DEFAULT
|
||||
return saved.takeIf { EmbyServer.normalise(it) == it } ?: EmbyServer.DEFAULT
|
||||
/**
|
||||
* The server whose workspace was open last, or the original server, or null when there's none yet. A box from before the
|
||||
* note has its original server's address only in its saved sign-in: [savedOrigin] reads it from there.
|
||||
*/
|
||||
fun activeOrigin(noBackup: File, savedOrigin: () -> String? = { null }): String? =
|
||||
readOrigin(File(noBackup, ACTIVE_FILE)) ?: originalOrigin(noBackup)
|
||||
?: if (File(noBackup, "orbit-connection.v1").exists()) savedOrigin()?.takeIf { EmbyServer.normalise(it) == it } else null
|
||||
|
||||
/** The open workspace, opening the last one used if none is yet; with no server yet, the box's own empty place for one. */
|
||||
@Synchronized fun current(context: Context): ServerWorkspace {
|
||||
current?.let { return it }
|
||||
val app = context.applicationContext
|
||||
val origin = activeOrigin(app.noBackupFilesDir) {
|
||||
// Once, on a box from before the note: the address its own sign-in was saved with.
|
||||
RememberedConnectionStore(File(app.noBackupFilesDir, "orbit-connection.v1"), ORIGINAL_ALIAS, "").savedOrigin()
|
||||
}
|
||||
if (origin != null) return open(app, origin)
|
||||
return rootLayout(app.noBackupFilesDir, app.cacheDir, "").also { it.appContext = app; current = it }
|
||||
}
|
||||
|
||||
/** The open workspace, opening the last one used if none is yet. */
|
||||
@Synchronized fun current(context: Context): ServerWorkspace = current ?: open(context, activeOrigin(context.noBackupFilesDir))
|
||||
|
||||
@Synchronized fun open(context: Context, origin: String): ServerWorkspace {
|
||||
val app = context.applicationContext
|
||||
return openIn(app.noBackupFilesDir, app.cacheDir, origin) { it.appContext = app }
|
||||
@@ -76,7 +115,8 @@ internal object Workspaces {
|
||||
require(EmbyServer.normalise(origin) == origin)
|
||||
if (current?.origin == origin) return current!!
|
||||
val next = layout(noBackup, cacheDir, origin).also(prepare)
|
||||
if (!next.original) {
|
||||
if (next.original) { if (originalOrigin(noBackup) == null) replace(File(noBackup, ORIGINAL_FILE), origin) }
|
||||
else {
|
||||
val note = File(next.root, ORIGIN_FILE)
|
||||
if (note.exists()) check(note.readText().trim() == origin) { "A server folder belongs to another address." }
|
||||
else { next.root.mkdirs(); replace(note, origin) }
|
||||
@@ -93,7 +133,8 @@ internal object Workspaces {
|
||||
}
|
||||
|
||||
/** For tests: no workspace open. */
|
||||
@Synchronized internal fun reset() { current?.close(); current = null; EmbyServer.origin = EmbyServer.DEFAULT }
|
||||
@Synchronized internal fun reset() { current?.close(); current = null; EmbyServer.origin = ""; isPaulsServer = defaultPaulsCheck }
|
||||
private val defaultPaulsCheck = isPaulsServer
|
||||
|
||||
/** A small file written whole or not at all. */
|
||||
private fun replace(target: File, text: String) {
|
||||
@@ -108,9 +149,10 @@ internal object Workspaces {
|
||||
|
||||
/** Every server with data on this box, the original first if it has any. Read only. */
|
||||
fun known(noBackup: File, cacheDir: File): List<String> {
|
||||
val original = originalOrigin(noBackup)
|
||||
val others = File(noBackup, "servers").listFiles().orEmpty().mapNotNull { dir -> File(dir, ORIGIN_FILE).takeIf { it.isFile }?.readText()?.trim() }
|
||||
.filter { EmbyServer.normalise(it) == it && it != EmbyServer.DEFAULT }.sorted()
|
||||
return (listOf(EmbyServer.DEFAULT) + others).filter { hasData(layout(noBackup, cacheDir, it)) }
|
||||
.filter { EmbyServer.normalise(it) == it && it != original }.sorted()
|
||||
return (listOfNotNull(original) + others).filter { hasData(layout(noBackup, cacheDir, it)) }
|
||||
}
|
||||
fun known(context: Context) = known(context.noBackupFilesDir, context.cacheDir)
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@ import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class AfterDarkMoviesTest {
|
||||
// No server is built in: these sign-ins belong to a made-up one.
|
||||
@org.junit.Before fun server() { EmbyServer.origin = "https://emby.example.com" }
|
||||
@org.junit.After fun noServer() { EmbyServer.origin = "" }
|
||||
private fun movie(id: String, genre: String = "Horror") = JSONObject().put("Id", id).put("Type", "Movie")
|
||||
.put("Name", "Fixture $id").put("ProductionYear", 1999).put("OfficialRating", "18")
|
||||
.put("Genres", JSONArray().put(genre)).put("Container", "mkv").put("RunTimeTicks", 54_000_000_000L)
|
||||
|
||||
@@ -5,6 +5,9 @@ import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class ChannelPresetsTest {
|
||||
// No server is built in: these sign-ins belong to a made-up one.
|
||||
@org.junit.Before fun server() { EmbyServer.origin = "https://emby.example.com" }
|
||||
@org.junit.After fun noServer() { EmbyServer.origin = "" }
|
||||
private fun series(id: String, title: String, year: Int? = null) = SeriesCandidate(id, title, year, "")
|
||||
|
||||
@Test
|
||||
|
||||
@@ -7,6 +7,9 @@ import org.junit.Test
|
||||
import java.net.InetAddress
|
||||
|
||||
class EmbyPlaybackTest {
|
||||
// No server is built in: these sign-ins belong to a made-up one.
|
||||
@org.junit.Before fun server() { EmbyServer.origin = "https://emby.example.com" }
|
||||
@org.junit.After fun noServer() { EmbyServer.origin = "" }
|
||||
private class Fake : EmbyTransport {
|
||||
val requests = mutableListOf<EmbyRequest>()
|
||||
var response = EmbyReply(200, "")
|
||||
@@ -67,7 +70,7 @@ class EmbyPlaybackTest {
|
||||
assertFalse(url.contains("api_key")); assertTrue(url.contains("Static=true"))
|
||||
val cdn = session.mediaUrl("https://media.example.test/file.mkv?signature=fixture-signature")
|
||||
assertTrue(session.mediaHeaders(cdn).isEmpty())
|
||||
assertTrue(session.mediaHeaders("https://bk2.appboxmanager.xyz:444/file").isEmpty())
|
||||
assertTrue(session.mediaHeaders("https://emby.example.com:444/file").isEmpty())
|
||||
}
|
||||
@Test fun rejectsInsecureAddressesAndCredentialsInExternalUrls() {
|
||||
val session = session(Fake())
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.junit.Test
|
||||
import java.net.URI
|
||||
|
||||
class EmbyServerTest {
|
||||
@After fun reset() { EmbyServer.origin = EmbyServer.DEFAULT }
|
||||
@After fun reset() { EmbyServer.origin = "" }
|
||||
|
||||
@Test fun typedAddressesBecomeHttpsOrigins() {
|
||||
assertEquals("https://emby.example.com", EmbyServer.normalise("emby.example.com"))
|
||||
|
||||
@@ -8,7 +8,7 @@ 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 }
|
||||
@After fun reset() { EmbyServer.origin = "" }
|
||||
private fun ip(text: String) = InetAddress.getByName(text)
|
||||
|
||||
@Test fun plainHttpOnlyForAHomeAddress() {
|
||||
@@ -32,7 +32,7 @@ class HomeServerTest {
|
||||
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") }
|
||||
EmbyServer.checkHomeConnection("https://emby.example.com") { throw AssertionError("not resolved") }
|
||||
}
|
||||
|
||||
@Test fun mediaUsesPlainHttpOnlyToTheHomeServerItself() {
|
||||
@@ -43,8 +43,8 @@ class HomeServerTest {
|
||||
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) }
|
||||
assertThrows(EmbyCheckException::class.java) { PlaybackUrls.resolve("http://cdn.example.com/v.mkv", "${"https://emby.example.com"}/emby/", "t", "https://emby.example.com") }
|
||||
assertThrows(EmbyCheckException::class.java) { PlaybackUrls.resolve("/emby/v.mkv", "http://192.168.1.20:8096/emby/", "t", "https://emby.example.com") }
|
||||
// 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"))
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.net.URL
|
||||
* The same code the box runs: sign-in, the catalogue, a channel read, the Drive-In's curated films and a stream.
|
||||
*/
|
||||
class JellyfinLiveTest {
|
||||
@After fun reset() { CuratedDriveInEvents.list = emptyList(); CuratedDriveInEvents.copies = emptyMap(); EmbyServer.origin = EmbyServer.DEFAULT }
|
||||
@After fun reset() { CuratedDriveInEvents.list = emptyList(); CuratedDriveInEvents.copies = emptyMap(); EmbyServer.origin = "" }
|
||||
|
||||
private class MemoryCatalogue : CatalogueSink {
|
||||
val records = mutableListOf<CatalogueRecord>(); var next = 0L; var finished = false
|
||||
|
||||
@@ -16,6 +16,9 @@ import java.security.MessageDigest
|
||||
class PortabilityTest {
|
||||
@get:Rule val folder = TemporaryFolder()
|
||||
private val other = "https://emby.friend.example:8920"
|
||||
/** Paul's server under a made-up address: the app holds only a hash of the real one. */
|
||||
private val paul = "https://paul.example"
|
||||
@org.junit.Before fun paulsServer() { Workspaces.isPaulsServer = { it == paul } }
|
||||
|
||||
@After fun reset() {
|
||||
Workspaces.reset()
|
||||
@@ -87,24 +90,30 @@ class PortabilityTest {
|
||||
@Test fun theOriginalServerIsTodaysDataWhereItIsAndOpeningItWritesNothing() {
|
||||
val (noBackup, cache) = todaysBox()
|
||||
val before = digest(noBackup); val cacheBefore = digest(cache)
|
||||
assertEquals(EmbyServer.DEFAULT, Workspaces.activeOrigin(noBackup))
|
||||
val original = Workspaces.openIn(noBackup, cache, Workspaces.activeOrigin(noBackup))
|
||||
// A box from before the note: its saved sign-in names the server, read once.
|
||||
assertEquals(paul, Workspaces.activeOrigin(noBackup) { paul })
|
||||
val original = Workspaces.openIn(noBackup, cache, Workspaces.activeOrigin(noBackup) { paul }!!)
|
||||
assertTrue(original.original)
|
||||
assertEquals(File(noBackup, "orbit-connection.v1"), original.connectionFile)
|
||||
assertEquals(File(noBackup, "catalogue.db"), original.catalogueFile)
|
||||
assertEquals(File(noBackup, "schedule"), original.scheduleDir)
|
||||
assertEquals(File(cache, "artwork"), original.artworkDir)
|
||||
assertEquals(before, digest(noBackup)); assertEquals(cacheBefore, digest(cache))
|
||||
assertEquals(setOf("orbit-connection.v1", "catalogue.db", "schedule"), noBackup.list()!!.toSet())
|
||||
assertTrue(Workspaces.originalOpen)
|
||||
// Only the note is added; every file that was there is byte for byte the same.
|
||||
assertEquals(before, digest(noBackup).filterKeys { it in before }); assertEquals(cacheBefore, digest(cache))
|
||||
assertEquals(setOf("orbit-connection.v1", "catalogue.db", "schedule", "original-server"), noBackup.list()!!.toSet())
|
||||
assertEquals(paul, Workspaces.originalOrigin(noBackup)); assertEquals(paul, Workspaces.activeOrigin(noBackup))
|
||||
assertTrue(Workspaces.paulsServerOpen)
|
||||
// Opening it again writes nothing at all.
|
||||
Workspaces.reset(); Workspaces.isPaulsServer = { it == paul }
|
||||
val once = digest(noBackup); Workspaces.openIn(noBackup, cache, paul); assertEquals(once, digest(noBackup))
|
||||
}
|
||||
|
||||
@Test fun anotherServerGetsItsOwnFolderAndTodaysDataIsNeverTouched() {
|
||||
val (noBackup, cache) = todaysBox()
|
||||
val before = digest(noBackup)
|
||||
Workspaces.openIn(noBackup, cache, EmbyServer.DEFAULT)
|
||||
Workspaces.openIn(noBackup, cache, paul)
|
||||
val friend = Workspaces.openIn(noBackup, cache, other)
|
||||
assertFalse(friend.original); assertFalse(Workspaces.originalOpen)
|
||||
assertFalse(friend.original); assertFalse(Workspaces.paulsServerOpen)
|
||||
assertEquals(File(noBackup, "servers/${Workspaces.keyOf(other)}"), friend.root)
|
||||
assertNotEquals(File(cache, "artwork"), friend.artworkDir)
|
||||
assertNotEquals("orbit-connection-key-v1", friend.keyAlias)
|
||||
@@ -112,12 +121,12 @@ class PortabilityTest {
|
||||
// Only the new folder's note and which server is in use were written; everything that was there is byte for byte the same.
|
||||
val after = digest(noBackup)
|
||||
assertEquals(before, after.filterKeys { it in before })
|
||||
assertEquals(setOf("servers/${Workspaces.keyOf(other)}/server", "active-server"), after.keys - before.keys)
|
||||
assertEquals(setOf("original-server", "servers/${Workspaces.keyOf(other)}/server", "active-server"), after.keys - before.keys)
|
||||
// Back to the original server: still the same data, and an older Orbit still finds all of it where it always was.
|
||||
assertTrue(Workspaces.openIn(noBackup, cache, EmbyServer.DEFAULT).original)
|
||||
assertTrue(Workspaces.openIn(noBackup, cache, paul).original)
|
||||
assertEquals(before, digest(noBackup).filterKeys { it in before })
|
||||
assertEquals(EmbyServer.DEFAULT, Workspaces.activeOrigin(noBackup))
|
||||
assertEquals(listOf(EmbyServer.DEFAULT), Workspaces.known(noBackup, cache)) // the new server holds nothing yet
|
||||
assertEquals(paul, Workspaces.activeOrigin(noBackup))
|
||||
assertEquals(listOf(paul), Workspaces.known(noBackup, cache)) // the new server holds nothing yet
|
||||
}
|
||||
|
||||
@Test fun aFolderNeverOpensForAnotherAddressAndAGarbledChoiceFallsBackToTheOriginal() {
|
||||
@@ -126,13 +135,16 @@ class PortabilityTest {
|
||||
File(root, "server").writeText("https://someone.else.example")
|
||||
assertThrows(IllegalStateException::class.java) { Workspaces.openIn(noBackup, cache, other) }
|
||||
File(noBackup, "active-server").writeText("http://not-https.example")
|
||||
assertEquals(EmbyServer.DEFAULT, Workspaces.activeOrigin(noBackup))
|
||||
assertNull(Workspaces.activeOrigin(noBackup)) // no note, and the sign-in can't be read
|
||||
Workspaces.openIn(noBackup, cache, paul)
|
||||
File(noBackup, "active-server").writeText("http://not-https.example")
|
||||
assertEquals(paul, Workspaces.activeOrigin(noBackup)) // the note
|
||||
assertThrows(IllegalArgumentException::class.java) { Workspaces.openIn(noBackup, cache, "http://plain.example") }
|
||||
}
|
||||
|
||||
@Test fun switchingServersForgetsWhatTheLastOneShowed() {
|
||||
val (noBackup, cache) = todaysBox()
|
||||
Workspaces.openIn(noBackup, cache, EmbyServer.DEFAULT)
|
||||
Workspaces.openIn(noBackup, cache, paul)
|
||||
CuratedDriveInEvents.refresh { PaulsEventCopies }
|
||||
ApprovedDriveInEvents.list = PaulsDriveInEvents.take(1)
|
||||
PromoBoard.shown[101] = 1L
|
||||
@@ -142,7 +154,7 @@ class PortabilityTest {
|
||||
|
||||
@Test fun paulsOwnDecisionsByItemApplyOnlyOnHisServer() {
|
||||
val (noBackup, cache) = todaysBox()
|
||||
Workspaces.openIn(noBackup, cache, EmbyServer.DEFAULT)
|
||||
Workspaces.openIn(noBackup, cache, paul)
|
||||
val afterDark = SmartChannels.single { it.number == AFTER_DARK_NUMBER }
|
||||
assertTrue(afterDark.withdrawn.isNotEmpty()); assertTrue(PremiereCalls.isNotEmpty())
|
||||
val advent = java.time.LocalDateTime.of(2026, 12, 1, 18, 30).atZone(java.time.ZoneId.of("Europe/London")).toInstant().toEpochMilli()
|
||||
@@ -154,6 +166,36 @@ class PortabilityTest {
|
||||
assertFalse(afterDark.signature.contains("#withdrawn"))
|
||||
}
|
||||
|
||||
@Test fun noServerIsBuiltInAndANewBoxsFirstServerBecomesItsOriginal() {
|
||||
Workspaces.reset()
|
||||
assertEquals("", EmbyServer.origin)
|
||||
val noBackup = folder.newFolder("fresh"); val cache = folder.newFolder("fresh-cache")
|
||||
assertNull(Workspaces.activeOrigin(noBackup)); assertTrue(Workspaces.known(noBackup, cache).isEmpty())
|
||||
val first = Workspaces.openIn(noBackup, cache, other)
|
||||
assertTrue(first.original); assertEquals(noBackup, first.root); assertFalse(Workspaces.paulsServerOpen)
|
||||
assertEquals(other, Workspaces.originalOrigin(noBackup)); assertEquals(other, Workspaces.activeOrigin(noBackup))
|
||||
// A second server gets its own folder, and Paul's server is just another one here.
|
||||
val second = Workspaces.openIn(noBackup, cache, paul)
|
||||
assertFalse(second.original); assertEquals(File(noBackup, "servers/${Workspaces.keyOf(paul)}"), second.root)
|
||||
}
|
||||
|
||||
@Test fun aBoxFromBeforeTheNoteGivesItsDataOnlyToPaulsServer() {
|
||||
val (noBackup, cache) = todaysBox()
|
||||
val before = digest(noBackup)
|
||||
// Its sign-in can't be read, so nothing is open; signing in somewhere else never takes Paul's data.
|
||||
assertNull(Workspaces.activeOrigin(noBackup))
|
||||
val friend = Workspaces.openIn(noBackup, cache, other)
|
||||
assertFalse(friend.original); assertNull(Workspaces.originalOrigin(noBackup))
|
||||
assertTrue(Workspaces.openIn(noBackup, cache, paul).original)
|
||||
assertEquals(paul, Workspaces.originalOrigin(noBackup))
|
||||
assertEquals(before, digest(noBackup).filterKeys { it in before })
|
||||
}
|
||||
|
||||
@Test fun theAppHoldsNoServerAddress() {
|
||||
val source = File("src/main").walkTopDown().filter { it.isFile && it.extension in setOf("kt", "xml", "html", "js", "json") }
|
||||
assertTrue(source.none { it.readText().contains("appboxmanager") })
|
||||
}
|
||||
|
||||
@Test fun aSessionStaysWithItsOwnServerAfterTheServerInUseChanges() {
|
||||
val requests = mutableListOf<String>()
|
||||
val transport = HttpsEmbyTransport("fixture-device", "https://emby.home.example")
|
||||
|
||||
@@ -7,6 +7,9 @@ import org.junit.Test
|
||||
import javax.crypto.KeyGenerator
|
||||
|
||||
class RememberedStateTest {
|
||||
// No server is built in: these sign-ins belong to a made-up one.
|
||||
@org.junit.Before fun server() { EmbyServer.origin = "https://emby.example.com" }
|
||||
@org.junit.After fun noServer() { EmbyServer.origin = "" }
|
||||
private fun state(): RememberedState {
|
||||
val series = SeriesCandidate("fixture-series", "Fixture series", 1996, "TV-PG")
|
||||
val episodes = SeriesEpisodes(series, List(2) { EpisodeCandidate("episode-$it", "Fixture $it", 1, it + 1, 60_000) }, false)
|
||||
|
||||
@@ -22,16 +22,21 @@ class WorkspaceSnapshotTest {
|
||||
val dir = System.getenv("ORBIT_SNAPSHOT_DIR")?.let(::File)
|
||||
assumeTrue(dir != null && dir.isDirectory)
|
||||
val noBackup = dir!!; val cache = File(noBackup.parentFile, "cache-for-test").apply { mkdirs() }
|
||||
// The install snapshot leaves the encrypted sign-in out; a stand-in marks where the box has one.
|
||||
File(noBackup, "orbit-connection.v1").let { if (!it.exists()) it.writeBytes(byteArrayOf(1)) }
|
||||
val before = digest(noBackup)
|
||||
val original = Workspaces.openIn(noBackup, cache, Workspaces.activeOrigin(noBackup))
|
||||
// Paul's server stands in under a made-up address; the box's own sign-in names the real one.
|
||||
val paul = "https://paul.example"; Workspaces.isPaulsServer = { it == paul }
|
||||
val original = Workspaces.openIn(noBackup, cache, Workspaces.activeOrigin(noBackup) { paul }!!)
|
||||
assertTrue(original.original); assertEquals(File(noBackup, "schedule"), original.scheduleDir)
|
||||
assertEquals(before, digest(noBackup))
|
||||
assertEquals(before, digest(noBackup).filterKeys { it in before })
|
||||
Workspaces.openIn(noBackup, cache, "https://emby.friend.example")
|
||||
Workspaces.openIn(noBackup, cache, EmbyServer.DEFAULT)
|
||||
Workspaces.openIn(noBackup, cache, paul)
|
||||
val after = digest(noBackup)
|
||||
assertEquals(before, after.filterKeys { it in before })
|
||||
println("snapshot files=${before.size} unchanged=${before.count { (k, v) -> after[k] == v }} added=${(after.keys - before.keys).sorted()}")
|
||||
val saved = File(noBackup, "schedule/episodes-300.json").readText().let { Regex("\"signature\":\"(events:[^\"]*)\"").find(it)!!.groupValues[1] }
|
||||
assertEquals(saved, eventSignature(PaulsDriveInEvents, PaulsEventCopies))
|
||||
// Paul's built-in events first; events he approved later follow them.
|
||||
assertTrue(saved, saved.startsWith(eventSignature(PaulsDriveInEvents, PaulsEventCopies)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,5 +28,6 @@ PY
|
||||
# The playback test hook is only ever in the playtest build (Paul, 9 November 2026): never in the release APK.
|
||||
if unzip -l app/build/outputs/apk/release/app-release.apk | grep -q playtest-approved || \
|
||||
unzip -p app/build/outputs/apk/release/app-release.apk 'classes*.dex' | grep -aq PlaytestFileActivity; then echo "Release APK contains the playback test hook."; exit 1; fi
|
||||
if unzip -p app/build/outputs/apk/release/app-release.apk 'classes*.dex' 'assets/*' | grep -aq appboxmanager; then echo "Release APK contains a built-in server address."; exit 1; fi
|
||||
sha256sum app/build/outputs/apk/release/app-release.apk | cut -c1-64
|
||||
echo "Release gate passed."
|
||||
|
||||
Reference in New Issue
Block a user