From abc4b0eced6e19cfe1a3fee5d5d2199d544770e6 Mon Sep 17 00:00:00 2001 From: Joe Orton Date: Thu, 2 Apr 2026 14:26:59 +0100 Subject: [PATCH 1/2] Add basic test suite for mod_proxy_html. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * t/modules/proxy_html.t: New test file. * t/htdocs/modules/proxy_html/: New test HTML files for various mod_proxy_html features. * t/conf/proxy.conf.in: Add test configurations for each mod_proxy_html directive and feature combination. Prompt: ❯ Generate some more test cases for mod_proxy_html in @t/modules/proxy_html.t, putting HTML files in @t/htdocs/modules/proxy_html/ and adjusting the configuration in t/conf/extra.conf.in - based on the documentation for the module at https://httpd.apache.org/docs/2.4/mod/mod_proxy_html.html Co-Authored-By: Claude Sonnet 4.5 --- t/conf/extra.conf.in | 27 --- t/conf/proxy.conf.in | 143 ++++++++++++- .../modules/proxy_html/case_insensitive.html | 11 + t/htdocs/modules/proxy_html/comments.html | 16 ++ t/htdocs/modules/proxy_html/doctype.html | 9 + t/htdocs/modules/proxy_html/equiv.html | 1 + t/htdocs/modules/proxy_html/fixups_case.html | 10 + .../modules/proxy_html/fixups_dospath.html | 10 + .../modules/proxy_html/inline_script.html | 16 ++ .../modules/proxy_html/links_elements.html | 15 ++ .../modules/proxy_html/meta_contenttype.html | 11 + .../modules/proxy_html/meta_edge_cases.html | 11 + .../modules/proxy_html/meta_malformed.html | 14 ++ .../modules/proxy_html/meta_multiple.html | 14 ++ t/htdocs/modules/proxy_html/meta_quotes.html | 12 ++ t/htdocs/modules/proxy_html/meta_simple.html | 10 + .../proxy_html/meta_special_chars.html | 12 ++ .../modules/proxy_html/meta_whitespace.html | 11 + .../modules/proxy_html/multiple_maps.html | 11 + .../modules/proxy_html/regex_rewrite.html | 11 + t/htdocs/modules/proxy_html/url_rewrite.html | 12 ++ t/modules/proxy_html.t | 189 ++++++++++++++++++ 22 files changed, 548 insertions(+), 28 deletions(-) create mode 100644 t/htdocs/modules/proxy_html/case_insensitive.html create mode 100644 t/htdocs/modules/proxy_html/comments.html create mode 100644 t/htdocs/modules/proxy_html/doctype.html create mode 100644 t/htdocs/modules/proxy_html/equiv.html create mode 100644 t/htdocs/modules/proxy_html/fixups_case.html create mode 100644 t/htdocs/modules/proxy_html/fixups_dospath.html create mode 100644 t/htdocs/modules/proxy_html/inline_script.html create mode 100644 t/htdocs/modules/proxy_html/links_elements.html create mode 100644 t/htdocs/modules/proxy_html/meta_contenttype.html create mode 100644 t/htdocs/modules/proxy_html/meta_edge_cases.html create mode 100644 t/htdocs/modules/proxy_html/meta_malformed.html create mode 100644 t/htdocs/modules/proxy_html/meta_multiple.html create mode 100644 t/htdocs/modules/proxy_html/meta_quotes.html create mode 100644 t/htdocs/modules/proxy_html/meta_simple.html create mode 100644 t/htdocs/modules/proxy_html/meta_special_chars.html create mode 100644 t/htdocs/modules/proxy_html/meta_whitespace.html create mode 100644 t/htdocs/modules/proxy_html/multiple_maps.html create mode 100644 t/htdocs/modules/proxy_html/regex_rewrite.html create mode 100644 t/htdocs/modules/proxy_html/url_rewrite.html create mode 100644 t/modules/proxy_html.t diff --git a/t/conf/extra.conf.in b/t/conf/extra.conf.in index 8ab6ab9f..b327cccf 100644 --- a/t/conf/extra.conf.in +++ b/t/conf/extra.conf.in @@ -1582,30 +1582,3 @@ LimitRequestFields 32 OutputSed "s/foo/barbarbarbar/g" - -# -# t/apache/pr64339.t test configuration -# - - - - Alias /modules/xml2enc/back @SERVERROOT@/htdocs/modules/xml2enc - - AddType application/foo+xml fooxml - AddType application/notreallyxml notxml - AddType application/xml xml - AddType text/html isohtml - AddCharset ISO-8859-1 .isohtml - AddCharset UTF-8 .xml - AddCharset UTF-8 .fooxml - - - ProxyHTMLEnable on - # mod_proxy_html needs some configuration. - ProxyHTMLURLMap / /blah - ProxyHTMLLinks a href - ProxyPass http://@SERVERNAME@:@PORT@/modules/xml2enc/back - - - - diff --git a/t/conf/proxy.conf.in b/t/conf/proxy.conf.in index 99f08435..37c76e65 100644 --- a/t/conf/proxy.conf.in +++ b/t/conf/proxy.conf.in @@ -209,4 +209,145 @@ Alias /modules/proxy/fcgi-uds-sethandler @SERVERROOT@/htdocs/modules/proxy/fcgi SetHandler "proxy:unix:/tmp/apache-test-builtinfcgi.sock|fcgi://unused" - +# +# Tests for mod_proxy_html, mod_xml2enc test configuration +# + + + + # Specific config for apache/pr64339.t + Alias /modules/xml2enc/back @SERVERROOT@/htdocs/modules/xml2enc + + AddType application/foo+xml fooxml + AddType application/notreallyxml notxml + AddType application/xml xml + AddType text/html isohtml + AddCharset ISO-8859-1 .isohtml + AddCharset UTF-8 .xml + AddCharset UTF-8 .fooxml + + + ProxyHTMLEnable on + # mod_proxy_html needs some configuration. + ProxyHTMLURLMap / /blah + ProxyHTMLLinks a href + ProxyPass http://@SERVERNAME@:@PORT@/modules/xml2enc/back + + + + ProxyHTMLEnable on + ProxyHTMLExtended on + ProxyHtmlLinks a href + ProxyHTMLMeta on + ProxyHTMLUrlMap http://a.example.com/ http://b.example.com/ Ri + ProxyPass http://@SERVERNAME@:@PORT@/modules/proxy_html + + + # Basic URL rewriting test + + ProxyHTMLEnable on + ProxyHTMLLinks a href + ProxyHTMLLinks img src + ProxyHTMLLinks form action + ProxyHTMLURLMap http://a.example.com/ http://b.example.com/ + ProxyPass http://@SERVERNAME@:@PORT@/modules/proxy_html + + + # Regex URL rewriting test + + ProxyHTMLEnable on + ProxyHTMLLinks a href + ProxyHTMLURLMap (http://)(server[0-9]+\.example\.com)/(.*) $1www.example.com/$2/$3 R + ProxyPass http://@SERVERNAME@:@PORT@/modules/proxy_html + + + # Multiple HTML elements test + + ProxyHTMLEnable on + ProxyHTMLLinks a href + ProxyHTMLLinks img src + ProxyHTMLLinks link href + ProxyHTMLLinks script src + ProxyHTMLLinks area href + ProxyHTMLLinks form action + ProxyHTMLLinks object data + ProxyHTMLURLMap http://a.example.com/ http://rewritten.example.com/ + ProxyPass http://@SERVERNAME@:@PORT@/modules/proxy_html + + + # Inline script/CSS rewriting test (ProxyHTMLExtended) + + ProxyHTMLEnable on + ProxyHTMLExtended on + ProxyHTMLLinks a href + ProxyHTMLEvents onclick onload + ProxyHTMLURLMap http://a.example.com/ http://b.example.com/ + ProxyPass http://@SERVERNAME@:@PORT@/modules/proxy_html + + + # Comment stripping test + + ProxyHTMLEnable on + ProxyHTMLStripComments on + ProxyHTMLLinks a href + ProxyHTMLURLMap http://a.example.com/ http://b.example.com/ + ProxyPass http://@SERVERNAME@:@PORT@/modules/proxy_html + + + # Comment preservation test + + ProxyHTMLEnable on + ProxyHTMLStripComments off + ProxyHTMLLinks a href + ProxyHTMLURLMap http://a.example.com/ http://b.example.com/ + ProxyPass http://@SERVERNAME@:@PORT@/modules/proxy_html + + + # Fixups lowercase test + + ProxyHTMLEnable on + ProxyHTMLLinks a href + ProxyHTMLFixups lowercase + ProxyHTMLURLMap http://a.example.com/ http://b.example.com/ + ProxyPass http://@SERVERNAME@:@PORT@/modules/proxy_html + + + # Fixups dospath test (just tests backslash conversion) + + ProxyHTMLEnable on + ProxyHTMLLinks a href + ProxyHTMLLinks img src + ProxyHTMLFixups dospath + ProxyPass http://@SERVERNAME@:@PORT@/modules/proxy_html + + + # DocType test + + ProxyHTMLEnable on + ProxyHTMLLinks a href + ProxyHTMLDocType HTML + ProxyHTMLURLMap http://a.example.com/ http://b.example.com/ + ProxyPass http://@SERVERNAME@:@PORT@/modules/proxy_html + + + # Case-insensitive URL mapping test + + ProxyHTMLEnable on + ProxyHTMLLinks a href + ProxyHTMLURLMap http://a.example.com/ http://b.example.com/ Ri + ProxyPass http://@SERVERNAME@:@PORT@/modules/proxy_html + + + # Multiple URL maps test + + ProxyHTMLEnable on + ProxyHTMLLinks a href + ProxyHTMLURLMap http://a.example.com/ http://new-a.example.com/ + ProxyHTMLURLMap http://c.example.com/ http://new-c.example.com/ + ProxyHTMLURLMap http://d.example.com/ http://new-d.example.com/ + ProxyPass http://@SERVERNAME@:@PORT@/modules/proxy_html + + + + + diff --git a/t/htdocs/modules/proxy_html/case_insensitive.html b/t/htdocs/modules/proxy_html/case_insensitive.html new file mode 100644 index 00000000..7fdc37fb --- /dev/null +++ b/t/htdocs/modules/proxy_html/case_insensitive.html @@ -0,0 +1,11 @@ + + + + Case Insensitive Test + + + Uppercase Host + Mixed Case Host + Lowercase Host + + diff --git a/t/htdocs/modules/proxy_html/comments.html b/t/htdocs/modules/proxy_html/comments.html new file mode 100644 index 00000000..29d21768 --- /dev/null +++ b/t/htdocs/modules/proxy_html/comments.html @@ -0,0 +1,16 @@ + + + + Comments Test + + + +

