diff options
| author | Christian Cleberg <[email protected]> | 2026-03-18 19:16:02 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-03-18 19:16:02 -0500 |
| commit | 7fba8922e1540741240555560cc9504342bdb091 (patch) | |
| tree | 8f87280f5b50dcf2199de2e8305e020276d51421 /HutchTests/SRHTClientTests.swift | |
| parent | 1745311950fd68ad81957b3ba64f8566cd86ce19 (diff) | |
| download | hutch-7fba8922e1540741240555560cc9504342bdb091.tar.gz hutch-7fba8922e1540741240555560cc9504342bdb091.tar.bz2 hutch-7fba8922e1540741240555560cc9504342bdb091.zip | |
Guard authenticated text fetches to sr.ht hosts and add regression test
Diffstat (limited to 'HutchTests/SRHTClientTests.swift')
| -rw-r--r-- | HutchTests/SRHTClientTests.swift | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/HutchTests/SRHTClientTests.swift b/HutchTests/SRHTClientTests.swift new file mode 100644 index 0000000..2ce2529 --- /dev/null +++ b/HutchTests/SRHTClientTests.swift @@ -0,0 +1,27 @@ +import Foundation +import Testing +@testable import Hutch + +struct SRHTClientTests { + + @Test + @MainActor + func fetchTextRejectsUnexpectedAuthenticatedURL() async throws { + let client = SRHTClient(token: "test-token") + let url = try #require(URL(string: "https://example.com/build-log")) + + do { + _ = try await client.fetchText(url: url) + Issue.record("Expected fetchText(url:) to reject non-sr.ht URLs.") + } catch let error as SRHTError { + guard case .invalidAuthenticatedURL(let rejectedURL) = error else { + Issue.record("Expected invalidAuthenticatedURL error, got \(error).") + return + } + + #expect(rejectedURL == url) + } catch { + Issue.record("Expected SRHTError.invalidAuthenticatedURL, got \(error).") + } + } +} |
