Skip to content

fix(sync): a 200 nobody can parse is a FAILED page, not an empty source - #1227

Merged
rubenvdlinde merged 1 commit into
developmentfrom
fix/oc-1190-sync-rejects-login-page
Aug 12, 2026
Merged

rubenvdlinde merged 1 commit into
developmentfrom
fix/oc-1190-sync-rejects-login-page

Conversation

@rubenvdlinde

Copy link
Copy Markdown
Contributor

Refs #1190 — fixes the product half. The fixture half stays open, deliberately; see below.

A 200 that is not a success

When a source answered 200 with a body no parser could read — overwhelmingly an HTML login or redirect page returned to a fetch with no session — fetchSinglePageData() returned an empty page with no failed flag.

Upstream that is indistinguishable from a source that genuinely had nothing. The run reports success, found: 0, nothing is transferred. No error, no alert, and any monitoring keyed on run status sees a clean run. The only signal that data did not move is a found: 0 that looks like an empty source.

The hard part is not spotting the login page

It is spotting it without breaking pagination. [] and {} decode cleanly to an empty array — that is exactly how a paginated source says "no more pages". So the test cannot be empty($result); failing on that would turn the last page of every sync in the fleet into an error.

The test is now whether any parser understood the body, tracked separately from whether the body held anything, via json_last_error().

HTML is refused the XML parser

A minimal login page — <html><body>Please log in</body></html> — is well-formed XML. It used to parse, come back non-empty, and walk on into object extraction to die there on Cannot determine the position of objects in the return body: a confusing complaint about the source's shape when the real problem is that nobody was logged in.

I found this by writing the test, not by reading the code — the first HTML case passed only because its markup had an unclosed <input>. Two shapes, two paths, and only one of them was covered.

A source that genuinely serves HTML declares Source.configuration.format: "html" (oc#107) and is handled well before this point, so an HTML document reaching here means nothing expected one.

Why failed and not an exception

failed is the flag fetchAllPages() already checks before its end-of-pagination test (REQ-009), so marking it here also stops downstream cleanup treating the page as "nothing left in the source". The plumbing existed; only this case never set it.

The log names the shape and points at credentials — a failed flag with a generic message sends whoever reads it hunting a phantom empty source.

Tests

Nine, and the ones that matter most are the negative ones:

case verdict
HTML login page (malformed) failed
HTML login page (well-formed XML) failed
non-HTML garbage failed, and does not claim HTML
[] not failed — end of pagination
{} not failed
empty body not failed — pre-existing behaviour, pinned
genuine XML still parsed
parseable JSON untouched

The looksLikeHtmlDocument() helper is only ever used to sharpen the log line, never to decide anything — and testNonHtmlGarbageFailsWithoutClaimingHtml exists because without it the helper could return true unconditionally and every other test would still pass.

Positive control: disabling the new branch turns four of the nine red.

Verification

  • PHPUnit 2,207 green, 0 failures, 0 errors (43 excluded locally — they need openregister's real FlowConcurrency, which CI provides).
  • PHPStan [OK] No errors. phpcs clean.

What stays open

The fixture half of #1190. That Source points at http://localhost/…/openregister/api/objects/…, so it exercises Nextcloud's auth middleware rather than the sync engine. It needs an external-shaped source that answers without a Nextcloud session — and sourceType: 'register/schema' is not the way out: reading from a register/schema is @todo: implement in getAllObjectsFromSource(). Verifying a replacement needs the full e2e stack, so it is not attempted here.

Both test.fixme blocks now carry the issue number — the original complaint on #1190 — and the first one's written reason is corrected, because the symptom it described no longer happens: the run now fails loudly instead of succeeding with found: 0.

⚠️ The PHPUnit (PHP 8.3, NC stable32) leg is red on development already — the coverage ratchet cannot measure its merge base. Diagnosed in #1224.

When a source answered 200 with a body no parser could read — overwhelmingly
an HTML login or redirect page returned to a fetch with no session —
`fetchSinglePageData()` returned an empty page with no `failed` flag.
Upstream that is indistinguishable from a source that genuinely had nothing:
the run reports success, `found: 0`, and nothing is transferred. No error, no
alert, and any monitoring keyed on run status sees a clean run. The only
signal that data did not move is a `found: 0` that looks like an empty source.

The hard part is not spotting the login page, it is spotting it WITHOUT
breaking pagination. `[]` and `{}` decode cleanly to an empty array, and that
is exactly how a paginated source says "no more pages" — so the test cannot be
`empty($result)`. It is now whether any parser UNDERSTOOD the body, tracked
separately from whether the body held anything, via `json_last_error()`.

An HTML document is also refused the XML parser entirely. A minimal login page
— `<html><body>Please log in</body></html>` — is well-formed XML, so it used
to parse, come back non-empty, and walk on into object extraction to die there
on "cannot determine the position of objects in the return body": a confusing
complaint about the source's shape when the real problem is that nobody was
logged in. A source that genuinely serves HTML declares
`Source.configuration.format: "html"` (oc#107) and is handled well before this
point, so an HTML document reaching here means nothing expected one.

`failed` is the flag `fetchAllPages()` already checks BEFORE its
end-of-pagination test (REQ-009), so marking it here also stops downstream
cleanup treating the page as "nothing left in the source".

The log names the shape and points at credentials — a `failed` flag with a
generic message sends whoever reads it hunting a phantom empty source.

Nine tests, and the ones that matter most are the negative ones: an empty JSON
array, an empty JSON object and an empty body must all stay non-failures, and
genuine XML must still parse. Those are what an over-eager fix breaks —
failing `[]` would turn the last page of every sync in the fleet into an error.
Positive control: disabling the new branch turns four red.

The e2e quarantine notes are corrected — the symptom they describe no longer
happens — and both now carry the issue number, which was the original
complaint on #1190.

Refs #1190. The FIXTURE half stays open: that Source points at an
authenticated localhost endpoint, so it tests Nextcloud's auth middleware
rather than the sync engine, and `sourceType: 'register/schema'` is not the
way out — reading FROM a register/schema is `@todo: implement`.
@rubenvdlinde
rubenvdlinde merged commit d7b2616 into development Aug 12, 2026
32 checks passed
@rubenvdlinde
rubenvdlinde deleted the fix/oc-1190-sync-rejects-login-page branch August 12, 2026 08:38
@github-actions

Copy link
Copy Markdown
Contributor

Quality Report — ConductionNL/openconnector @ a4a8589

Check PHP Vue Security License Tests
lint ✅
phpcs ✅
phpmd ✅
psalm ✅
phpstan ✅
phpmetrics ✅
eslint ✅
stylelint ✅
build ✅
build ✅
check-specs ✅
test-l10n ✅
composer ✅ ✅ 152/152
npm ✅ ✅ 551/551
PHPUnit ✅
Newman ✅
Playwright ✅
Hydra gates ✅

Quality workflow — 2026-08-12 08:40 UTC

Download the full PDF report from the workflow artifacts.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant