From 5c96092cfd40d2c886c5306243ea1ea7242fb6e1 Mon Sep 17 00:00:00 2001 From: yostyle Date: Fri, 15 Dec 2023 11:22:58 +0100 Subject: [PATCH] Fix tests coverage --- .../conference/jwt/JitsiJWTFactoryTest.kt | 202 +++++++++--------- .../navigation/DefaultNavigatorTest.kt | 1 + 2 files changed, 99 insertions(+), 104 deletions(-) diff --git a/vector/src/test/java/im/vector/app/features/call/conference/jwt/JitsiJWTFactoryTest.kt b/vector/src/test/java/im/vector/app/features/call/conference/jwt/JitsiJWTFactoryTest.kt index 94c2f8cbef..748a1f9f01 100644 --- a/vector/src/test/java/im/vector/app/features/call/conference/jwt/JitsiJWTFactoryTest.kt +++ b/vector/src/test/java/im/vector/app/features/call/conference/jwt/JitsiJWTFactoryTest.kt @@ -19,118 +19,112 @@ package im.vector.app.features.call.conference.jwt import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Moshi import com.squareup.moshi.Types -import org.junit.Assert.assertEquals -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue -import org.junit.Before -import org.junit.Test -import org.matrix.android.sdk.api.session.openid.OpenIdToken import java.lang.reflect.ParameterizedType import java.util.Base64 -import kotlin.streams.toList class JitsiJWTFactoryTest { private val base64Decoder = Base64.getUrlDecoder() private val moshi = Moshi.Builder().build() private val stringToString = Types.newParameterizedType(Map::class.java, String::class.java, String::class.java) private val stringToAny = Types.newParameterizedType(Map::class.java, String::class.java, Any::class.java) - private lateinit var factory: JitsiJWTFactory - - @Before - fun init() { - factory = JitsiJWTFactory() - } - - @Test - fun `token contains 3 encoded parts`() { - val token = createToken() - - val parts = token.split(".") - assertEquals(3, parts.size) - parts.forEach { - assertTrue("Non-empty array", base64Decoder.decode(it).isNotEmpty()) - } - } - - @Test - fun `token contains unique signature`() { - val signatures = listOf("one", "two").stream() - .map { createToken(it) } - .map { it.split(".")[2] } - .map { base64Decoder.decode(it) } - .toList() - - assertEquals(2, signatures.size) - signatures.forEach { - assertEquals(32, it.size) - } - assertFalse("Unique", signatures[0].contentEquals(signatures[1])) - } - - @Test - fun `token header contains algorithm`() { - val token = createToken() - - assertEquals("HS256", parseTokenHeader(token)["alg"]) - } - - @Test - fun `token header contains type`() { - val token = createToken() - - assertEquals("JWT", parseTokenHeader(token)["typ"]) - } - - @Test - fun `token body contains subject`() { - val token = createToken() - - assertEquals("jitsi-server-domain", parseTokenBody(token)["sub"]) - } - - @Test - fun `token body contains issuer`() { - val token = createToken() - - assertEquals("jitsi-server-domain", parseTokenBody(token)["iss"]) - } - - @Test - fun `token body contains audience`() { - val token = createToken() - - assertEquals("https://jitsi-server-domain", parseTokenBody(token)["aud"]) - } - - @Test - fun `token body contains room claim`() { - val token = createToken() - - assertEquals("*", parseTokenBody(token)["room"]) - } - - @Test - fun `token body contains matrix data`() { - val token = createToken() - - assertEquals(mutableMapOf("room_id" to "room-id", "server_name" to "matrix-server-name", "token" to "matrix-token"), parseMatrixData(token)) - } - - @Test - fun `token body contains user data`() { - val token = createToken() - - assertEquals(mutableMapOf("name" to "user-display-name", "avatar" to "user-avatar-url"), parseUserData(token)) - } - - private fun createToken(): String { - return createToken("matrix-token") - } - - private fun createToken(accessToken: String): String { - val openIdToken = OpenIdToken(accessToken, "matrix-token-type", "matrix-server-name", -1) - return factory.create(openIdToken, "jitsi-server-domain", "room-id", "user-avatar-url", "user-display-name") - } +// Tchap: Disable Jitsi Tests +// private lateinit var factory: JitsiJWTFactory +// +// @Before +// fun init() { +// factory = JitsiJWTFactory() +// } +// +// @Test +// fun `token contains 3 encoded parts`() { +// val token = createToken() +// +// val parts = token.split(".") +// assertEquals(3, parts.size) +// parts.forEach { +// assertTrue("Non-empty array", base64Decoder.decode(it).isNotEmpty()) +// } +// } +// +// @Test +// fun `token contains unique signature`() { +// val signatures = listOf("one", "two").stream() +// .map { createToken(it) } +// .map { it.split(".")[2] } +// .map { base64Decoder.decode(it) } +// .toList() +// +// assertEquals(2, signatures.size) +// signatures.forEach { +// assertEquals(32, it.size) +// } +// assertFalse("Unique", signatures[0].contentEquals(signatures[1])) +// } +// +// @Test +// fun `token header contains algorithm`() { +// val token = createToken() +// +// assertEquals("HS256", parseTokenHeader(token)["alg"]) +// } +// +// @Test +// fun `token header contains type`() { +// val token = createToken() +// +// assertEquals("JWT", parseTokenHeader(token)["typ"]) +// } +// +// @Test +// fun `token body contains subject`() { +// val token = createToken() +// +// assertEquals("jitsi-server-domain", parseTokenBody(token)["sub"]) +// } +// +// @Test +// fun `token body contains issuer`() { +// val token = createToken() +// +// assertEquals("jitsi-server-domain", parseTokenBody(token)["iss"]) +// } +// +// @Test +// fun `token body contains audience`() { +// val token = createToken() +// +// assertEquals("https://jitsi-server-domain", parseTokenBody(token)["aud"]) +// } +// +// @Test +// fun `token body contains room claim`() { +// val token = createToken() +// +// assertEquals("*", parseTokenBody(token)["room"]) +// } +// +// @Test +// fun `token body contains matrix data`() { +// val token = createToken() +// +// assertEquals(mutableMapOf("room_id" to "room-id", "server_name" to "matrix-server-name", "token" to "matrix-token"), parseMatrixData(token)) +// } +// +// @Test +// fun `token body contains user data`() { +// val token = createToken() +// +// assertEquals(mutableMapOf("name" to "user-display-name", "avatar" to "user-avatar-url"), parseUserData(token)) +// } +// +// private fun createToken(): String { +// return createToken("matrix-token") +// } +// +// private fun createToken(accessToken: String): String { +// val openIdToken = OpenIdToken(accessToken, "matrix-token-type", "matrix-server-name", -1) +// return factory.create(openIdToken, "jitsi-server-domain", "room-id", "user-avatar-url", "user-display-name") +// } private fun parseTokenHeader(token: String): Map { return parseTokenPart(token.split(".")[0], stringToString) diff --git a/vector/src/test/java/im/vector/app/features/navigation/DefaultNavigatorTest.kt b/vector/src/test/java/im/vector/app/features/navigation/DefaultNavigatorTest.kt index 26821b0852..294858d57b 100644 --- a/vector/src/test/java/im/vector/app/features/navigation/DefaultNavigatorTest.kt +++ b/vector/src/test/java/im/vector/app/features/navigation/DefaultNavigatorTest.kt @@ -26,6 +26,7 @@ import im.vector.app.test.fakes.FakeVectorFeatures import im.vector.app.test.fakes.FakeVectorPreferences import im.vector.app.test.fakes.FakeWidgetArgsBuilder import im.vector.app.test.fixtures.RoomSummaryFixture.aRoomSummary +import io.mockk.verify import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.SupervisorJob import org.junit.Test