diff --git a/hydra-gates/scripts/lib/php_template_scope.py b/hydra-gates/scripts/lib/php_template_scope.py new file mode 100644 index 000000000..607283d22 --- /dev/null +++ b/hydra-gates/scripts/lib/php_template_scope.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: EUPL-1.2 +"""Does a Nextcloud PHP template OWN THE DOCUMENT, or is it a fragment? + +WHY THIS EXISTS +--------------- +Nextcloud's `OCP\\Template` renderer SUBSTITUTES an app template into core's +own page. A template that emits no `` / `
` is a fragment inside a +document core already built — core emitted that page's landmarks, its `lang` +attribute and its skip link long before the template's first byte. + +gate-38 was asking every `templates/settings/*.php` in the fleet for a skip +link. Measured: NOT ONE of the 30 app templates in this fleet owns a document +— the typical body is literally ``, a Vue +mount point — so the finding was universal and its only remedy was to inject +a SECOND "skip to content" anchor ahead of core's real one. A WCAG 2.4.1 +regression demanded by a WCAG 2.4.1 gate (#214, #216, #227). + +WHY A HELPER AND NOT A GREP +--------------------------- +The first cut of this check was `grep -iE '<(html|body)\\b'`, and the very +first fixture it ran against defeated it: the fixture's own explanatory +comment contained the words ``, so a bare mount point was classified as +a page root. That is the gate-64 defect verbatim — a checker that greps a +string literal misses every constant and matches every comment, failing both +ways at once — so the classification is done on EMITTED MARKUP only: + + * `` regions are removed. Anything inside them is code, a + docblock or a `//` comment; none of it is markup the browser receives. + * `` HTML comments are removed. Commented-out markup ships + nothing. + +Usage: + php_template_scope.py --owns-documenthi
\n')) + + def test_markup_after_a_closed_php_block_is_still_seen(self): + # The PHP-stripper must not eat the rest of the file. A `?>` closes + # exactly one block. + self.assertTrue(pts.owns_document( + "\nhi\n")) + + def test_html_between_two_php_blocks(self): + self.assertTrue(pts.owns_document( + "\n\n\n" + "hi\n")) + + def test_uppercase_tags(self): + self.assertTrue(pts.owns_document('hi')) + + def test_a_real_comment_next_to_a_real_document(self): + # Stripping comments must not strip the document with them. + self.assertTrue(pts.owns_document( + '\n' + 'hi
\n')) + + +class UnterminatedPhp(unittest.TestCase): + def test_an_unclosed_php_opener_swallows_the_rest(self): + # PHP's own rule, and the common shape of a pure-logic template. + self.assertFalse(pts.owns_document(" mentioned here\n$x = 1;\n")) + + +class Cli(unittest.TestCase): + """The bash caller keys on the EXIT STATUS, so the status is a contract. + + Gate-19 returned a finding COUNT as an exit status and lost 256 findings + to a byte; an exit status this gate reads must be tested as an interface, + not assumed. + """ + + def _write(self, tmp, name, content): + p = os.path.join(tmp, name) + with open(p, 'w', encoding='utf-8') as f: + f.write(content) + return p + + def test_exit_codes(self): + import tempfile + with tempfile.TemporaryDirectory() as tmp: + root = self._write(tmp, 'root.php', 'hi') + frag = self._write(tmp, 'frag.php', '') + self.assertEqual(pts.main(['x', '--owns-document', root]), 0) + self.assertEqual(pts.main(['x', '--owns-document', frag]), 1) + # A file that cannot be read is NOT silently "fragment" — that + # would drop it from scope and read as a pass. + self.assertEqual( + pts.main(['x', '--owns-document', os.path.join(tmp, 'nope.php')]), 2) + + +if __name__ == '__main__': + unittest.main(verbosity=2) diff --git a/hydra-gates/scripts/run-hydra-gates.sh b/hydra-gates/scripts/run-hydra-gates.sh index e30abd570..10bc6bd41 100755 --- a/hydra-gates/scripts/run-hydra-gates.sh +++ b/hydra-gates/scripts/run-hydra-gates.sh @@ -3472,24 +3472,95 @@ fi # --------------------------------------------------------------------------- -# Gate 38: Skip-link — every app entry-point Vue (App.vue / *Root.vue) or -# admin/settings PHP template must include a skip-to-content affordance, -# either via NC's shell (typically inherited by mounting underConfigure things.
+