Skip to content

Add a parse test for the minimal private-site API root - #1606

Draft
jkmassel wants to merge 1 commit into
trunkfrom
jkmassel/private-site-api-root-parse-test
Draft

jkmassel wants to merge 1 commit into
trunkfrom
jkmassel/private-site-api-root-parse-test

Conversation

@jkmassel

@jkmassel jkmassel commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a validation test that the minimal REST API root a private site advertises parses into WpApiDetails. A private site serves a stripped-down /wp-json/ index — just enough for a client to discover the application-password login endpoint — and this locks in that the library reads it correctly.

No library behavior change: WpApiDetails already parses this shape. The test guards that contract against regressions.

Changes

  • test-data/api-details/test-case-08.json (new): the minimal private-site root — application-passwords authentication only, empty namespaces and routes ({}), gmt_offset: 0, and no timezone_string/site_icon_url.
  • wp_api/src/login.rs: test_parse_private_site_api_root asserts the fixture parses and that find_application_passwords_authentication_url() returns the authorize endpoint. The fixture is also added to the test_api_details_json parse list, with a pointer comment to the new README.
  • test-data/api-details/README.md (new): a catalogue of all eight api-details fixtures — what each exercises, plus the recurring WordPress serialization quirks they cover ([] vs {} empty maps, gmt_offset as string-or-number, site_icon_url as false/string/absent, and the UTF-8 BOM). Retroactively documents the previously-undocumented cases 01–07.
  • CHANGELOG.md: an **Internal:** entry under ### Changed.

Notes

The fixture uses "routes": {}, matching what a correct emitter produces. The parser is intentionally left strictroutes is a plain HashMap, so a routes: [] (PHP's json_encode([]) for an empty map) would fail this test rather than be silently tolerated. That is the desired behavior: a malformed root surfaces as a loud failure. Empty authentication is the one field that already tolerates [], because WordPress core itself emits it that way (see test-case-04.json).

Test plan

  • cargo test -p wp_api --lib -- login::tests — all parse tests pass, including test_parse_private_site_api_root and the new test_api_details_json case.
  • cargo fmt --all -- --check — clean.
  • cargo clippy -p wp_api --tests --all-features -- -D warnings — clean.

Changelog

  • I've added an entry to CHANGELOG.md under ## [Unreleased], using the Keep a Changelog categories — an **Internal:** note under ### Changed (no user-facing behavior change).

Locks in that `WpApiDetails` reads the stripped-down `/wp-json/` index a
private site serves — application-passwords auth only, empty namespaces and
routes. Also adds a README cataloguing the `api-details` fixtures. No library
behavior change.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@wpmobilebot

Copy link
Copy Markdown
Collaborator

XCFramework Build

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

.package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1606")

Built from 4faa68c

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants