-
Notifications
You must be signed in to change notification settings - Fork 6
fix(ios): gate the media upload server on the site root too #624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import Foundation | ||
|
|
||
| /// Whether the editor configuration can reach the configured site for media. | ||
| /// | ||
| /// Deliberately outside `EditorViewController`. That type is `#if canImport(UIKit)`, | ||
| /// so on the macOS host it does not exist and nothing in it can be tested — including | ||
| /// this check, which already diverged silently between iOS and Android once. Living | ||
| /// here, it is reachable from the host test suite. | ||
| enum MediaServerCredentials { | ||
| /// Whether a ``DefaultMediaUploader`` built from this configuration could actually | ||
| /// reach the site. | ||
| /// | ||
| /// Both fields are required. The uploader delivers GutenbergKit's uploads to the | ||
| /// configured site, so it needs somewhere to send them and credentials to be | ||
| /// accepted; with either missing, every media request it makes fails. | ||
| /// | ||
| /// `siteApiRoot` is a `URL` here where Android types it as a `String`, so the | ||
| /// equivalent of Android's `isEmpty()` check is "not absolute" — a URL with no | ||
| /// scheme or host cannot address the site, and every request built from it fails at | ||
| /// the URLSession layer. | ||
| static func areUsable(siteApiRoot: URL, authHeader: String) -> Bool { | ||
| siteApiRoot.scheme != nil && siteApiRoot.host() != nil && !authHeader.isEmpty | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,41 @@ | ||||||
| import Foundation | ||||||
| import Testing | ||||||
|
|
||||||
| @testable import GutenbergKit | ||||||
|
|
||||||
| @Suite("MediaServerCredentials") | ||||||
| struct MediaServerCredentialsTests { | ||||||
| private static let siteRoot = URL(string: "https://example.com/wp-json/")! | ||||||
|
|
||||||
| @Test("accepts an absolute site root with an auth header") | ||||||
| func acceptsUsableCredentials() { | ||||||
| #expect(MediaServerCredentials.areUsable(siteApiRoot: Self.siteRoot, authHeader: "Bearer t")) | ||||||
| } | ||||||
|
|
||||||
| @Test("rejects an empty auth header") | ||||||
| func rejectsEmptyAuthHeader() { | ||||||
| #expect(!MediaServerCredentials.areUsable(siteApiRoot: Self.siteRoot, authHeader: "")) | ||||||
| } | ||||||
|
|
||||||
| // The two arms below are what a `URL` makes different from Android's `String`: | ||||||
| // `isEmpty()` has no direct equivalent, so "addressable" is spelled as scheme and | ||||||
| // host both being present. A URL missing either cannot reach the site, and every | ||||||
| // request built from it fails at the URLSession layer. | ||||||
|
|
||||||
| @Test("rejects a site root with no scheme") | ||||||
| func rejectsSchemelessSiteRoot() { | ||||||
| let relative = URL(string: "example.com/wp-json/")! | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finding from Claude:
A network-path reference separates them (
Suggested change
|
||||||
| #expect(!MediaServerCredentials.areUsable(siteApiRoot: relative, authHeader: "Bearer t")) | ||||||
| } | ||||||
|
|
||||||
| @Test("rejects a site root with no host") | ||||||
| func rejectsHostlessSiteRoot() { | ||||||
| let fileURL = URL(fileURLWithPath: "/tmp/wp-json") | ||||||
| #expect(!MediaServerCredentials.areUsable(siteApiRoot: fileURL, authHeader: "Bearer t")) | ||||||
| } | ||||||
|
|
||||||
| @Test("rejects an empty site root, the default when a host configures none") | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finding from Claude:
Suggested change
|
||||||
| func rejectsEmptySiteRoot() { | ||||||
| #expect(!MediaServerCredentials.areUsable(siteApiRoot: URL(string: "/")!, authHeader: "Bearer t")) | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finding from Claude:
This widens the gate from
!authHeader.isEmptyto also require an addressablesiteApiRoot— but a delegate that handles uploads itself never touchesDefaultMediaUploader.MediaUploadServer.processAndUploadreturns.uploaded(result)straight fromuploadDelegatewithout resolvingcontext.defaultUploader, so that host now loses its own upload path over a site root it never uses.Intended? If not, the site-root arm belongs where
defaultUploaderis actually built.