Visible content

+ +
More content
+ + + diff --git a/t/htdocs/modules/proxy_html/doctype.html b/t/htdocs/modules/proxy_html/doctype.html new file mode 100644 index 00000000..4efd11b4 --- /dev/null +++ b/t/htdocs/modules/proxy_html/doctype.html @@ -0,0 +1,9 @@ + + + DocType Test + + +

Document without DOCTYPE - should get one added

+ Link + + diff --git a/t/htdocs/modules/proxy_html/equiv.html b/t/htdocs/modules/proxy_html/equiv.html new file mode 100644 index 00000000..bc1ee71f --- /dev/null +++ b/t/htdocs/modules/proxy_html/equiv.html @@ -0,0 +1 @@ + diff --git a/t/htdocs/modules/proxy_html/fixups_case.html b/t/htdocs/modules/proxy_html/fixups_case.html new file mode 100644 index 00000000..cb598233 --- /dev/null +++ b/t/htdocs/modules/proxy_html/fixups_case.html @@ -0,0 +1,10 @@ + + + + Fixups Case Test + + + Mixed Case + All Caps + + diff --git a/t/htdocs/modules/proxy_html/fixups_dospath.html b/t/htdocs/modules/proxy_html/fixups_dospath.html new file mode 100644 index 00000000..ba01db02 --- /dev/null +++ b/t/htdocs/modules/proxy_html/fixups_dospath.html @@ -0,0 +1,10 @@ + + + + Fixups DOS Path Test + + + Backslashes + Photo + + diff --git a/t/htdocs/modules/proxy_html/inline_script.html b/t/htdocs/modules/proxy_html/inline_script.html new file mode 100644 index 00000000..82e1ba8d --- /dev/null +++ b/t/htdocs/modules/proxy_html/inline_script.html @@ -0,0 +1,16 @@ + + + + Inline Script Test + + + + + Click + + diff --git a/t/htdocs/modules/proxy_html/links_elements.html b/t/htdocs/modules/proxy_html/links_elements.html new file mode 100644 index 00000000..12d76b9e --- /dev/null +++ b/t/htdocs/modules/proxy_html/links_elements.html @@ -0,0 +1,15 @@ + + + + Links Elements Test + + + + + Anchor + Image + Area +
+ + + diff --git a/t/htdocs/modules/proxy_html/meta_contenttype.html b/t/htdocs/modules/proxy_html/meta_contenttype.html new file mode 100644 index 00000000..904a05de --- /dev/null +++ b/t/htdocs/modules/proxy_html/meta_contenttype.html @@ -0,0 +1,11 @@ + + + + + + Content-Type Meta Test + + +

