Skip to content

Commit ad5799d

Browse files
committed
fix: address second round of PR review feedback
1 parent 4471a13 commit ad5799d

5 files changed

Lines changed: 19 additions & 20 deletions

File tree

Plugins/EtcdDriverPlugin/EtcdCommandParser.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ extension EtcdParseError: PluginDriverError {
8080
}
8181

8282
struct EtcdCommandParser {
83-
private static let logger = Logger(subsystem: "com.TablePro.EtcdDriver", category: "EtcdCommandParser")
83+
private static let logger = Logger(subsystem: "com.TablePro", category: "EtcdCommandParser")
8484

8585
// MARK: - Public API
8686

Plugins/EtcdDriverPlugin/EtcdHttpClient.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ final class EtcdHttpClient: @unchecked Sendable {
314314
private var authToken: String?
315315
private var _isAuthenticating = false
316316

317-
private static let logger = Logger(subsystem: "com.TablePro.EtcdDriver", category: "EtcdHttpClient")
317+
private static let logger = Logger(subsystem: "com.TablePro", category: "EtcdHttpClient")
318318

319319
init(config: DriverConnectionConfig) {
320320
self.config = config
@@ -903,6 +903,7 @@ final class EtcdHttpClient: @unchecked Sendable {
903903

904904
if !verifyHostname {
905905
// VerifyCA mode: validate the CA chain but skip hostname check
906+
Self.logger.debug("TLS: skipping hostname verification (VerifyCA mode)")
906907
let policy = SecPolicyCreateBasicX509()
907908
SecTrustSetPolicies(serverTrust, policy)
908909
}

Plugins/EtcdDriverPlugin/EtcdPluginDriver.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class EtcdPluginDriver: PluginDatabaseDriver, @unchecked Sendable {
2121
lock.withLock { _httpClient }
2222
}
2323

24-
private static let logger = Logger(subsystem: "com.TablePro.EtcdDriver", category: "EtcdPluginDriver")
24+
private static let logger = Logger(subsystem: "com.TablePro", category: "EtcdPluginDriver")
2525
private static let maxKeys = PluginRowLimits.defaultMax
2626

2727

@@ -213,7 +213,7 @@ final class EtcdPluginDriver: PluginDatabaseDriver, @unchecked Sendable {
213213

214214
// Skip leading "/" when finding the first segment
215215
let searchStart: String.Index
216-
if relative.hasPrefix("/") && relative.count > 1 {
216+
if relative.hasPrefix("/"), relative.index(after: relative.startIndex) < relative.endIndex {
217217
searchStart = relative.index(after: relative.startIndex)
218218
} else {
219219
searchStart = relative.startIndex
@@ -919,8 +919,8 @@ final class EtcdPluginDriver: PluginDatabaseDriver, @unchecked Sendable {
919919
/// Empty prefix uses null byte (\0) as key to mean "all keys".
920920
private static func allKeysRange(for prefix: String) -> (key: String, rangeEnd: String) {
921921
if prefix.isEmpty {
922-
// \0 as key = start from beginning, \0 as range_end = all keys
923-
let b64Key = EtcdHttpClient.base64Encode("\0")
922+
// Empty key = start from beginning, \0 as range_end = all keys
923+
let b64Key = EtcdHttpClient.base64Encode("")
924924
let b64RangeEnd = EtcdHttpClient.base64Encode("\0")
925925
return (b64Key, b64RangeEnd)
926926
}

Plugins/EtcdDriverPlugin/EtcdStatementGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import os
1010
import TableProPluginKit
1111

1212
struct EtcdStatementGenerator {
13-
private static let logger = Logger(subsystem: "com.TablePro.EtcdDriver", category: "EtcdStatementGenerator")
13+
private static let logger = Logger(subsystem: "com.TablePro", category: "EtcdStatementGenerator")
1414

1515
let prefix: String
1616
let columns: [String]

TableProTests/Plugins/EtcdHttpClientUtilityTests.swift

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,19 @@ struct EtcdPrefixRangeEndTests {
116116

117117
@Test("All 0xFF bytes returns null byte")
118118
func allMaxBytes() {
119-
// Build a string where all bytes are 0xFF
120-
let bytes: [UInt8] = [0xFF, 0xFF, 0xFF]
121-
let input = String(bytes: bytes, encoding: .utf8) ?? ""
122-
// If input can't be created as valid UTF-8, test that the function handles it
123-
if !input.isEmpty {
124-
let result = TestEtcdPrefixRange.rangeEnd(for: input)
125-
#expect(result == "\0")
126-
}
119+
// 0xFF bytes aren't valid UTF-8; test with lossy decoding to exercise the all-max-byte path
120+
let input = String(decoding: [0xFF, 0xFF, 0xFF] as [UInt8], as: UTF8.self)
121+
let result = TestEtcdPrefixRange.rangeEnd(for: input)
122+
#expect(result == "\0")
127123
}
128124

129-
@Test("Prefix with trailing 0xFF bytes rolls back correctly")
130-
func trailingMaxBytes() {
131-
// "a" followed by nothing special: just increment last byte
132-
let result = TestEtcdPrefixRange.rangeEnd(for: "a")
133-
#expect(result == "b")
125+
@Test("Prefix ending with high-value byte rolls back correctly")
126+
func trailingHighBytes() {
127+
// "a" + 0xFE (high but not max) should increment 0xFE to 0xFF, truncate to "a\xFF"
128+
// But since 0xFE isn't valid UTF-8 continuation, test with valid multi-byte:
129+
// Use "z" which is 0x7A — incrementing gives 0x7B = "{"
130+
let result = TestEtcdPrefixRange.rangeEnd(for: "az")
131+
#expect(result == "a{")
134132
}
135133
}
136134

0 commit comments

Comments
 (0)