This repository was archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathVaporAPNSTests.swift
74 lines (62 loc) · 2.27 KB
/
VaporAPNSTests.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
//
// VaporAPNSTests.swift
// VaporAPNS
//
// Created by Matthijs Logemann on 23/09/2016.
//
//
import XCTest
@testable import VaporAPNS
import VaporJWT
import JSON
import Foundation
import CLibreSSL
import Core
class VaporAPNSTests: XCTestCase { // TODO: Set this up so others can test this 😉
let vaporAPNS: VaporAPNS! = nil
override func setUp() {
// print ("Hi")
}
func testLoadPrivateKey() throws {
var filepath = ""
let fileManager = FileManager.default
#if os(Linux)
filepath = fileManager.currentDirectoryPath.appending("/Tests/VaporAPNSTests/TestAPNSAuthKey.p8")
#else
if let filepathe = Bundle.init(for: type(of: self)).path(forResource: "TestAPNSAuthKey", ofType: "p8") {
filepath = filepathe
}else {
filepath = fileManager.currentDirectoryPath.appending("/Tests/VaporAPNSTests/TestAPNSAuthKey.p8")
}
#endif
print (filepath)
if fileManager.fileExists(atPath: filepath) {
let (privKey, pubKey) = try filepath.tokenString()
XCTAssertEqual(privKey, "ALEILVyGWnbBaSaIFDsh0yoZaK+Ej0po/55jG2FR6u6C")
XCTAssertEqual(pubKey, "BKqKwB6hpXp9SzWGt3YxnHgCEkcbS+JSrhoqkeqru/Nf62MeE958RIiKYsLFA/czdE7ThCt46azneU0IBnMCuQU=")
} else {
XCTFail("APNS Authentication key not found!")
}
}
func testEncoding() throws {
let jwt = try! JWT(
additionalHeaders: [KeyID("E811E6AE22")],
payload: Node([IssuerClaim("D86BEC0E8B"), IssuedAtClaim()]),
signer: ES256(key: "ALEILVyGWnbBaSaIFDsh0yoZaK+Ej0po/55jG2FR6u6C"))
let tokenString = try! jwt.createToken()
do {
let jwt2 = try JWT(token: tokenString)
let verified = try jwt2.verifySignatureWith(ES256(key: "BKqKwB6hpXp9SzWGt3YxnHgCEkcbS+JSrhoqkeqru/Nf62MeE958RIiKYsLFA/czdE7ThCt46azneU0IBnMCuQU="))
XCTAssertTrue(verified)
} catch {
print(error)
XCTFail("Couldn't verify token")
}
}
static var allTests : [(String, (VaporAPNSTests) -> () throws -> Void)] {
return [
("testLoadPrivateKey", testLoadPrivateKey),
("testEncoding", testEncoding),
]
}
}