2022-01-23 20:49:06 +01:00
|
|
|
@testable import App
|
|
|
|
import XCTVapor
|
|
|
|
|
|
|
|
final class AppTests: XCTestCase {
|
2022-04-07 23:53:25 +02:00
|
|
|
|
|
|
|
func testEncodingUInt32() {
|
|
|
|
let input: UInt32 = 123
|
|
|
|
let data = input.encoded
|
|
|
|
let output = UInt32(data: data)
|
|
|
|
XCTAssertEqual(input, output)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testEncodingContent() {
|
|
|
|
let input = Message.Content(time: 1234567890, id: 23456789)
|
2022-05-01 13:12:16 +02:00
|
|
|
let data = Array(input.encoded)
|
2022-04-07 23:53:25 +02:00
|
|
|
let output = Message.Content(decodeFrom: data)
|
|
|
|
XCTAssertEqual(input, output)
|
2022-04-08 13:33:09 +02:00
|
|
|
let data2 = [42, 42] + data
|
|
|
|
let output2 = Message.Content(decodeFrom: data2[2...])
|
2022-04-07 23:53:25 +02:00
|
|
|
XCTAssertEqual(input, output2)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testEncodingMessage() {
|
|
|
|
let input = Message(mac: Data(repeating: 42, count: 32),
|
|
|
|
content: Message.Content(time: 1234567890, id: 23456789))
|
|
|
|
let data = input.encoded
|
|
|
|
let buffer = ByteBuffer(data: data)
|
|
|
|
let output = Message(decodeFrom: buffer)
|
|
|
|
XCTAssertEqual(input, output)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testSigning() throws {
|
|
|
|
let key = SymmetricKey(size: .bits256)
|
|
|
|
let content = Message.Content(time: 1234567890, id: 23456789)
|
|
|
|
let input = content.authenticate(using: key)
|
|
|
|
XCTAssertTrue(input.isValid(using: key))
|
|
|
|
|
|
|
|
let data = content.authenticateAndSerialize(using: key)
|
|
|
|
let decoded = Message(decodeFrom: ByteBuffer(data: data))
|
|
|
|
XCTAssertNotNil(decoded)
|
|
|
|
XCTAssertTrue(decoded!.isValid(using: key))
|
|
|
|
XCTAssertEqual(decoded!, input)
|
|
|
|
XCTAssertEqual(content, input.content)
|
2022-01-23 20:49:06 +01:00
|
|
|
}
|
2022-04-08 13:33:09 +02:00
|
|
|
|
|
|
|
func testMessageTransmission() throws {
|
|
|
|
let app = Application(.testing)
|
|
|
|
defer { app.shutdown() }
|
|
|
|
try configure(app)
|
|
|
|
|
|
|
|
// How to open a socket via request?
|
|
|
|
}
|
2022-01-23 20:49:06 +01:00
|
|
|
}
|