///| test "parse_display: local displays only" { assert_eq(@x11.parse_display(":0"), Some((0, 0))) assert_eq(@x11.parse_display(":1.2"), Some((1, 2))) assert_eq(@x11.parse_display("unix:10"), Some((10, 0))) assert_eq(@x11.parse_display("localhost:10.0"), None) assert_eq(@x11.parse_display(""), None) assert_eq(@x11.parse_display(":"), None) } ///| One Xauthority entry: family, address, display number, auth name, data (big-endian lengths). fn xauth_entry(family : Int, addr : String, num : String, data : Array[Byte]) -> Array[Byte] { let out : Array[Byte] = [] fn field(b : Array[Byte]) -> Unit { out.push(((b.length() >> 8) & 0xFF).to_byte()) out.push((b.length() & 0xFF).to_byte()) for c in b { out.push(c) } } fn text(s : String) -> Array[Byte] { let b : Array[Byte] = [] for c in s { b.push(c.to_int().to_byte()) } b } out.push(((family >> 8) & 0xFF).to_byte()) out.push((family & 0xFF).to_byte()) field(text(addr)) field(text(num)) field(text("MIT-MAGIC-COOKIE-1")) field(data) out } ///| test "xauth_cookie: picks this host's entry for the display" { let file : Array[Byte] = [] file.append(xauth_entry(256, "otherhost", "0", [b'\x01'])) file.append(xauth_entry(256, "rig", "1", [b'\x02'])) file.append(xauth_entry(256, "rig", "0", [b'\x03', b'\x04'])) let f = Bytes::from_array(file) assert_eq(@x11.xauth_cookie(f, 0, "rig").to_array(), [b'\x03', b'\x04']) assert_eq(@x11.xauth_cookie(f, 1, "rig").to_array(), [b'\x02']) // No entry for this host: any local one for the display. assert_eq(@x11.xauth_cookie(f, 0, "elsewhere").to_array(), [b'\x01']) assert_eq(@x11.xauth_cookie(f, 7, "rig").length(), 0) // FamilyWild (xauth's "ffff" entries, as Docker setups write) matches any host. let wild = Bytes::from_array(xauth_entry(0xFFFF, "", "0", [b'\x09'])) assert_eq(@x11.xauth_cookie(wild, 0, "rig").to_array(), [b'\x09']) }