forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasswordTests.swift
21 lines (17 loc) · 955 Bytes
/
PasswordTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import XCTest
import NIOCore
@testable import PostgresNIO
class PasswordTests: XCTestCase {
func testEncodePassword() {
let encoder = PSQLFrontendMessageEncoder()
var byteBuffer = ByteBuffer()
// md522d085ed8dc3377968dc1c1a40519a2a = "abc123" with salt 1, 2, 3, 4
let message = PostgresFrontendMessage.password(.init(value: "md522d085ed8dc3377968dc1c1a40519a2a"))
encoder.encode(data: message, out: &byteBuffer)
let expectedLength = 41 // 1 (id) + 4 (length) + 35 (string) + 1 (null termination)
XCTAssertEqual(byteBuffer.readableBytes, expectedLength)
XCTAssertEqual(byteBuffer.readInteger(as: UInt8.self), PostgresFrontendMessage.ID.password.rawValue)
XCTAssertEqual(byteBuffer.readInteger(as: Int32.self), Int32(expectedLength - 1)) // length
XCTAssertEqual(byteBuffer.readNullTerminatedString(), "md522d085ed8dc3377968dc1c1a40519a2a")
}
}