forked from daltoniam/Starscream
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MockTransport.swift
65 lines (51 loc) · 1.57 KB
/
MockTransport.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// MockTransport.swift
// Starscream
//
// Created by Dalton Cherry on 1/28/19.
// Copyright © 2019 Vluxe. All rights reserved.
//
import Foundation
@testable import Starscream
public class MockTransport: Transport {
public var usingTLS: Bool {
return false
}
private weak var delegate: TransportEventClient?
private let id: String
weak var server: MockServer?
var uuid: String {
return id
}
public init(server: MockServer) {
self.server = server
self.id = UUID().uuidString
}
public func register(delegate: TransportEventClient) {
self.delegate = delegate
}
public func connect(url: URL, timeout: Double, certificatePinning: CertificatePinning?) {
server?.connect(transport: self)
delegate?.connectionChanged(state: .connected)
}
public func disconnect() {
server?.disconnect(uuid: uuid)
}
public func write(data: Data, completion: @escaping ((Error?) -> ())) {
server?.write(data: data, uuid: uuid)
}
public func received(data: Data) {
delegate?.connectionChanged(state: .receive(data))
}
public func getSecurityData() -> (SecTrust?, String?) {
return (nil, nil)
}
}
public class MockSecurity: CertificatePinning, HeaderValidator {
public func evaluateTrust(trust: SecTrust, domain: String?, completion: ((PinningState) -> ())) {
completion(.success)
}
public func validate(headers: [String: String], key: String) -> Error? {
return nil
}
}