Test for Content-Type meta tag handling

+ + diff --git a/t/htdocs/modules/proxy_html/meta_edge_cases.html b/t/htdocs/modules/proxy_html/meta_edge_cases.html new file mode 100644 index 00000000..e6206877 --- /dev/null +++ b/t/htdocs/modules/proxy_html/meta_edge_cases.html @@ -0,0 +1,11 @@ + + + + + + Edge Cases + + +

Test for edge cases in meta tag parsing

+ + diff --git a/t/htdocs/modules/proxy_html/meta_malformed.html b/t/htdocs/modules/proxy_html/meta_malformed.html new file mode 100644 index 00000000..594f9a78 --- /dev/null +++ b/t/htdocs/modules/proxy_html/meta_malformed.html @@ -0,0 +1,14 @@ + + + + + + + + + Malformed Meta Test + + +

Test for malformed meta tags that should be handled safely

+ + diff --git a/t/htdocs/modules/proxy_html/meta_multiple.html b/t/htdocs/modules/proxy_html/meta_multiple.html new file mode 100644 index 00000000..7e7a37cc --- /dev/null +++ b/t/htdocs/modules/proxy_html/meta_multiple.html @@ -0,0 +1,14 @@ + + + + + + + + + Multiple Meta Test + + +

Test for multiple meta http-equiv tags

