Incoming session verification support (#3428)

* Fixes #1227 - Add support for receiving and interacting with incoming session verification requests.
* Fix a couple of random small warnings
* Move static view config to the view state
* Update snapshots
This commit is contained in:
Stefan Ceriu
2024-10-29 15:21:17 +02:00
committed by GitHub
parent cf5e9fb313
commit d77bb935b7
104 changed files with 995 additions and 483 deletions
@@ -60,7 +60,6 @@ extension ClientProxyMock {
logoutReturnValue = nil
searchUsersSearchTermLimitReturnValue = .success(.init(results: [], limited: false))
profileForReturnValue = .success(.init(userID: "@a:b.com", displayName: "Some user"))
sessionVerificationControllerProxyReturnValue = .failure(.sdkError(ClientProxyMockError.generic))
ignoreUserReturnValue = .success(())
unignoreUserReturnValue = .success(())
@@ -2210,6 +2210,7 @@ class ClientProxyMock: ClientProxyProtocol {
set(value) { underlyingSecureBackupController = value }
}
var underlyingSecureBackupController: SecureBackupControllerProtocol!
var sessionVerificationController: SessionVerificationControllerProxyProtocol?
//MARK: - isOnlyDeviceLeft
@@ -3519,70 +3520,6 @@ class ClientProxyMock: ClientProxyProtocol {
return removeUserAvatarReturnValue
}
}
//MARK: - sessionVerificationControllerProxy
var sessionVerificationControllerProxyUnderlyingCallsCount = 0
var sessionVerificationControllerProxyCallsCount: Int {
get {
if Thread.isMainThread {
return sessionVerificationControllerProxyUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = sessionVerificationControllerProxyUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
sessionVerificationControllerProxyUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
sessionVerificationControllerProxyUnderlyingCallsCount = newValue
}
}
}
}
var sessionVerificationControllerProxyCalled: Bool {
return sessionVerificationControllerProxyCallsCount > 0
}
var sessionVerificationControllerProxyUnderlyingReturnValue: Result<SessionVerificationControllerProxyProtocol, ClientProxyError>!
var sessionVerificationControllerProxyReturnValue: Result<SessionVerificationControllerProxyProtocol, ClientProxyError>! {
get {
if Thread.isMainThread {
return sessionVerificationControllerProxyUnderlyingReturnValue
} else {
var returnValue: Result<SessionVerificationControllerProxyProtocol, ClientProxyError>? = nil
DispatchQueue.main.sync {
returnValue = sessionVerificationControllerProxyUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
sessionVerificationControllerProxyUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
sessionVerificationControllerProxyUnderlyingReturnValue = newValue
}
}
}
}
var sessionVerificationControllerProxyClosure: (() async -> Result<SessionVerificationControllerProxyProtocol, ClientProxyError>)?
func sessionVerificationControllerProxy() async -> Result<SessionVerificationControllerProxyProtocol, ClientProxyError> {
sessionVerificationControllerProxyCallsCount += 1
if let sessionVerificationControllerProxyClosure = sessionVerificationControllerProxyClosure {
return await sessionVerificationControllerProxyClosure()
} else {
return sessionVerificationControllerProxyReturnValue
}
}
//MARK: - deactivateAccount
var deactivateAccountPasswordEraseDataUnderlyingCallsCount = 0
@@ -13435,12 +13372,146 @@ class SecureBackupControllerMock: SecureBackupControllerProtocol {
}
}
class SessionVerificationControllerProxyMock: SessionVerificationControllerProxyProtocol {
var callbacks: PassthroughSubject<SessionVerificationControllerProxyCallback, Never> {
get { return underlyingCallbacks }
set(value) { underlyingCallbacks = value }
var actions: PassthroughSubject<SessionVerificationControllerProxyAction, Never> {
get { return underlyingActions }
set(value) { underlyingActions = value }
}
var underlyingCallbacks: PassthroughSubject<SessionVerificationControllerProxyCallback, Never>!
var underlyingActions: PassthroughSubject<SessionVerificationControllerProxyAction, Never>!
//MARK: - acknowledgeVerificationRequest
var acknowledgeVerificationRequestDetailsUnderlyingCallsCount = 0
var acknowledgeVerificationRequestDetailsCallsCount: Int {
get {
if Thread.isMainThread {
return acknowledgeVerificationRequestDetailsUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = acknowledgeVerificationRequestDetailsUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
acknowledgeVerificationRequestDetailsUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
acknowledgeVerificationRequestDetailsUnderlyingCallsCount = newValue
}
}
}
}
var acknowledgeVerificationRequestDetailsCalled: Bool {
return acknowledgeVerificationRequestDetailsCallsCount > 0
}
var acknowledgeVerificationRequestDetailsReceivedDetails: SessionVerificationRequestDetails?
var acknowledgeVerificationRequestDetailsReceivedInvocations: [SessionVerificationRequestDetails] = []
var acknowledgeVerificationRequestDetailsUnderlyingReturnValue: Result<Void, SessionVerificationControllerProxyError>!
var acknowledgeVerificationRequestDetailsReturnValue: Result<Void, SessionVerificationControllerProxyError>! {
get {
if Thread.isMainThread {
return acknowledgeVerificationRequestDetailsUnderlyingReturnValue
} else {
var returnValue: Result<Void, SessionVerificationControllerProxyError>? = nil
DispatchQueue.main.sync {
returnValue = acknowledgeVerificationRequestDetailsUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
acknowledgeVerificationRequestDetailsUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
acknowledgeVerificationRequestDetailsUnderlyingReturnValue = newValue
}
}
}
}
var acknowledgeVerificationRequestDetailsClosure: ((SessionVerificationRequestDetails) async -> Result<Void, SessionVerificationControllerProxyError>)?
func acknowledgeVerificationRequest(details: SessionVerificationRequestDetails) async -> Result<Void, SessionVerificationControllerProxyError> {
acknowledgeVerificationRequestDetailsCallsCount += 1
acknowledgeVerificationRequestDetailsReceivedDetails = details
DispatchQueue.main.async {
self.acknowledgeVerificationRequestDetailsReceivedInvocations.append(details)
}
if let acknowledgeVerificationRequestDetailsClosure = acknowledgeVerificationRequestDetailsClosure {
return await acknowledgeVerificationRequestDetailsClosure(details)
} else {
return acknowledgeVerificationRequestDetailsReturnValue
}
}
//MARK: - acceptVerificationRequest
var acceptVerificationRequestUnderlyingCallsCount = 0
var acceptVerificationRequestCallsCount: Int {
get {
if Thread.isMainThread {
return acceptVerificationRequestUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = acceptVerificationRequestUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
acceptVerificationRequestUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
acceptVerificationRequestUnderlyingCallsCount = newValue
}
}
}
}
var acceptVerificationRequestCalled: Bool {
return acceptVerificationRequestCallsCount > 0
}
var acceptVerificationRequestUnderlyingReturnValue: Result<Void, SessionVerificationControllerProxyError>!
var acceptVerificationRequestReturnValue: Result<Void, SessionVerificationControllerProxyError>! {
get {
if Thread.isMainThread {
return acceptVerificationRequestUnderlyingReturnValue
} else {
var returnValue: Result<Void, SessionVerificationControllerProxyError>? = nil
DispatchQueue.main.sync {
returnValue = acceptVerificationRequestUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
acceptVerificationRequestUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
acceptVerificationRequestUnderlyingReturnValue = newValue
}
}
}
}
var acceptVerificationRequestClosure: (() async -> Result<Void, SessionVerificationControllerProxyError>)?
func acceptVerificationRequest() async -> Result<Void, SessionVerificationControllerProxyError> {
acceptVerificationRequestCallsCount += 1
if let acceptVerificationRequestClosure = acceptVerificationRequestClosure {
return await acceptVerificationRequestClosure()
} else {
return acceptVerificationRequestReturnValue
}
}
//MARK: - requestVerification
var requestVerificationUnderlyingCallsCount = 0
@@ -16529,6 +16529,92 @@ open class SessionVerificationControllerSDKMock: MatrixRustSDK.SessionVerificati
fileprivate var pointer: UnsafeMutableRawPointer!
//MARK: - acceptVerificationRequest
open var acceptVerificationRequestThrowableError: Error?
var acceptVerificationRequestUnderlyingCallsCount = 0
open var acceptVerificationRequestCallsCount: Int {
get {
if Thread.isMainThread {
return acceptVerificationRequestUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = acceptVerificationRequestUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
acceptVerificationRequestUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
acceptVerificationRequestUnderlyingCallsCount = newValue
}
}
}
}
open var acceptVerificationRequestCalled: Bool {
return acceptVerificationRequestCallsCount > 0
}
open var acceptVerificationRequestClosure: (() async throws -> Void)?
open override func acceptVerificationRequest() async throws {
if let error = acceptVerificationRequestThrowableError {
throw error
}
acceptVerificationRequestCallsCount += 1
try await acceptVerificationRequestClosure?()
}
//MARK: - acknowledgeVerificationRequest
open var acknowledgeVerificationRequestSenderIdFlowIdThrowableError: Error?
var acknowledgeVerificationRequestSenderIdFlowIdUnderlyingCallsCount = 0
open var acknowledgeVerificationRequestSenderIdFlowIdCallsCount: Int {
get {
if Thread.isMainThread {
return acknowledgeVerificationRequestSenderIdFlowIdUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = acknowledgeVerificationRequestSenderIdFlowIdUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
acknowledgeVerificationRequestSenderIdFlowIdUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
acknowledgeVerificationRequestSenderIdFlowIdUnderlyingCallsCount = newValue
}
}
}
}
open var acknowledgeVerificationRequestSenderIdFlowIdCalled: Bool {
return acknowledgeVerificationRequestSenderIdFlowIdCallsCount > 0
}
open var acknowledgeVerificationRequestSenderIdFlowIdReceivedArguments: (senderId: String, flowId: String)?
open var acknowledgeVerificationRequestSenderIdFlowIdReceivedInvocations: [(senderId: String, flowId: String)] = []
open var acknowledgeVerificationRequestSenderIdFlowIdClosure: ((String, String) async throws -> Void)?
open override func acknowledgeVerificationRequest(senderId: String, flowId: String) async throws {
if let error = acknowledgeVerificationRequestSenderIdFlowIdThrowableError {
throw error
}
acknowledgeVerificationRequestSenderIdFlowIdCallsCount += 1
acknowledgeVerificationRequestSenderIdFlowIdReceivedArguments = (senderId: senderId, flowId: flowId)
DispatchQueue.main.async {
self.acknowledgeVerificationRequestSenderIdFlowIdReceivedInvocations.append((senderId: senderId, flowId: flowId))
}
try await acknowledgeVerificationRequestSenderIdFlowIdClosure?(senderId, flowId)
}
//MARK: - approveVerification
open var approveVerificationThrowableError: Error?
@@ -16649,75 +16735,6 @@ open class SessionVerificationControllerSDKMock: MatrixRustSDK.SessionVerificati
try await declineVerificationClosure?()
}
//MARK: - isVerified
open var isVerifiedThrowableError: Error?
var isVerifiedUnderlyingCallsCount = 0
open var isVerifiedCallsCount: Int {
get {
if Thread.isMainThread {
return isVerifiedUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = isVerifiedUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
isVerifiedUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
isVerifiedUnderlyingCallsCount = newValue
}
}
}
}
open var isVerifiedCalled: Bool {
return isVerifiedCallsCount > 0
}
var isVerifiedUnderlyingReturnValue: Bool!
open var isVerifiedReturnValue: Bool! {
get {
if Thread.isMainThread {
return isVerifiedUnderlyingReturnValue
} else {
var returnValue: Bool? = nil
DispatchQueue.main.sync {
returnValue = isVerifiedUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
isVerifiedUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
isVerifiedUnderlyingReturnValue = newValue
}
}
}
}
open var isVerifiedClosure: (() async throws -> Bool)?
open override func isVerified() async throws -> Bool {
if let error = isVerifiedThrowableError {
throw error
}
isVerifiedCallsCount += 1
if let isVerifiedClosure = isVerifiedClosure {
return try await isVerifiedClosure()
} else {
return isVerifiedReturnValue
}
}
//MARK: - requestVerification
open var requestVerificationThrowableError: Error?
@@ -16,16 +16,18 @@ extension SessionVerificationControllerProxyMock {
SessionVerificationEmoji(symbol: "🏁", description: "Flag"),
SessionVerificationEmoji(symbol: "🌏", description: "Globe")]
static func configureMock(callbacks: PassthroughSubject<SessionVerificationControllerProxyCallback, Never> = .init(),
static func configureMock(actions: PassthroughSubject<SessionVerificationControllerProxyAction, Never> = .init(),
isVerified: Bool = false,
requestDelay: Duration = .seconds(1)) -> SessionVerificationControllerProxyMock {
let mock = SessionVerificationControllerProxyMock()
mock.underlyingCallbacks = callbacks
mock.underlyingActions = actions
mock.acknowledgeVerificationRequestDetailsReturnValue = .success(())
mock.requestVerificationClosure = { [unowned mock] in
Task.detached {
try await Task.sleep(for: requestDelay)
mock.callbacks.send(.acceptedVerificationRequest)
mock.actions.send(.acceptedVerificationRequest)
}
return .success(())
@@ -34,11 +36,11 @@ extension SessionVerificationControllerProxyMock {
mock.startSasVerificationClosure = { [unowned mock] in
Task.detached {
try await Task.sleep(for: requestDelay)
mock.callbacks.send(.startedSasVerification)
mock.actions.send(.startedSasVerification)
Task.detached {
try await Task.sleep(for: requestDelay)
mock.callbacks.send(.receivedVerificationData(emojis))
mock.actions.send(.receivedVerificationData(emojis))
}
}
@@ -48,7 +50,7 @@ extension SessionVerificationControllerProxyMock {
mock.approveVerificationClosure = { [unowned mock] in
Task.detached {
try await Task.sleep(for: requestDelay)
mock.callbacks.send(.finished)
mock.actions.send(.finished)
}
return .success(())
@@ -57,7 +59,7 @@ extension SessionVerificationControllerProxyMock {
mock.declineVerificationClosure = { [unowned mock] in
Task.detached {
try await Task.sleep(for: requestDelay)
mock.callbacks.send(.cancelled)
mock.actions.send(.cancelled)
}
return .success(())
@@ -66,7 +68,7 @@ extension SessionVerificationControllerProxyMock {
mock.cancelVerificationClosure = { [unowned mock] in
Task.detached {
try await Task.sleep(for: requestDelay)
mock.callbacks.send(.cancelled)
mock.actions.send(.cancelled)
}
return .success(())