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() {
|
2023-08-08 15:17:59 +02:00
|
|
|
let input = Message.Content(time: 1234567890, id: 23456789, device: 0)
|
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),
|
2023-08-08 15:17:59 +02:00
|
|
|
content: Message.Content(time: 1234567890, id: 23456789, device: 0))
|
2022-04-07 23:53:25 +02:00
|
|
|
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)
|
2023-08-08 15:17:59 +02:00
|
|
|
let content = Message.Content(time: 1234567890, id: 23456789, device: 0)
|
2022-04-07 23:53:25 +02:00
|
|
|
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
|
|
|
|
2023-02-17 00:09:51 +01:00
|
|
|
func testMessageTransmission() async throws {
|
2022-04-08 13:33:09 +02:00
|
|
|
let app = Application(.testing)
|
|
|
|
defer { app.shutdown() }
|
2023-02-17 00:09:51 +01:00
|
|
|
try await configure(app)
|
2022-04-08 13:33:09 +02:00
|
|
|
|
|
|
|
// How to open a socket via request?
|
|
|
|
}
|
2022-01-23 20:49:06 +01:00
|
|
|
}
|