diff --git a/tools/chatgui-android/app/src/test/java/com/utun/chat/data/AvatarProtocolTest.kt b/tools/chatgui-android/app/src/test/java/com/utun/chat/data/AvatarProtocolTest.kt index ad1c537c..a2fec088 100644 --- a/tools/chatgui-android/app/src/test/java/com/utun/chat/data/AvatarProtocolTest.kt +++ b/tools/chatgui-android/app/src/test/java/com/utun/chat/data/AvatarProtocolTest.kt @@ -23,8 +23,9 @@ class AvatarProtocolTest { @Test fun unsignedNodeAndContentAddress() { assertEquals(uid, AvatarProtocol.node("fedcba9876543210")) assertEquals("fedcba9876543210", AvatarProtocol.hex(uid)) - assertTrue(AvatarProtocol.validFile("a".repeat(64) + ".png")) - listOf("A".repeat(64) + ".png", "../" + "a".repeat(64) + ".png", "a.png", "a".repeat(64) + ".jpg") + assertTrue(AvatarProtocol.validFile("a".repeat(64) + ".json")) + assertTrue(AvatarProtocol.validObject("a".repeat(64)+".webp")) + listOf("A".repeat(64) + ".json", "../" + "a".repeat(64) + ".json", "a.json", "a".repeat(64) + ".jpg") .forEach { assertFalse(it, AvatarProtocol.validFile(it)) } assertEquals(0L, AvatarProtocol.node("invalid")) } @@ -90,4 +91,21 @@ class AvatarProtocolTest { assertThrows(IllegalArgumentException::class.java) { AvatarProtocol.published(result.copyOf(16)) } assertThrows(IllegalArgumentException::class.java) { AvatarProtocol.published(result.also { it[16] = 2 }) } } + @Test fun catalogDecodesVersionCursorAndOnlyManifestEntries() { + val name="b".repeat(64)+".json" + val entry=buffer(35+name.length).apply { + putShort(name.length.toShort()); put(1); putLong(300); putLong(1234); put(ByteArray(16)); put(name.toByteArray()) + }.array() + val wire=buffer(141+7+entry.size).apply { + putLong(uid); putLong(23); put(4); put(2); put(1); putShort(0) + putLong(71); putLong(uid); putLong(0); putLong(0); putLong(8); put(ByteArray(16) { 7 }) + position(16+117); put(2); put(1); putShort(7); putShort(0); putShort(entry.size.toShort()) + put("avatars".toByteArray()); put(entry) + }.array() + val reply=AvatarProtocol.response(wire) + assertEquals(8L,reply.cursor); assertTrue(reply.more); assertEquals("avatars",reply.path) + assertArrayEquals(ByteArray(16) { 7 },reply.version) + assertEquals(listOf(AvatarProtocol.Entry(name,1234)),AvatarProtocol.entries(reply)) + assertThrows(IllegalArgumentException::class.java) { AvatarProtocol.entries(reply.copy(payload=entry.copyOf(34))) } + } } diff --git a/tools/chatgui-android/app/src/test/java/com/utun/chat/data/MemberAvatarTest.kt b/tools/chatgui-android/app/src/test/java/com/utun/chat/data/MemberAvatarTest.kt index 8bc9b46c..72cb36c1 100644 --- a/tools/chatgui-android/app/src/test/java/com/utun/chat/data/MemberAvatarTest.kt +++ b/tools/chatgui-android/app/src/test/java/com/utun/chat/data/MemberAvatarTest.kt @@ -7,14 +7,14 @@ import java.nio.ByteOrder class MemberAvatarTest { @Test fun sharedSnapshotKeepsAvatarAndSignedStorageRole() { - val bytes = ByteArray(157) + val bytes = ByteArray(158) val b = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN) b.putLong(0, 123); bytes[8] = 1; bytes[10] = 2 "Alice".toByteArray().copyInto(bytes, 15) val server = 0xfedcba9876543210uL.toLong() b.putLong(79, server) - val file = "b".repeat(64) + ".png" - file.toByteArray().copyInto(bytes, 87); bytes[156] = 1 + val file = "b".repeat(64) + ".json" + file.toByteArray().copyInto(bytes, 87); bytes[157] = 1 val previous = ChatMember(123, "Old", isVerified = true, nodeType = 3, directUp = true, bgpNodes = 7) val member = requireNotNull(parseMemberWire(bytes)).toChatMember(previous) assertEquals("Alice", member.name); assertTrue(member.online); assertTrue(member.isAdmin) @@ -24,16 +24,16 @@ class MemberAvatarTest { assertFalse(member.isStorage) } @Test fun clearingReferenceDoesNotKeepAnOldAvatar() { - val previous = ChatMember(123, "Alice", avatarServer = 456, avatarFile = "b".repeat(64) + ".png", storageRole = true) + val previous = ChatMember(123, "Alice", avatarServer = 456, avatarFile = "b".repeat(64) + ".json", storageRole = true) val updated = MemberWire(123, 1, true, 0, 0, 0, false, "Alice").toChatMember(previous) assertEquals(0L, updated.avatarServer); assertEquals("", updated.avatarFile); assertFalse(updated.storageRole) assertTrue(updated.isSelf) } - @Test fun recordsAtAnOffsetRequireAll157Bytes() { - val bytes = ByteArray(160) + @Test fun recordsAtAnOffsetRequireAll158Bytes() { + val bytes = ByteArray(161) ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).putLong(3, 987) assertEquals(987L, parseMemberWire(bytes, 3)?.nodeId) assertNull(parseMemberWire(bytes, 4)); assertNull(parseMemberWire(bytes, -1)) - assertNull(parseMemberWire(bytes.copyOf(156))) + assertNull(parseMemberWire(bytes.copyOf(157))) } }