mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-18 03:27:08 +00:00
Hub: - add encrypted Live Activity token registry, registration API, and update/end pushes over direct APNs - enable only for HAPI_IOS_PUSH=apns; relay reports remote:false - keep content-state encrypted with the per-install push key and a domain-separated AAD iOS: - add ActivityKit coordinator, HapiWidgets extension, lock-screen and Dynamic Island UI, encrypted content-state, deep links, and settings toggle - cap concurrent activities and reconcile across hub switches Docs/tests: - native contract, privacy, READMEs, localization catalogs - cross-language cipher fixture and hub/iOS unit tests via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run> Co-Authored-By: Claude Code <noreply@anthropic.com>
69 lines
2.6 KiB
Swift
69 lines
2.6 KiB
Swift
import Foundation
|
|
import HapiProtocol
|
|
import Testing
|
|
|
|
@Suite("SessionLink parsing")
|
|
struct SessionLinkTests {
|
|
@Test func parsesAPlainSessionLink() {
|
|
let link = SessionLink.parse("hapicompanion://sessions/sess-123")
|
|
|
|
#expect(link == SessionLink(sessionId: "sess-123", hubUrl: nil))
|
|
}
|
|
|
|
@Test func parsesAnEncodedHubHint() {
|
|
let link = SessionLink.parse(
|
|
"hapicompanion://sessions/sess-123?hub=https%3A%2F%2Fhapi.example.com"
|
|
)
|
|
|
|
#expect(link?.sessionId == "sess-123")
|
|
#expect(link?.hubUrl == "https://hapi.example.com")
|
|
}
|
|
|
|
@Test func acceptsCaseInsensitiveSchemeAndHost() {
|
|
let link = SessionLink.parse("HAPICOMPANION://SESSIONS/sess-123")
|
|
|
|
#expect(link?.sessionId == "sess-123")
|
|
}
|
|
|
|
@Test func acceptsATrailingSlash() {
|
|
#expect(SessionLink.parse("hapicompanion://sessions/sess-123/")?.sessionId == "sess-123")
|
|
}
|
|
|
|
@Test func ignoresABlankOrNonHTTPHubHint() {
|
|
#expect(SessionLink.parse("hapicompanion://sessions/sess-123?hub=")?.hubUrl == nil)
|
|
#expect(SessionLink.parse("hapicompanion://sessions/sess-123?hub=not-a-url")?.hubUrl == nil)
|
|
#expect(SessionLink.parse("hapicompanion://sessions/sess-123?hub=ftp%3A%2F%2Fh")?.hubUrl == nil)
|
|
}
|
|
|
|
@Test func keepsTheFirstDuplicateHubHint() {
|
|
let link = SessionLink.parse(
|
|
"hapicompanion://sessions/sess-123?hub=https%3A%2F%2Fa.example.com&hub=https%3A%2F%2Fb.example.com"
|
|
)
|
|
|
|
#expect(link?.hubUrl == "https://a.example.com")
|
|
}
|
|
|
|
@Test func rejectsWrongSchemeOrHost() {
|
|
#expect(SessionLink.parse("https://sessions/sess-123") == nil)
|
|
#expect(SessionLink.parse("hapicompanion://session/sess-123") == nil)
|
|
#expect(SessionLink.parse("hapicompanion://bind?hub=https%3A%2F%2Fh") == nil)
|
|
}
|
|
|
|
@Test func rejectsMissingOrMalformedIds() {
|
|
#expect(SessionLink.parse("hapicompanion://sessions") == nil)
|
|
#expect(SessionLink.parse("hapicompanion://sessions/") == nil)
|
|
#expect(SessionLink.parse("hapicompanion://sessions/a/b") == nil)
|
|
#expect(SessionLink.parse("hapicompanion://sessions/%20") == nil)
|
|
#expect(SessionLink.parse("hapicompanion://sessions/%zz") == nil)
|
|
#expect(SessionLink.parse("") == nil)
|
|
}
|
|
|
|
@Test func buildsTheWidgetURL() throws {
|
|
let url = try #require(SessionLink.url(sessionId: "sess-123", hubUrl: "https://hapi.example.com"))
|
|
let link = try #require(SessionLink.parse(url.absoluteString))
|
|
|
|
#expect(link.sessionId == "sess-123")
|
|
#expect(link.hubUrl == "https://hapi.example.com")
|
|
}
|
|
}
|