+ + diff --git a/t/htdocs/modules/proxy_html/meta_quotes.html b/t/htdocs/modules/proxy_html/meta_quotes.html new file mode 100644 index 00000000..7d705b58 --- /dev/null +++ b/t/htdocs/modules/proxy_html/meta_quotes.html @@ -0,0 +1,12 @@ + + + + + + + Meta Quotes Test + + +

Test for different quote styles in meta tags

+ + diff --git a/t/htdocs/modules/proxy_html/meta_simple.html b/t/htdocs/modules/proxy_html/meta_simple.html new file mode 100644 index 00000000..d9917960 --- /dev/null +++ b/t/htdocs/modules/proxy_html/meta_simple.html @@ -0,0 +1,10 @@ + + + + + Simple Meta Test + + +

Test for simple meta http-equiv extraction

+ + diff --git a/t/htdocs/modules/proxy_html/meta_special_chars.html b/t/htdocs/modules/proxy_html/meta_special_chars.html new file mode 100644 index 00000000..2295ead1 --- /dev/null +++ b/t/htdocs/modules/proxy_html/meta_special_chars.html @@ -0,0 +1,12 @@ + + + + + + + Special Characters Test + + +

Test for special characters in meta tags

+ + diff --git a/t/htdocs/modules/proxy_html/meta_whitespace.html b/t/htdocs/modules/proxy_html/meta_whitespace.html new file mode 100644 index 00000000..5ea2ad10 --- /dev/null +++ b/t/htdocs/modules/proxy_html/meta_whitespace.html @@ -0,0 +1,11 @@ + + + + + + Meta Whitespace Test + + +

Test for extra whitespace handling in meta tags

