Skip to content

Commit

Permalink
Merge branch 'develop' into Read-receipts-not-generated-when-respondi…
Browse files Browse the repository at this point in the history
…ng-from-notification
  • Loading branch information
ohassine authored Sep 5, 2024
2 parents 9165d25 + 933e17c commit 34ee937
Show file tree
Hide file tree
Showing 13 changed files with 5,862 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/semantic-commit-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
# Please look up the latest version from
# https://github.com/amannn/action-semantic-pull-request/releases
- name: Run Semantic Commint Linter
uses: amannn/[email protected].2
uses: amannn/[email protected].3
with:
# Configure which types are allowed.
# Default: https://github.com/commitizen/conventional-commit-types
Expand Down
75 changes: 75 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,81 @@ moduleGraphConfig {
heading.set("#### Dependency Graph")
}

tasks.register("runAllUnitTests") {
description = "Runs all Unit Tests."

rootProject.subprojects {
if (tasks.findByName("testDebugUnitTest") != null) {
println("Adding $name to runUnitTests")
dependsOn(":$name:testDebugUnitTest")
}
if (name != "cryptography") {
if (tasks.findByName("jvmTest") != null) {
println("Adding $name to jvmTest")
dependsOn(":$name:jvmTest")
}
}
}
}

tasks.register("aggregateTestResults") {
description = "Aggregates all Unit Test results into a single report."

doLast {
val testResultsDir = rootProject.layout.buildDirectory.dir("testResults").get().asFile
testResultsDir.deleteRecursively()
testResultsDir.mkdirs()

val indexHtmlFile = File(testResultsDir, "index.html")
indexHtmlFile.writeText(
"""
<html>
<head>
<title>Aggregated Test Reports</title>
</head>
<body>
<h1>Aggregated Test Reports</h1>
<ul>
""".trimIndent()
)

rootProject.subprojects {
val testResultsParentDir = layout.buildDirectory.dir("reports/tests").get().asFile

if (testResultsParentDir.exists()) {
testResultsParentDir.listFiles()?.forEach { testDir ->
if (testDir.isDirectory) {
val subprojectDir = File(testResultsDir, "$name/${testDir.name}")
subprojectDir.mkdirs()

testDir.copyRecursively(subprojectDir, overwrite = true)

indexHtmlFile.appendText(
"""
<li><a href="./$name/${testDir.name}/index.html">$name - ${testDir.name} Report</a></li>
""".trimIndent()
)
}
}
}
}

indexHtmlFile.appendText(
"""
</ul>
</body>
</html>
""".trimIndent()
)

// Print the location of the aggregated test results directory
// relative to the current terminal working dir
val currentWorkingDir = File(System.getProperty("user.dir"))
val relativePath = testResultsDir.relativeTo(currentWorkingDir).path
println("Aggregated test reports are available at: $relativePath")
}
}

tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ class ProteusClientCoreCryptoImpl private constructor(private val coreCrypto: Co

override suspend fun encryptBatched(message: ByteArray, sessionIds: List<CryptoSessionId>): Map<CryptoSessionId, ByteArray> {
return wrapException {
coreCrypto.proteusEncryptBatched(sessionIds.map { it.value }, toUByteList((message))).mapNotNull { entry ->
coreCrypto.proteusEncryptBatched(
sessionId = sessionIds.map { it.value },
plaintext = toUByteList((message))
).mapNotNull { entry ->
CryptoSessionId.fromEncodedString(entry.key)?.let { sessionId ->
sessionId to toByteArray(entry.value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ import com.wire.crypto.client.toByteArray
import com.wire.kalium.cryptography.exceptions.ProteusException
import io.ktor.util.decodeBase64Bytes
import io.ktor.util.encodeBase64
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import java.io.File

@Suppress("TooManyFunctions")
class ProteusClientCoreCryptoImpl private constructor(
private val coreCrypto: CoreCrypto,
) : ProteusClient {

private val mutex = Mutex()
private val existingSessionsCache = mutableSetOf<CryptoSessionId>()

override suspend fun close() {
coreCrypto.close()
}
Expand All @@ -46,6 +51,7 @@ class ProteusClientCoreCryptoImpl private constructor(
override suspend fun remoteFingerPrint(sessionId: CryptoSessionId): ByteArray = wrapException {
coreCrypto.proteusFingerprintRemote(sessionId.value).toByteArray()
}

override suspend fun getFingerprintFromPreKey(preKey: PreKeyCrypto): ByteArray = wrapException {
coreCrypto.proteusFingerprintPrekeybundle(preKey.encodedData.decodeBase64Bytes()).toByteArray()
}
Expand All @@ -62,9 +68,16 @@ class ProteusClientCoreCryptoImpl private constructor(
return wrapException { toPreKey(coreCrypto.proteusLastResortPrekeyId().toInt(), coreCrypto.proteusLastResortPrekey()) }
}

override suspend fun doesSessionExist(sessionId: CryptoSessionId): Boolean {
return wrapException {
override suspend fun doesSessionExist(sessionId: CryptoSessionId): Boolean = mutex.withLock {
if (existingSessionsCache.contains(sessionId)) {
return@withLock true
}
wrapException {
coreCrypto.proteusSessionExists(sessionId.value)
}.also { exists ->
if (exists) {
existingSessionsCache.add(sessionId)
}
}
}

Expand All @@ -77,13 +90,9 @@ class ProteusClientCoreCryptoImpl private constructor(

return wrapException {
if (sessionExists) {
val decryptedMessage = coreCrypto.proteusDecrypt(sessionId.value, message)
coreCrypto.proteusSessionSave(sessionId.value)
decryptedMessage
coreCrypto.proteusDecrypt(sessionId.value, message)
} else {
val decryptedMessage = coreCrypto.proteusSessionFromMessage(sessionId.value, message)
coreCrypto.proteusSessionSave(sessionId.value)
decryptedMessage
coreCrypto.proteusSessionFromMessage(sessionId.value, message)
}
}
}
Expand Down Expand Up @@ -119,7 +128,8 @@ class ProteusClientCoreCryptoImpl private constructor(
}
}

override suspend fun deleteSession(sessionId: CryptoSessionId) {
override suspend fun deleteSession(sessionId: CryptoSessionId) = mutex.withLock {
existingSessionsCache.remove(sessionId)
wrapException {
coreCrypto.proteusSessionDelete(sessionId.value)
}
Expand Down
3 changes: 3 additions & 0 deletions docs/notebooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A place to store [Jupyter Notebook](https://jupyter.org/) files of ongoing studies.

You can use Kotlin and run it directly in the IDE, thanks to [Kotlin Notebook](https://kotlinlang.org/docs/kotlin-notebook-overview.html).
Loading

0 comments on commit 34ee937

Please sign in to comment.