Warn and block sending on verification violation (#3679)

* feat(crypto): Warn and block sending on verification violation

* fixup: Fix ComposerToolbar previews

* fixup! add ComposerToolBarViewModelTests for canSend

* add new preview tests for verification violations

* Use `deferFulfillment`s in the unit tests.

---------

Co-authored-by: Stefan Ceriu <stefanc@matrix.org>
This commit is contained in:
Valere
2025-01-20 17:29:34 +01:00
committed by GitHub
parent 0fd8df52ab
commit f20847f62b
21 changed files with 419 additions and 22 deletions
@@ -4682,6 +4682,76 @@ class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
return pinUserIdentityReturnValue
}
}
//MARK: - withdrawUserIdentityVerification
var withdrawUserIdentityVerificationUnderlyingCallsCount = 0
var withdrawUserIdentityVerificationCallsCount: Int {
get {
if Thread.isMainThread {
return withdrawUserIdentityVerificationUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = withdrawUserIdentityVerificationUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
withdrawUserIdentityVerificationUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
withdrawUserIdentityVerificationUnderlyingCallsCount = newValue
}
}
}
}
var withdrawUserIdentityVerificationCalled: Bool {
return withdrawUserIdentityVerificationCallsCount > 0
}
var withdrawUserIdentityVerificationReceivedUserID: String?
var withdrawUserIdentityVerificationReceivedInvocations: [String] = []
var withdrawUserIdentityVerificationUnderlyingReturnValue: Result<Void, ClientProxyError>!
var withdrawUserIdentityVerificationReturnValue: Result<Void, ClientProxyError>! {
get {
if Thread.isMainThread {
return withdrawUserIdentityVerificationUnderlyingReturnValue
} else {
var returnValue: Result<Void, ClientProxyError>? = nil
DispatchQueue.main.sync {
returnValue = withdrawUserIdentityVerificationUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
withdrawUserIdentityVerificationUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
withdrawUserIdentityVerificationUnderlyingReturnValue = newValue
}
}
}
}
var withdrawUserIdentityVerificationClosure: ((String) async -> Result<Void, ClientProxyError>)?
func withdrawUserIdentityVerification(_ userID: String) async -> Result<Void, ClientProxyError> {
withdrawUserIdentityVerificationCallsCount += 1
withdrawUserIdentityVerificationReceivedUserID = userID
DispatchQueue.main.async {
self.withdrawUserIdentityVerificationReceivedInvocations.append(userID)
}
if let withdrawUserIdentityVerificationClosure = withdrawUserIdentityVerificationClosure {
return await withdrawUserIdentityVerificationClosure(userID)
} else {
return withdrawUserIdentityVerificationReturnValue
}
}
//MARK: - resetIdentity
var resetIdentityUnderlyingCallsCount = 0