mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.1 KiB
Swift
61 lines
2.1 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import Foundation
|
|
import PromiseKit
|
|
import SessionSnodeKit
|
|
|
|
@testable import SessionMessagingKit
|
|
|
|
// FIXME: Change 'OnionRequestAPIType' to have instance methods instead of static methods once everything is updated to use 'Dependencies'
|
|
class TestOnionRequestAPI: OnionRequestAPIType {
|
|
struct RequestData: Codable {
|
|
let urlString: String?
|
|
let httpMethod: String
|
|
let headers: [String: String]
|
|
let snodeMethod: String?
|
|
let body: Data?
|
|
|
|
let server: String
|
|
let version: OnionRequestAPI.Version
|
|
let publicKey: String?
|
|
}
|
|
class ResponseInfo: OnionRequestResponseInfoType {
|
|
let requestData: RequestData
|
|
let code: Int
|
|
let headers: [String: String]
|
|
|
|
init(requestData: RequestData, code: Int, headers: [String: String]) {
|
|
self.requestData = requestData
|
|
self.code = code
|
|
self.headers = headers
|
|
}
|
|
}
|
|
|
|
class var mockResponse: Data? { return nil }
|
|
|
|
static func sendOnionRequest(_ request: URLRequest, to server: String, using version: OnionRequestAPI.Version, with x25519PublicKey: String) -> Promise<(OnionRequestResponseInfoType, Data?)> {
|
|
let responseInfo: ResponseInfo = ResponseInfo(
|
|
requestData: RequestData(
|
|
urlString: request.url?.absoluteString,
|
|
httpMethod: (request.httpMethod ?? "GET"),
|
|
headers: (request.allHTTPHeaderFields ?? [:]),
|
|
snodeMethod: nil,
|
|
body: request.httpBody,
|
|
|
|
server: server,
|
|
version: version,
|
|
publicKey: x25519PublicKey
|
|
),
|
|
code: 200,
|
|
headers: [:]
|
|
)
|
|
|
|
return Promise.value((responseInfo, mockResponse))
|
|
}
|
|
|
|
static func sendOnionRequest(to snode: Snode, invoking method: Snode.Method, with parameters: JSON, using version: OnionRequestAPI.Version, associatedWith publicKey: String?) -> Promise<Data> {
|
|
// TODO: Test the 'responseInfo' somehow?
|
|
return Promise.value(mockResponse!)
|
|
}
|
|
}
|