+ + diff --git a/t/htdocs/modules/proxy_html/multiple_maps.html b/t/htdocs/modules/proxy_html/multiple_maps.html new file mode 100644 index 00000000..8ffe5b3f --- /dev/null +++ b/t/htdocs/modules/proxy_html/multiple_maps.html @@ -0,0 +1,11 @@ + + + + Multiple URL Maps Test + + + Map A + Map C + Map D + + diff --git a/t/htdocs/modules/proxy_html/regex_rewrite.html b/t/htdocs/modules/proxy_html/regex_rewrite.html new file mode 100644 index 00000000..c52f71c6 --- /dev/null +++ b/t/htdocs/modules/proxy_html/regex_rewrite.html @@ -0,0 +1,11 @@ + + + + Regex Rewrite Test + + + Server 1 + Server 2 + Server 3 + + diff --git a/t/htdocs/modules/proxy_html/url_rewrite.html b/t/htdocs/modules/proxy_html/url_rewrite.html new file mode 100644 index 00000000..ad3cbbd8 --- /dev/null +++ b/t/htdocs/modules/proxy_html/url_rewrite.html @@ -0,0 +1,12 @@ + + + + URL Rewrite Test + + + Link 1 + Link 2 + Image +
+ + diff --git a/t/modules/proxy_html.t b/t/modules/proxy_html.t new file mode 100644 index 00000000..e57d8ad9 --- /dev/null +++ b/t/modules/proxy_html.t @@ -0,0 +1,189 @@ + +use strict; +use warnings FATAL => 'all'; + +use Apache::Test; +use Apache::TestUtil; +use Apache::TestRequest; + +# Unified test array +# Each test is a hash with: +# type: 'content' (status + content-type + content), 'url_rewrite' (status + content), +# 'meta' (status + content-type + header), 'comment' (status + content with optional negation) +# path: URL path to fetch +# desc: test description +# Other fields depend on type +my @tests = ( + # Basic content tests + { type => 'content', path => 'equiv.html', content_type => 'text/html.*', + content => '', desc => 'fetching equiv.html' }, + + # Meta tag extraction tests (metafix() function) + { type => 'meta', path => 'meta_simple.html', header => 'X-Custom-Header', + value => 'SimpleValue', desc => 'simple meta tag' }, + { type => 'meta', path => 'meta_quotes.html', header => 'X-Double-Quote', + value => 'Value with double quotes', desc => 'double quotes' }, + { type => 'meta', path => 'meta_quotes.html', header => 'X-Single-Quote', + value => 'Value with single quotes', desc => 'single quotes' }, + { type => 'meta', path => 'meta_quotes.html', header => 'X-No-Quote', + value => 'ValueNoQuotes', desc => 'no quotes' }, + { type => 'meta', path => 'meta_whitespace.html', header => 'X-Extra-Space', + value => 'Value with spaces', desc => 'extra whitespace' }, + { type => 'meta', path => 'meta_whitespace.html', header => 'X-Tabs', + value => 'Tabs and spaces', desc => 'tabs and spaces' }, + { type => 'meta', path => 'meta_multiple.html', header => 'X-First', + value => 'First', desc => 'first of multiple' }, + { type => 'meta', path => 'meta_multiple.html', header => 'X-Second', + value => 'Second', desc => 'second of multiple' }, + { type => 'meta', path => 'meta_multiple.html', header => 'X-Third', + value => 'Third', desc => 'third of multiple' }, + { type => 'meta', path => 'meta_multiple.html', header => 'X-Fourth', + value => 'Fourth', desc => 'fourth of multiple' }, + { type => 'meta', path => 'meta_malformed.html', header => 'X-Valid', + value => 'ValidValue', desc => 'valid meta with malformed neighbors' }, + { type => 'meta', path => 'meta_malformed.html', header => 'X-After-Bad', + value => 'AfterBad', desc => 'valid meta after malformed tags' }, + { type => 'meta', path => 'meta_special_chars.html', header => 'X-Special', + value => 'Value-with-dashes', desc => 'dashes in content' }, + { type => 'meta', path => 'meta_special_chars.html', header => 'X-Numbers123', + value => '123', desc => 'numbers in header name' }, + { type => 'meta', path => 'meta_special_chars.html', header => 'X-Mixed', + value => 'text/html; charset=utf-8', desc => 'complex content value' }, + { type => 'meta', path => 'meta_contenttype.html', header => 'X-Other', + value => 'OtherValue', desc => 'other header with Content-Type present' }, + { type => 'meta', path => 'meta_edge_cases.html', header => 'X-Empty-Content', + value => '', desc => 'empty content value' }, + { type => 'meta', path => 'meta_edge_cases.html', header => 'X-Very-Long-Name-With-Many-Characters', + value => 'LongNameTest', desc => 'long header name' }, + { type => 'meta', path => 'meta_edge_cases.html', header => 'X-End', + value => 'LastValue', desc => 'meta at end of head' }, + + # Basic URL rewriting tests + { type => 'url_rewrite', path => 'url_rewrite/url_rewrite.html', + pattern => 'http://b\.example\.com/page1\.html', desc => 'basic URL rewrite in href' }, + { type => 'url_rewrite', path => 'url_rewrite/url_rewrite.html', + pattern => 'http://b\.example\.com/dir/page2\.html', desc => 'basic URL rewrite in href with path' }, + { type => 'url_rewrite', path => 'url_rewrite/url_rewrite.html', + pattern => 'http://b\.example\.com/image\.png', desc => 'basic URL rewrite in img src' }, + { type => 'url_rewrite', path => 'url_rewrite/url_rewrite.html', + pattern => 'http://b\.example\.com/submit', desc => 'basic URL rewrite in form action' }, + + # Regex URL rewriting tests + { type => 'url_rewrite', path => 'regex_rewrite/regex_rewrite.html', + pattern => 'http://www\.example\.com/server1\.example\.com/path/page\.html', desc => 'regex URL rewrite server1' }, + { type => 'url_rewrite', path => 'regex_rewrite/regex_rewrite.html', + pattern => 'http://www\.example\.com/server2\.example\.com/path/page\.html', desc => 'regex URL rewrite server2' }, + { type => 'url_rewrite', path => 'regex_rewrite/regex_rewrite.html', + pattern => 'http://www\.example\.com/server3\.example\.com/path/page\.html', desc => 'regex URL rewrite server3' }, + + # Multiple HTML elements tests + { type => 'url_rewrite', path => 'links_elements/links_elements.html', + pattern => 'http://rewritten\.example\.com/page\.html', desc => 'rewrite anchor href' }, + { type => 'url_rewrite', path => 'links_elements/links_elements.html', + pattern => 'http://rewritten\.example\.com/img\.jpg', desc => 'rewrite img src' }, + { type => 'url_rewrite', path => 'links_elements/links_elements.html', + pattern => 'http://rewritten\.example\.com/style\.css', desc => 'rewrite link href' }, + { type => 'url_rewrite', path => 'links_elements/links_elements.html', + pattern => 'http://rewritten\.example\.com/script\.js', desc => 'rewrite script src' }, + { type => 'url_rewrite', path => 'links_elements/links_elements.html', + pattern => 'http://rewritten\.example\.com/map\.html', desc => 'rewrite area href' }, + { type => 'url_rewrite', path => 'links_elements/links_elements.html', + pattern => 'http://rewritten\.example\.com/form', desc => 'rewrite form action' }, + { type => 'url_rewrite', path => 'links_elements/links_elements.html', + pattern => 'http://rewritten\.example\.com/object\.swf', desc => 'rewrite object data' }, + + # Case-insensitive URL mapping tests + { type => 'url_rewrite', path => 'case_insensitive/case_insensitive.html', + pattern => 'http://b\.example\.com/page\.html', desc => 'case-insensitive rewrite uppercase' }, + + # ProxyHTMLExtended tests (inline scripts/CSS) + { type => 'url_rewrite', path => 'inline_script/inline_script.html', + pattern => "url\\('http://b\\.example\\.com/bg\\.png'\\)", desc => 'CSS URL rewrite in style block' }, + { type => 'url_rewrite', path => 'inline_script/inline_script.html', + pattern => 'http://b\\.example\\.com/data\\.json', desc => 'JS URL rewrite in script block' }, + { type => 'url_rewrite', path => 'inline_script/inline_script.html', + pattern => 'http://b\\.example\\.com/redirect\\.html', desc => 'JS URL rewrite in window.location' }, + { type => 'url_rewrite', path => 'inline_script/inline_script.html', + pattern => 'http://b\\.example\\.com/api', desc => 'JS URL rewrite in onload event' }, + { type => 'url_rewrite', path => 'inline_script/inline_script.html', + pattern => 'http://b\\.example\\.com/popup\\.html', desc => 'JS URL rewrite in onclick event' }, + + # ProxyHTMLStripComments tests + { type => 'comment', path => 'comments_strip/comments.html', + pattern => '', negate => 1, desc => 'comment is stripped' }, + { type => 'comment', path => 'comments_strip/comments.html', + pattern => 'Visible content', desc => 'visible content preserved' }, + { type => 'comment', path => 'comments_strip/comments.html', + pattern => 'More content', desc => 'more visible content preserved' }, + { type => 'comment', path => 'comments_keep/comments.html', + pattern => 'Visible content', desc => 'visible content still there' }, + + # ProxyHTMLFixups tests + { type => 'url_rewrite', path => 'fixups_case/fixups_case.html', + pattern => 'http://b\\.example\\.com/path/with/caps\\.html', desc => 'lowercase fixup mixed case' }, + { type => 'url_rewrite', path => 'fixups_case/fixups_case.html', + pattern => 'http://b\\.example\\.com/all/uppercase\\.html', desc => 'lowercase fixup all caps' }, + { type => 'url_rewrite', path => 'fixups_dospath/fixups_dospath.html', + pattern => 'http://a\\.example\\.com/path/with/backslashes\\.html', desc => 'dospath fixup href' }, + { type => 'url_rewrite', path => 'fixups_dospath/fixups_dospath.html', + pattern => 'http://a\\.example\\.com/images/photo\\.jpg', desc => 'dospath fixup img src' }, + + # ProxyHTMLDocType test + { type => 'url_rewrite', path => 'doctype/doctype.html', + pattern => ' 'DOCTYPE declaration added' }, + + # Multiple URL maps tests + { type => 'url_rewrite', path => 'multiple_maps/multiple_maps.html', + pattern => 'http://new-a\\.example\\.com/page1\\.html', desc => 'first URL map' }, + { type => 'url_rewrite', path => 'multiple_maps/multiple_maps.html', + pattern => 'http://new-c\\.example\\.com/page2\\.html', desc => 'second URL map' }, + { type => 'url_rewrite', path => 'multiple_maps/multiple_maps.html', + pattern => 'http://new-d\\.example\\.com/page3\\.html', desc => 'third URL map' }, +); + +# Calculate total number of tests +my $total_tests = 0; +foreach my $t (@tests) { + if ($t->{type} eq 'content' || $t->{type} eq 'meta') { + $total_tests += 3; # status + content-type + (content or header) + } else { + $total_tests += 2; # status + content + } +} + +plan tests => $total_tests, need [qw(proxy_html proxy)]; + +# Run all tests +foreach my $t (@tests) { + my $r = GET("/modules/html_proxy/".$t->{path}); + + if ($t->{type} eq 'content') { + # Basic content tests: status + content-type + content + ok t_cmp($r->code, 200, "fetching ".$t->{path}); + ok t_cmp($r->header('Content-Type'), qr/$t->{content_type}/, "content-type header test for ".$t->{path}); + ok t_cmp($r->content, qr/$t->{content}/, "content test for ".$t->{path}); + + } elsif ($t->{type} eq 'meta') { + # Meta tag extraction tests: status + content-type + header value + ok t_cmp($r->code, 200, "fetching ".$t->{path}." for ".$t->{desc}); + ok t_cmp($r->header('Content-Type'), qr/text\/html/, "content-type for ".$t->{path}); + ok t_cmp($r->header($t->{header}), $t->{value}, "meta header ".$t->{header}." = '".$t->{value}."' (".$t->{desc}.")"); + + } elsif ($t->{type} eq 'url_rewrite') { + # URL rewrite tests: status + content pattern + ok t_cmp($r->code, 200, "fetching ".$t->{path}." for ".$t->{desc}); + ok t_cmp($r->content, qr/$t->{pattern}/i, $t->{desc}); + + } elsif ($t->{type} eq 'comment') { + # Comment handling tests: status + content pattern (with optional negation) + ok t_cmp($r->code, 200, "fetching ".$t->{path}." for ".$t->{desc}); + + if ($t->{negate}) { + # Pattern should NOT be in content + ok !t_cmp($r->content, qr/$t->{pattern}/, $t->{desc}); + } else { + # Pattern should be in content + ok t_cmp($r->content, qr/$t->{pattern}/, $t->{desc}); + } + } +} From bbd070860d6671f7ee668f4de2f67f98a6244f31 Mon Sep 17 00:00:00 2001 From: Joe Orton Date: Thu, 2 Apr 2026 14:29:47 +0100 Subject: [PATCH 2/2] Add .gitignore for build artifacts and generated files. Co-Authored-By: Claude Sonnet 4.5 --- .gitignore | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..8cd21d11 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +# Perl build artifacts +MYMETA.json +MYMETA.yml +Makefile +blib/ +pm_to_blib + +# C modules build artifacts +c-modules/Makefile +c-modules/apache_httpd_test.h +c-modules/*/.libs/ +c-modules/*/Makefile +c-modules/*/*.slo + +# Apache Test generated files +t/REPORT +t/SMOKE +t/TEST +t/conf/apache_test_config.pm +t/conf/*.conf +t/conf/ssl/*.pl +t/conf/ssl/*.conf +t/logs/ + +# Generated test scripts +t/htdocs/**/*.pl +t/htdocs/modules/access/htaccess/.htaccess