Files
flamenet-messenger-android/engine/src/test/kotlin/io/flamenet/e2e/BridgeOfferTest.kt
T
Paul HittandClaude Fable 5.1 2fa430f21c API-style comments and ktlint formatting
Every comment is reduced to its first sentence plus @param, @return
and @throws tags. Comment lines: 20040 to 8526. ktlint 1.8 applied
with its default (official Kotlin) style across all modules; 262 files
reformatted. The 264 remaining ktlint findings are naming and filename
rules, which are code changes, and are left alone.

Comments and formatting only. 1208 tests pass, counted from the XML.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-08 20:02:07 -04:00

87 lines
2.8 KiB
Kotlin

package io.flamenet.e2e
import org.json.JSONObject
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNull
import kotlin.test.assertTrue
/**
* Handing a contact the bridge you use (§6.19).
*/
class BridgeOfferTest {
private val line =
"obfs4 198.51.100.7:4444 0123456789ABCDEF0123456789ABCDEF01234567 " +
"cert=" +
java.util.Base64
.getEncoder()
.encodeToString(ByteArray(52) { 0xAB.toByte() })
.trimEnd('=') +
" iat-mode=0"
@Test
fun `an offer round trips through the envelope`() {
val parsed = Content.parse(Content.bridgeOffer(line))
assertEquals(Content.Kind.BRIDGE, parsed.kind)
assertEquals(line, Content.bridgeLine(parsed))
}
/**
* `1`, not `true`. iOS decodes `ctl` as a number, and a boolean does not
* merely fail to set the flag, it fails the whole envelope's decode and
* falls through to the plain-text path, which is how an Android user once
* sent an iPhone a bubble of raw JSON.
*/
@Test
fun `the control flag is the number one on the wire`() {
val json = JSONObject(Content.bridgeOffer(line))
assertEquals(1, json.getInt("ctl"))
assertEquals(Content.Kind.BRIDGE, json.getString("kind"))
}
/**
* What an older build does with this.
*/
@Test
fun `an offer is control traffic and never renders`() {
val parsed = Content.parse(Content.bridgeOffer(line))
assertTrue(parsed.isControl, "an offer must never become a bubble")
assertFalse(parsed.isRenderable)
assertTrue(Content.Kind.BRIDGE in Content.Kind.CONTROL)
}
/**
* The line crosses whole.
*/
@Test
fun `the line is carried verbatim`() {
val awkward = "obfs4 [2001:db8::1]:9001 ABC cert=zz+/9 iat-mode=1 sni=x.example"
assertEquals(awkward, Content.bridgeLine(Content.parse(Content.bridgeOffer(awkward))))
}
/** Asked of the wrong kind, it says nothing rather than guessing. */
@Test
fun `another kind carries no bridge line`() {
assertNull(Content.bridgeLine(Content.parse(Content.disappearing(60))))
assertNull(Content.bridgeLine(Content.parse("just a message")))
}
/**
* An empty or whitespace line is not an offer.
*/
@Test
fun `an empty line is not an offer`() {
assertNull(Content.bridgeLine(Content.parse(Content.bridgeOffer(" "))))
}
/**
* The engine validates nothing, deliberately.
*/
@Test
fun `a malformed line still arrives, to be judged where it can be explained`() {
val junk = "obfs4 this-is-not-a-bridge-line"
assertEquals(junk, Content.bridgeLine(Content.parse(Content.bridgeOffer(junk))))
}
}