This repository was archived by the owner on Sep 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathRevocationListUpdateTests.swift
88 lines (79 loc) · 3.57 KB
/
RevocationListUpdateTests.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/
@testable import CovidCertificateSDK
import XCTest
final class RevocationListUpdateTests: XCTestCase {
override func setUp() {
if !CovidCertificateSDK.isInitialized {
CovidCertificateSDK.initialize(environment: .dev, apiKey: "")
}
}
/* func testUpdate() {
let storage = TrustStorage()
var lastNextSince: String?
let revs = (0 ... 100).map(String.init)
let session = MockSession { request in
URLComponents(url: request.url!, resolvingAgainstBaseURL: true)?.queryItems?.forEach { item in
if item.name == "since", lastNextSince != nil {
XCTAssertEqual(item.value, lastNextSince)
}
}
let since: Int = lastNextSince == nil ? 0 : Int(lastNextSince!)!
let nextSince = min(since + (revs.count / 20), revs.count)
let list = RevocationList()
list.revokedCerts = Set<String>(revs[since ... nextSince])
let data = try! JSONEncoder().encode(list)
let httpResponse = HTTPURLResponse(url: URL(string: "http://ubique.ch")!, statusCode: 200, httpVersion: nil, headerFields: [
"up-to-date": nextSince == revs.count ? "true" : "false",
"x-next-since": String(nextSince),
])
lastNextSince = String(nextSince)
return (data, httpResponse, nil)
}
let update = RevocationListUpdate(trustStorage: storage, decoder: RevocationListJSONDecoder(), session: session)
_ = update.synchronousUpdate()
for i in 0 ... revs.count / (revs.count / 20) {
XCTAssert(storage.isCertificateRevoced(uvci: revs[i * (revs.count / 20)]))
}
XCTAssertEqual(session.requests.count, 20)
}
func testUpdateEmptyList() {
let storage = TrustStorage()
let session = MockSession { request in
var since: String = ""
URLComponents(url: request.url!, resolvingAgainstBaseURL: true)?.queryItems?.forEach { item in
if item.name == "since" {
since = item.value ?? ""
}
}
let list = RevocationList()
list.revokedCerts = Set<String>()
let data = try! JSONEncoder().encode(list)
let httpResponse = HTTPURLResponse(url: URL(string: "http://ubique.ch")!, statusCode: 200, httpVersion: nil, headerFields: [
"up-to-date": "true",
"x-next-since": since,
])
return (data, httpResponse, nil)
}
let update = RevocationListUpdate(trustStorage: storage, decoder: RevocationListJSONDecoder(), session: session)
_ = update.synchronousUpdate()
}
func testPrePackagedDecoding() {
let storage = RevocationStorage(enviroment: .prod)
XCTAssertNotNil(storage.nextSince)
XCTAssertNotEqual(storage.lastDownload, 0)
XCTAssertNotEqual(storage.validDuration, 0)
}*/
}
class RevocationListJSONDecoder: RevocationListDecoder {
func decode(_ data: Data) -> RevocationList? {
try? JSONDecoder().decode(RevocationList.self, from: data)
}
}