Skip to content

fix(ios): gate the media upload server on the site root too - #624

Draft
jkmassel wants to merge 1 commit into
fix/register-core-media-upload-middlewarefrom
fix/media-server-site-root-guard
Draft

fix(ios): gate the media upload server on the site root too#624
jkmassel wants to merge 1 commit into
fix/register-core-media-upload-middlewarefrom
fix/media-server-site-root-guard

Conversation

@jkmassel

@jkmassel jkmassel commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Stacked on #594. First of ten PRs splitting #621; each is a single commit on the one before.

What?

iOS starts the native media upload server without checking that siteApiRoot is usable. Android has checked it since it landed.

Why?

startUploadServer guards on authHeader.isEmpty alone, though the comment directly above it says the uploader "needs a site root and an auth header". An iOS host that configured an auth header but no siteApiRoot started a server whose every request failed at the URLSession layer, instead of falling back to the WebView upload path the way Android does.

The two platforms diverged here unnoticed because the check lives in EditorViewController, which is #if canImport(UIKit) — it does not exist on the macOS host, so nothing in it is reachable from the test suite.

How?

  • ios/Sources/GutenbergKit/Sources/Media/MediaServerCredentials.swift: new. areUsable(siteApiRoot:authHeader:) owns the check, outside the UIKit gate so it is testable.
  • ios/Sources/GutenbergKit/Sources/EditorViewController.swift: startUploadServer calls it.

siteApiRoot is a URL here where Android types it as a String, so isEmpty() has no direct equivalent — "addressable" is spelled as scheme and host both being present.

Testing Instructions

Five tests pin the predicate, including both arms of the site-root check.

  • swift test — host suite green
  • iOS Simulator xcodebuild (the host build compiles EditorViewController as empty, so the gated change needs a simulator build)
  • SwiftLint clean

`startUploadServer` checked only `authHeader.isEmpty`, though the comment
directly above it said the uploader "needs a site root and an auth
header". Android has checked both since it landed. An iOS host that
configured an auth header but no `siteApiRoot` therefore started a server
whose every request failed at the URLSession layer, instead of falling
back to the WebView upload path the way Android does.

`siteApiRoot` is a `URL` here where Android types it as a `String`, so
`isEmpty()` has no direct equivalent — "addressable" is spelled as scheme
and host both being present.

Put the check in `MediaServerCredentials` rather than inline.
`EditorViewController` is `#if canImport(UIKit)`, so it does not exist on
the macOS host and nothing in it is reachable from the test suite — which
is how the two platforms diverged here unnoticed. Outside the gate, the
predicate gets five tests, including both arms of the site-root check.
@github-actions github-actions Bot added the [Type] Bug An existing feature does not function as intended label Sep 5, 2026
@jkmassel jkmassel added the iOS label Sep 5, 2026
@jkmassel jkmassel self-assigned this Sep 5, 2026
@wpmobilebot

Copy link
Copy Markdown

XCFramework Build

This PR's XCFramework is available for testing. Add the following to your Package.swift:

.package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/624")

Built from 72b6329

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

iOS [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants