diff --git a/Sources/CLI/client/AppleSupportClient+Error.swift b/Sources/CLI/client/AppleSupportClient+Error.swift index 5dc29ae..2c235f7 100644 --- a/Sources/CLI/client/AppleSupportClient+Error.swift +++ b/Sources/CLI/client/AppleSupportClient+Error.swift @@ -10,7 +10,7 @@ enum AppleSupportClientError: Error, Equatable, LocalizedError { var errorDescription: String? { switch self { case .invalidPath: - return "Expected a developer-site-relative path under help/ or support/ without a query or fragment." + return "Expected a supported developer-site-relative path without a query or fragment." case .invalidResponse: return "Apple support returned an invalid response or redirected outside supported developer pages." case .httpStatus(let status): diff --git a/Sources/CLI/client/AppleSupportClient.swift b/Sources/CLI/client/AppleSupportClient.swift index 377d16a..70552f2 100644 --- a/Sources/CLI/client/AppleSupportClient.swift +++ b/Sources/CLI/client/AppleSupportClient.swift @@ -8,6 +8,7 @@ import Logging #if DEBUG protocol AppleSupportClient: Sendable { func fetchHTML(at destination: SupportDestination) async throws -> SupportHTMLDocument + func fetchDocument(at destination: SupportDestination) async throws -> SupportDocumentResponse } extension DefaultAppleSupportClient: AppleSupportClient {} typealias DefaultAppleSupportClientDependencies = HTTPDataTransport @@ -16,6 +17,11 @@ import Logging typealias DefaultAppleSupportClientDependencies = URLSession #endif +enum SupportDocumentResponse: Equatable, Sendable { + case html(SupportHTMLDocument) + case pdf(URL) +} + struct SupportHTMLDocument: Equatable, Sendable { let destination: SupportDestination let html: String @@ -32,7 +38,14 @@ final class DefaultAppleSupportClient SupportHTMLDocument { - logger.debug("Requesting support HTML", metadata: ["path": .string(destination.path)]) + switch try await fetchDocument(at: destination) { + case .html(let document): return document + case .pdf: throw AppleSupportClientError.unsupportedContentType("application/pdf") + } + } + + func fetchDocument(at destination: SupportDestination) async throws -> SupportDocumentResponse { + logger.debug("Requesting support document", metadata: ["path": .string(destination.path)]) let (data, response) = try await dependencies.data(from: destination.url) guard let response = response as? HTTPURLResponse, let responseURL = response.url else { throw AppleSupportClientError.invalidResponse @@ -42,6 +55,7 @@ final class DefaultAppleSupportClient 2 && parts[0] == "help" && ["account", "app-store-connect", "app-review"].contains(parts[1])) - || path == "support/fee-waiver" - || path == "support/terms/apple-developer-program-license-agreement" + || path.hasPrefix("support/") + || path == "xcode/system-requirements" } private func quote(_ text: String) -> String { diff --git a/Sources/CLI/renderer/SupportTextRenderer.swift b/Sources/CLI/renderer/SupportTextRenderer.swift index f592632..5974ed3 100644 --- a/Sources/CLI/renderer/SupportTextRenderer.swift +++ b/Sources/CLI/renderer/SupportTextRenderer.swift @@ -45,6 +45,8 @@ struct SupportTextRenderer { } case .termsEntry(let value): return termsEntry(value, level: 1) + case .pdf(let value): + return [value.message + " " + value.url.absoluteString] case .article(let value): return [ heading(value.title, level: 1), value.url.absoluteString, diff --git a/Sources/CLI/support/AppleSupportService.swift b/Sources/CLI/support/AppleSupportService.swift index 5051798..0ba927e 100644 --- a/Sources/CLI/support/AppleSupportService.swift +++ b/Sources/CLI/support/AppleSupportService.swift @@ -13,7 +13,7 @@ import Foundation func fetchGlossaryEntry(term: String) async throws -> SupportGlossaryEntry func fetchTerms(category: String?) async throws -> SupportTermsCatalog func fetchTermsEntry(named name: String) async throws -> SupportTermsEntry - func fetchArticle(path: String) async throws -> SupportArticle + func fetchDocument(path: String) async throws -> SupportDocument } extension DefaultAppleSupportService: AppleSupportService {} typealias DefaultAppleSupportServiceDependencies = AppleSupportClient @@ -88,8 +88,12 @@ final class DefaultAppleSupportService SupportArticle { - try await parser(path: path).article() + func fetchDocument(path: String) async throws -> SupportDocument { + let destination = try SupportDestination(path: path) + switch try await dependencies.fetchDocument(at: destination) { + case .html(let document): return try .article(SupportHTMLParser(document: document).article()) + case .pdf(let url): return .pdf(SupportPDF(url: url)) + } } private func parser(path: String) async throws -> SupportHTMLParser { diff --git a/Sources/CLI/support/SupportContent.swift b/Sources/CLI/support/SupportContent.swift index 38e09ef..8bdff1e 100644 --- a/Sources/CLI/support/SupportContent.swift +++ b/Sources/CLI/support/SupportContent.swift @@ -39,6 +39,16 @@ struct SupportBreadcrumb: Encodable, Equatable, Sendable { let url: URL? } +enum SupportDocument: Equatable, Sendable { + case article(SupportArticle) + case pdf(SupportPDF) +} + +struct SupportPDF: Encodable, Equatable, Sendable { + let url: URL + let message = "Page is PDF which cannot be displayed. You can download from:" +} + struct SupportArticle: Encodable, Equatable, Sendable { let url: URL let title: String diff --git a/Sources/CLI/support/SupportHTMLParser+Content.swift b/Sources/CLI/support/SupportHTMLParser+Content.swift index cb7d01d..109a578 100644 --- a/Sources/CLI/support/SupportHTMLParser+Content.swift +++ b/Sources/CLI/support/SupportHTMLParser+Content.swift @@ -118,7 +118,7 @@ extension SupportHTMLParser { } private func isInline(_ element: Element) -> Bool { - if !element.isBlock() { return true } + if !element.isBlock() { return element.children().allSatisfy(isInline) } return ["ins", "del", "s"].contains(element.tagName()) && element.children().allSatisfy(isInline) } diff --git a/Sources/CLI/support/SupportHTMLParser.swift b/Sources/CLI/support/SupportHTMLParser.swift index 5ec0e4f..d203e02 100644 --- a/Sources/CLI/support/SupportHTMLParser.swift +++ b/Sources/CLI/support/SupportHTMLParser.swift @@ -77,7 +77,7 @@ struct SupportHTMLParser { let url = URL(string: raw, relativeTo: source.destination.url)?.absoluteURL, let components = URLComponents(url: url, resolvingAgainstBaseURL: true), let scheme = components.scheme?.lowercased(), - ["https", "http", "mailto"].contains(scheme), + ["https", "http", "mailto", "applefeedback"].contains(scheme), components.user == nil, components.password == nil else { throw SupportParsingError.invalidLink } return url @@ -108,8 +108,14 @@ struct SupportHTMLParser { } func article() throws -> SupportArticle { - let article = try required("main .main-content article") - let heading = try required("main h1") + let article: Element + if source.destination.path == "xcode/system-requirements" { + _ = try required("main .section-requirements") + article = try required("main") + } else { + article = try required("main .main-content article, main > article, body > article") + } + let heading = try document.select("main h1").first() ?? required("h1", in: article) let content = try blocks(in: article) guard !content.isEmpty else { throw layoutError } return SupportArticle( diff --git a/Tests/CLIIntegrationTests/SupportCommandIntegrationTests.swift b/Tests/CLIIntegrationTests/SupportCommandIntegrationTests.swift index 7a52a62..76eee8e 100644 --- a/Tests/CLIIntegrationTests/SupportCommandIntegrationTests.swift +++ b/Tests/CLIIntegrationTests/SupportCommandIntegrationTests.swift @@ -41,6 +41,31 @@ struct SupportCommandIntegrationTests { "help/app-store-connect/reference/app-information/screenshot-specifications", "support/fee-waiver", "support/terms/apple-developer-program-license-agreement", + "support/bimi", + "support/install-beta", + "support/technical", + "support/kernel-extensions", + "support/forums", + "support/expiration", + "support/ipv6", + "support/sca", + "support/xcode", + "support/app-store", + "support/volume-purchase-and-custom-apps", + "support/protecting-users-from-suspicious-software", + "support/required-device-capabilities", + "support/unlisted-app-distribution", + "support/dma-and-apps-in-the-eu", + "support/third-party-SDK-requirements", + "support/interoperability-requests", + "support/reader-apps", + "support/age-assurance", + "support/app-distribution-in-brazil", + "support/app-distribution-in-japan", + "support/apps-in-the-eu", + "support/storekit-external-entitlement-kr", + "support/hce-transactions-in-apps", + "support/nfc-se-platform", ]) func liveDocument(path: String) throws { // -- Arrange -- @@ -62,6 +87,26 @@ struct SupportCommandIntegrationTests { } } + @Test("returns a download notice for a live PDF without failing") + func livePDF() throws { + // -- Arrange -- + let path = "support/macos-server/macOS-Server-Service-Migration-Guide.pdf" + + // -- Act -- + let output = try runAppleDocs(["support", "view", "--path", path]) + let json = try runAppleDocs(["support", "view", "--path", path, "--agent", "--json"]) + let value = try #require(JSONSerialization.jsonObject(with: Data(json.utf8)) as? [String: Any]) + + // -- Assert -- + #expect(output.contains("Page is PDF which cannot be displayed. You can download from:")) + #expect( + output.contains("https://developer.apple.com/support/downloads/macOS-Server-Service-Migration-Guide.pdf")) + #expect(value["kind"] as? String == "pdf") + #expect( + value["url"] as? String + == "https://developer.apple.com/support/downloads/macOS-Server-Service-Migration-Guide.pdf") + } + @Test("renders live agent text with follow-up navigation") func liveAgentText() throws { // -- Arrange -- diff --git a/Tests/CLITests/client/AppleSupportClientTests.swift b/Tests/CLITests/client/AppleSupportClientTests.swift index a1d0a80..607a82a 100644 --- a/Tests/CLITests/client/AppleSupportClientTests.swift +++ b/Tests/CLITests/client/AppleSupportClientTests.swift @@ -69,6 +69,32 @@ struct AppleSupportClientTests { await #expect(throws: AppleSupportClientError.unsupportedContentType(contentType)) { try await fetch() } } + @Test("reports a linked PDF as non-HTML after its file redirect") + func rejectsLinkedPDF() async throws { + // -- Arrange -- + let url = try #require( + URL(string: "https://developer.apple.com/support/macos-server/macOS-Server-Service-Migration-Guide.pdf")) + let finalURL = try #require( + URL(string: "https://developer.apple.com/support/downloads/macOS-Server-Service-Migration-Guide.pdf")) + let response = try #require( + HTTPURLResponse( + url: finalURL, statusCode: 200, httpVersion: nil, headerFields: ["Content-Type": "application/pdf"])) + let client = DefaultAppleSupportClient( + logger: Logger(label: "test") { _ in SwiftLogNoOpLogHandler() }, + dependencies: HTTPTestTransport(responses: [ + url: .response(data: Data("%PDF-1.3".utf8), response: response) + ])) + let destination = try SupportDestination(path: "support/macos-server/macOS-Server-Service-Migration-Guide.pdf") + + // -- Act -- + let fetch = { try await client.fetchHTML(at: destination) } + + // -- Assert -- + await #expect(throws: AppleSupportClientError.unsupportedContentType("application/pdf")) { + try await fetch() + } + } + @Test("keeps a validated redirect destination") func followsDeveloperRedirect() async throws { // -- Arrange -- @@ -95,6 +121,8 @@ struct AppleSupportClientTests { arguments: [ "https://example.com/help/glossary/", "http://developer.apple.com/help/glossary/", "https://developer.apple.com/account/", "https://developer.apple.com:444/help/glossary/", + "https://example.com/xcode/system-requirements/", "https://developer.apple.com/xcode/download/", + "https://developer.apple.com/xcode/system-requirements?query=secret", ]) func rejectsRedirect(raw: String) async throws { // -- Arrange -- diff --git a/Tests/CLITests/client/SupportDestinationTests.swift b/Tests/CLITests/client/SupportDestinationTests.swift index a49f31a..a2cf44f 100644 --- a/Tests/CLITests/client/SupportDestinationTests.swift +++ b/Tests/CLITests/client/SupportDestinationTests.swift @@ -18,6 +18,33 @@ struct SupportDestinationTests { #expect(destination.url.absoluteString == "https://developer.apple.com/support/D-U-N-S/") } + @Test("preserves PDF file URLs without adding a directory slash") + func preservesPDFURL() throws { + // -- Arrange -- + let path = "support/macos-server/macOS-Server-Service-Migration-Guide.pdf" + + // -- Act -- + let destination = try SupportDestination(path: path) + + // -- Assert -- + #expect( + destination.url.absoluteString + == "https://developer.apple.com/support/macos-server/macOS-Server-Service-Migration-Guide.pdf") + } + + @Test("accepts the Xcode support redirect destination") + func xcodeRequirements() throws { + // -- Arrange -- + let url = try #require(URL(string: "https://developer.apple.com/xcode/system-requirements")) + + // -- Act -- + let destination = try SupportDestination(responseURL: url) + + // -- Assert -- + #expect(destination.path == "xcode/system-requirements") + #expect(destination.url.absoluteString == "https://developer.apple.com/xcode/system-requirements/") + } + @Test( "rejects unsafe or unsupported input before transport", arguments: [ @@ -25,6 +52,7 @@ struct SupportDestinationTests { "help/../account", "help/./glossary", "help/%2e%2e/account", "help/%252e%252e/account", "help/foo%2f..%2faccount", "help/glossary?query=secret", "help/glossary#term", "help/foo\\bar", "help/foo%5cbar", "help/foo\u{001B}[2J", "help/foo%0a", "help//glossary", "help/foo%3fquery=secret", + "xcode", "xcode/download", "xcode/system-requirements/other", "xcode/system-requirements/../download", ]) func rejectsPath(raw: String) { // -- Arrange -- diff --git a/Tests/CLITests/cmd/support/SupportCommandExecutionTests.swift b/Tests/CLITests/cmd/support/SupportCommandExecutionTests.swift index 6c6b984..22c0940 100644 --- a/Tests/CLITests/cmd/support/SupportCommandExecutionTests.swift +++ b/Tests/CLITests/cmd/support/SupportCommandExecutionTests.swift @@ -28,6 +28,52 @@ struct SupportCommandExecutionTests { #expect(deps.telemetry.commands.count == 1) } + @Test("PDF views print a download notice without failing", arguments: [false, true]) + func pdfNotice(agent: Bool) async throws { + // -- Arrange -- + let arguments = + ["support", "view", "--path", "support/macos-server/macOS-Server-Service-Migration-Guide.pdf"] + + (agent ? ["--agent"] : []) + let command = try #require(CLI.parseAsRoot(arguments) as? SupportViewCommand) + let deps = try ExecutionDependencies() + + // -- Act -- + try await command.run(deps: deps) + let output = try #require(deps.output.lines.first) + + // -- Assert -- + #expect(deps.output.lines.count == 1) + #expect(output.contains("Page is PDF which cannot be displayed. You can download from:")) + #expect( + output.contains("https://developer.apple.com/support/downloads/macOS-Server-Service-Migration-Guide.pdf")) + #expect(!output.contains(".pdf/")) + } + + @Test("PDF JSON exposes the download destination", arguments: [false, true]) + func pdfJSON(agent: Bool) async throws { + // -- Arrange -- + let arguments = + [ + "support", "view", "--path", "support/macos-server/macOS-Server-Service-Migration-Guide.pdf", "--json", + ] + (agent ? ["--agent"] : []) + let command = try #require(CLI.parseAsRoot(arguments) as? SupportViewCommand) + let deps = try ExecutionDependencies() + + // -- Act -- + try await command.run(deps: deps) + let output = try #require(deps.output.lines.first) + let value = try #require(JSONSerialization.jsonObject(with: Data(output.utf8)) as? [String: Any]) + + // -- Assert -- + #expect(value["kind"] as? String == "pdf") + #expect( + value["url"] as? String + == "https://developer.apple.com/support/downloads/macOS-Server-Service-Migration-Guide.pdf") + #expect(value["message"] as? String == "Page is PDF which cannot be displayed. You can download from:") + #expect(value["content"] == nil) + #expect((value["navigation"] != nil) == agent) + } + @Test("propagates a missing selection without writing successful output") func selectionFailure() async throws { // -- Arrange -- @@ -75,6 +121,14 @@ private struct ExecutionDependencies: ExecutionProviders { url: url, statusCode: 200, httpVersion: nil, headerFields: ["Content-Type": "text/html"])) responses[url] = .response(data: Data(html.utf8), response: response) } + let pdfURL = try #require( + URL(string: "https://developer.apple.com/support/macos-server/macOS-Server-Service-Migration-Guide.pdf")) + let downloadURL = try #require( + URL(string: "https://developer.apple.com/support/downloads/macOS-Server-Service-Migration-Guide.pdf")) + let pdfResponse = try #require( + HTTPURLResponse( + url: downloadURL, statusCode: 200, httpVersion: nil, headerFields: ["Content-Type": "application/pdf"])) + responses[pdfURL] = .response(data: Data("%PDF-1.3".utf8), response: pdfResponse) supportService = DefaultAppleSupportService( dependencies: DefaultAppleSupportClient( logger: Logger(label: "test") { _ in SwiftLogNoOpLogHandler() }, diff --git a/Tests/CLITests/renderer/SupportRendererTests.swift b/Tests/CLITests/renderer/SupportRendererTests.swift index e94bd8d..e1908e9 100644 --- a/Tests/CLITests/renderer/SupportRendererTests.swift +++ b/Tests/CLITests/renderer/SupportRendererTests.swift @@ -70,6 +70,31 @@ struct SupportRendererTests { #expect(presentation.navigation?.first?.command.contains("'Developer'\\''s account'") == true) } + @Test("offers view commands for standalone articles and Xcode support") + func standaloneNavigation() throws { + // -- Arrange -- + let paths = SupportArticleFixture.standalone.map(\.path) + ["support/xcode", "xcode/system-requirements"] + let links = try paths.map { path in + SupportPageLink( + title: path, url: try #require(URL(string: "https://developer.apple.com/" + path + "/"))) + } + let payload = SupportPayload.articles( + SupportArticlesCatalog( + header: SupportPageHeader( + url: URL(string: "https://developer.apple.com/support/articles/")!, + title: "Articles", introduction: ""), + categories: [SupportArticleCategory(id: "development", title: "Development", summary: "", links: links)] + )) + + // -- Act -- + let presentation = SupportPresenter().present(payload, audience: .agent) + + // -- Assert -- + #expect( + presentation.navigation?.map(\.command) + == paths.map { "apple-docs support view --path '\($0)' --agent" }) + } + @Test("human rendering keeps table contents, code whitespace and legal notices") func humanDocument() throws { // -- Arrange -- diff --git a/Tests/CLITests/support/AppleSupportServiceTests.swift b/Tests/CLITests/support/AppleSupportServiceTests.swift index 09fabde..b89fdf2 100644 --- a/Tests/CLITests/support/AppleSupportServiceTests.swift +++ b/Tests/CLITests/support/AppleSupportServiceTests.swift @@ -90,13 +90,69 @@ struct AppleSupportServiceTests { """) // -- Act -- - let article = try await service.fetchArticle(path: "support/fee-waiver") + let document = try await service.fetchDocument(path: "support/fee-waiver") // -- Assert -- + guard case .article(let article) = document else { + Issue.record("Expected an HTML article") + return + } #expect(article.title == "Fee waiver") #expect(article.content == [.paragraph([.text("Eligible organizations.")])]) } + @Test("reads the Xcode support redirect and its requirements table") + func fetchesXcodeRequirements() async throws { + // -- Arrange -- + let destination = try SupportDestination(path: "support/xcode") + let finalURL = try #require(URL(string: "https://developer.apple.com/xcode/system-requirements")) + let html = """ + + +
+
+

SDKs and system requirements

+
+ +

Previous Xcode versions

+ + +
Xcode VersionSupported macOS VersionsSDKs
Xcode 15.4macOS Sonoma 14.xiOS 17.5
tvOS 17.5
+
+
+ """ + let response = try #require( + HTTPURLResponse( + url: finalURL, statusCode: 200, httpVersion: nil, headerFields: ["Content-Type": "text/html"])) + let service = Service( + dependencies: DefaultAppleSupportClient( + logger: Logger(label: "test") { _ in SwiftLogNoOpLogHandler() }, + dependencies: HTTPTestTransport(responses: [ + destination.url: .response(data: Data(html.utf8), response: response) + ]))) + + // -- Act -- + let document = try await service.fetchDocument(path: "support/xcode") + + // -- Assert -- + guard case .article(let article) = document else { + Issue.record("Expected an HTML article") + return + } + #expect(article.title == "SDKs and system requirements") + #expect(article.url.absoluteString == "https://developer.apple.com/xcode/system-requirements/") + #expect(article.content.first == .heading(level: 3, text: "Previous Xcode versions", anchor: nil)) + let table = try #require(article.content.last) + guard case .table(let rows) = table else { + Issue.record("Expected the requirements table without page chrome") + return + } + #expect(rows.count == 2) + #expect(rows[0].cells.map(\.isHeader) == [true, true, true]) + #expect(rows[1].cells[0].content == [.paragraph([.text("Xcode 15.4")])]) + #expect(rows[1].cells[2].content == [.paragraph([.text("iOS 17.5"), .lineBreak, .text("tvOS 17.5")])]) + } + @Test( "guide identifiers reject paths and cannot escape the guide root", arguments: [ diff --git a/Tests/CLITests/support/SupportArticleFixture.swift b/Tests/CLITests/support/SupportArticleFixture.swift new file mode 100644 index 0000000..a333795 --- /dev/null +++ b/Tests/CLITests/support/SupportArticleFixture.swift @@ -0,0 +1,347 @@ +struct SupportArticleFixture: Sendable { + let path: String + let title: String + let introduction: String + let html: String + + // Reduced from the support pages returned by the article and guide catalogs. + static let standalone: [Self] = general + distribution + + private static let general: [Self] = [ + Self( + path: "support/bimi", + title: "Prepare your email server for BIMI support in Apple Mail", + introduction: "Apple Mail in macOS Ventura 13, iOS 16, and iPadOS 16, or la", + html: """ +
+
+

Prepare your email server for BIMI support in + Apple Mail

+

Apple Mail in macOS Ventura 13, iOS 16, and iPadOS 16, or later supports BIMI + (Brand Indicators for Message Identification), an email specification that enables email clients to + show brand-controlled logos based on information provided by the corresponding organization.

+
+ """), + Self( + path: "support/install-beta", + title: "Installing and using Apple beta software", + introduction: "Apple beta software, also referred to as a preview, seed, or", + html: """ +
+
+

Installing and using Apple beta software

+

Apple beta software, also referred to as a preview, seed, or release + candidate, is for developers to take advantage of the latest advancements in Apple platforms and + test apps for compatibility.

+
+ """), + Self( + path: "support/technical", + title: "Code-level support", + introduction: "Need help with technical or development issues for Apple fra", + html: """ +
+
+

Code-level support

+

Need help with technical or development issues for Apple frameworks, + APIs, and tools?

+
+ """), + Self( + path: "support/kernel-extensions", + title: "Deprecated Kernel Extensions and System Extension Alternatives", + introduction: "System extensions on", + html: """ +
+
+

Deprecated Kernel Extensions and System Extension Alternatives

+

System extensions on macOS Catalina 10.15 or + later allow software, such as network extensions and endpoint security solutions, to extend the + functionality of macOS without requiring kernel-level access.

+
+ """), + Self( + path: "support/forums", + title: "Apple Developer Forums", + introduction: "Apple Developer Forums are a great place to post questions,", + html: """ +
+
+

Apple Developer Forums

+

Apple Developer Forums are a great place to post questions, + exchange knowledge, and connect with fellow developers and Apple engineers on a variety of + development topics.

+
+ """), + Self( + path: "support/expiration", + title: "Apple Worldwide Developer Relations Intermediate Certificate Expiration", + introduction: "To help protect customers and developers, we require that al", + html: """ +
+
+

Apple Worldwide Developer Relations Intermediate Certificate + Expiration

+

To help protect customers and developers, we require that all third-party apps, Apple Wallet + passes, Safari Extensions, Safari Push Notifications, and App Store + purchase receipts are signed by a trusted certificate authority.

+
+ """), + Self( + path: "support/ipv6", + title: "IPv6-Only Networks", + introduction: "As of June 1, 2016, all apps submitted to the", + html: """ +
+
+

IPv6-Only Networks

+

As of June 1, 2016, all apps submitted to the App Store must support + IPv6-only networks.

+
+ """), + Self( + path: "support/sca", + title: "Strong Customer Authentication Transactions", + introduction: "Starting March 14, 2022, the Financial Conduct Authority (FC", + html: """ +
+
+

Strong Customer Authentication Transactions

+

Starting March 14, 2022, the Financial Conduct Authority (FCA) will + require Strong Customer Authentication (SCA) for users in the United Kingdom, which may impact how + they complete online purchases.

+
+ """), + Self( + path: "support/app-store", + title: "App Store", + introduction: "The App Store makes it simple for users to discover, purchas", + html: """ +
+
+

App Store

+

The App Store makes it simple for users to discover, purchase, and + download apps for iPhone, iPad, Mac, Apple TV, and Apple Watch.

+
+ """), + Self( + path: "support/volume-purchase-and-custom-apps", + title: "Distributing Apps on Apple Business and Apple School Manager", + introduction: "All apps on the App Store are automatically available for vo", + html: """ +
+
+

Distributing Apps on Apple Business and Apple School Manager

+

All apps on the App Store are automatically available for volume + purchase for the same price in Apple Business and Apple School Manager, which is where businesses + and educational institutions download apps for volume distribution.

+
+ """), + Self( + path: "support/protecting-users-from-suspicious-software", + title: "Protecting Users from Suspicious Software", + introduction: "Apple is committed to providing great experiences that respe", + html: """ +
+
+

Protecting Users from Suspicious Software

+

Apple is committed to providing great experiences that respect customer + privacy and security.

+
+ """), + Self( + path: "support/required-device-capabilities", + title: "Required Device Capabilities", + introduction: "To ensure that people only download apps that their device s", + html: """ +
+
+

Required Device Capabilities

+

To ensure that people only download apps that their device + supports, the App Store uses values in the UIRequiredDeviceCapabilities property list key to determine the hardware-related capabilities an + app requires.

+
+ """), + Self( + path: "support/unlisted-app-distribution", + title: "Unlisted app distribution", + introduction: "Release your apps that aren’t suited for public distribution", + html: """ +
+
+

Unlisted app distribution

+

Release your apps that aren’t suited for public distribution as unlisted on the App Store, discoverable only with a direct link.

+
+ """), + Self( + path: "support/dma-and-apps-in-the-eu", + title: "Changes for apps in the European Union", + introduction: "Since 2024, Apple has made updates to iOS, iPadOS, Safari, a", + html: """ +
+
+

Changes for apps in the European Union

+

Since 2024, Apple has made updates to iOS, iPadOS, + Safari, and the App Store in the European Union (EU) to comply with the Digital Markets + Act (DMA), giving developers more options in the EU — including the ability to process payments for + digital goods and services outside of Apple In-App Purchase, distribute on alternative app + marketplaces, operate alternative app marketplaces, distribute directly from their website, and use + alternative browser engines.

+
+ """), + ] +} + +extension SupportArticleFixture { + private static let distribution: [Self] = [ + Self( + path: "support/third-party-SDK-requirements", + title: "Third-party SDK requirements", + introduction: "Third-party software development kits (SDKs) can provide gre", + html: """ +
+
+

Third-party SDK requirements

+

Third-party software development kits (SDKs) can provide great functionality for apps; they can + also have the potential to impact user privacy in ways that aren’t obvious to developers and users.

+
+ """), + Self( + path: "support/interoperability-requests", + title: "Interoperability requests", + introduction: "At Apple, enriching people’s lives with amazing experiences", + html: """ +
+
+

Interoperability requests

+

At Apple, enriching people’s lives with amazing experiences is a core + value we share with developers.

+
+ """), + Self( + path: "support/reader-apps", + title: "Distributing “reader” apps with a link to your website", + introduction: "Reader apps are apps that provide one or more of the followi", + html: """ +
+
+

Distributing “reader” apps with a link to your website

+

Reader apps are apps that provide one or more of the following digital content + types — magazines, newspapers, books, audio, music, or video — as the primary functionality of the + app.

+
+ """), + Self( + path: "support/age-assurance", + title: "Age assurance frameworks Q&A", + introduction: "Apple offers a number of frameworks and features that help d", + html: """ +
+
+

Age assurance frameworks Q&A

+

Apple offers a number of frameworks and features that help developers + comply with current and upcoming regional age assurance laws and related requirements.

+
+ """), + Self( + path: "support/app-distribution-in-brazil", + title: "Changes to iOS in Brazil", + introduction: "As part of a recent agreement with Brazil’s competition regu", + html: """ +
+
+

Changes to iOS in Brazil

+

As part of a recent agreement with Brazil’s competition + regulator CADE (Conselho Administrativo de Defesa Econômica), iOS 26.5 introduces new options for + developers with apps in Brazil.

+
+ """), + Self( + path: "support/app-distribution-in-japan", + title: "Changes to iOS in Japan", + introduction: "iOS 26.2 introduces changes for iOS to comply with the Mobil", + html: """ +
+
+

Changes to iOS in Japan

+

iOS 26.2 introduces changes for iOS to comply with + the Mobile Software Competition Act (MSCA), creating new options for developers with apps in Japan.

+
+ """), + Self( + path: "support/apps-in-the-eu", + title: "Changes for apps in the European Union", + introduction: "Since 2024, Apple has made updates to iOS, iPadOS, Safari, a", + html: """ +
+
+

Changes for apps in the European Union

+

Since 2024, Apple has made updates to iOS, iPadOS, + Safari, and the App Store in the European Union (EU) to comply with the Digital Markets + Act (DMA), giving developers more options in the EU — including the ability to process payments for + digital goods and services outside of Apple In-App Purchase, distribute on alternative app + marketplaces, operate alternative app marketplaces, distribute directly from their website, and use + alternative browser engines.

+
+ """), + Self( + path: "support/storekit-external-entitlement-kr", + title: "Distributing apps using a third-party payment provider in South Korea", + introduction: "Following amendments to the Telecommunications Business Act", + html: """ +
+
+

Distributing apps using a third-party payment provider in + South Korea

+

Following amendments to the Telecommunications Business Act in South Korea, developers of apps + distributed on the App Store solely in South Korea can use the StoreKit External Purchase + Entitlement to use alternative payment service providers for in-app purchases.

+
+ """), + Self( + path: "support/hce-transactions-in-apps", + title: "HCE-based contactless NFC transactions for apps in the European Economic Area (EEA)", + introduction: "iOS 17.4 or later includes APIs that support contactless tra", + html: """ +
+
+

HCE-based contactless NFC transactions for apps in the + European Economic Area (EEA)

+

iOS 17.4 or later includes APIs that support contactless transactions + for in-store payments, car keys, closed loop transit, corporate badges, home keys, hotel keys, + program membership, and event tickets from within compatible iOS apps using host card emulation + (HCE).

+
+ """), + Self( + path: "support/nfc-se-platform", + title: "NFC & SE Platform for secure contactless transactions", + introduction: "iOS 18.1 introduced APIs that support secure contactless tra", + html: """ +
+
+

NFC & SE Platform for secure contactless + transactions

+

iOS 18.1 introduced APIs that support secure contactless transactions + within compatible iOS apps using the NFC & SE Platform for in-store payments, car + keys, closed loop transit, corporate badges, student ID, home keys, hotel keys, merchant loyalty and + rewards, and event tickets.

+
+ """), + ] +} diff --git a/Tests/CLITests/support/SupportArticleLayoutTests.swift b/Tests/CLITests/support/SupportArticleLayoutTests.swift new file mode 100644 index 0000000..9a52d89 --- /dev/null +++ b/Tests/CLITests/support/SupportArticleLayoutTests.swift @@ -0,0 +1,45 @@ +import Foundation +import Testing + +@testable import CLI + +@Suite("Support article layouts") +struct SupportArticleLayoutTests { + @Test("rejects an unknown Xcode layout rather than treating page chrome as content") + func unknownXcodeLayout() throws { + // -- Arrange -- + let html = "

Page Not Found

Try a different page.

" + let parser = try SupportHTMLParser( + document: SupportHTMLDocument( + destination: SupportDestination(path: "xcode/system-requirements"), html: html, + responseByteCount: html.utf8.count)) + + // -- Act -- + let parse = { try parser.article() } + + // -- Assert -- + #expect(throws: SupportParsingError.unsupportedLayout("xcode/system-requirements")) { try parse() } + } + + @Test("reads standalone support articles", arguments: SupportArticleFixture.standalone) + func standalone(fixture: SupportArticleFixture) throws { + // -- Arrange -- + let parser = try SupportHTMLParser( + document: SupportHTMLDocument( + destination: SupportDestination(path: fixture.path), html: fixture.html, + responseByteCount: fixture.html.utf8.count)) + + // -- Act -- + let article = try parser.article() + + // -- Assert -- + #expect(article.title == fixture.title) + let first = try #require(article.content.first) + guard case .paragraph(let content) = first, case .text(let text) = content.first else { + Issue.record("Expected the article introduction, not navigation or page chrome") + return + } + #expect(text.hasPrefix(fixture.introduction)) + #expect(article.url.absoluteString == "https://developer.apple.com/" + fixture.path + "/") + } +} diff --git a/Tests/CLITests/support/SupportInlineParsingTests.swift b/Tests/CLITests/support/SupportInlineParsingTests.swift index 4391353..54322e8 100644 --- a/Tests/CLITests/support/SupportInlineParsingTests.swift +++ b/Tests/CLITests/support/SupportInlineParsingTests.swift @@ -5,6 +5,52 @@ import Testing @Suite("Support inline parsing boundaries") struct SupportInlineParsingTests { + @Test("preserves the interoperability page's Feedback Assistant submission link") + func feedbackAssistantLink() throws { + // -- Arrange -- + let html = """ +
+

Interoperability requests

+ """ + let parser = try SupportHTMLParser( + document: SupportHTMLDocument( + destination: SupportDestination(path: "support/interoperability-requests"), html: html, + responseByteCount: html.utf8.count)) + + // -- Act -- + let article = try parser.article() + + // -- Assert -- + let url = try #require( + URL(string: "applefeedback://new?form_identifier=dev.tech&answers%5B%3Aarea%5D=seed%3Ainterop")) + #expect( + article.content.last == .paragraph([.link(label: [.text("Submit request")], url: url)])) + } + + @Test( + "rejects executable and local-file links", + arguments: ["javascript:alert(1)", "data:text/html,bad", "file:///etc/passwd"]) + func rejectsUnsafeLinks(url: String) throws { + // -- Arrange -- + let html = """ +
+ """ + let parser = try SupportHTMLParser( + document: SupportHTMLDocument( + destination: SupportDestination(path: "support/interoperability-requests"), html: html, + responseByteCount: html.utf8.count)) + + // -- Act -- + let parse = { try parser.article() } + + // -- Assert -- + #expect(throws: SupportParsingError.invalidLink) { try parse() } + } + @Test("direct inline code does not absorb later sibling content") func directInlineCode() throws { // -- Arrange --