diff --git a/htmlSanityCheck-core/src/test/groovy/org/aim42/htmlsanitycheck/check/BrokenHttpLinksCheckerSpec.groovy b/htmlSanityCheck-core/src/test/groovy/org/aim42/htmlsanitycheck/check/BrokenHttpLinksCheckerSpec.groovy index 39c71c79..684e5748 100644 --- a/htmlSanityCheck-core/src/test/groovy/org/aim42/htmlsanitycheck/check/BrokenHttpLinksCheckerSpec.groovy +++ b/htmlSanityCheck-core/src/test/groovy/org/aim42/htmlsanitycheck/check/BrokenHttpLinksCheckerSpec.groovy @@ -7,15 +7,11 @@ import org.aim42.htmlsanitycheck.html.HtmlPage import org.aim42.htmlsanitycheck.test.dns.CustomHostNameResolver import org.wiremock.integrations.testcontainers.WireMockContainer import spock.lang.Ignore -import spock.lang.IgnoreIf import spock.lang.Shared import spock.lang.Specification import spock.lang.Unroll - import java.lang.reflect.Field import java.lang.reflect.Proxy - - // see end-of-file for license information @@ -81,16 +77,6 @@ class BrokenHttpLinksCheckerSpec extends Specification { throw new RuntimeException("Failed to register custom DNS resolver", e); } } - /** - * checking for internet connectivity is a somewhat brittle - as there's no such thing as "the internet" - * (the checker will most likely use google.com as a proxy for "internet" - */ - // todo: test that properly - @IgnoreIf({ !System.getenv('GITHUB_ACTIONS') }) - def "recognize if there is internet connectivity"() { - expect: "if there is no internet connection, testing should fail" - Web.isInternetConnectionAvailable() - } def "empty page has no errors"() { given: "an empty HTML page" @@ -112,7 +98,7 @@ class BrokenHttpLinksCheckerSpec extends Specification { def "one syntactically correct http URL is ok"() { given: "an HTML page with a single correct anchor/link" String HTML = """$HtmlConst.HTML_HEAD - google + google $HtmlConst.HTML_END """ htmlPage = new HtmlPage(HTML) @@ -147,9 +133,9 @@ class BrokenHttpLinksCheckerSpec extends Specification { collector.nrOfProblems() == 0 where: - goodUrl << ["https://junit.org/junit4/javadoc/latest/org/junit/Before.html", - "https://plumelib.org/plume-util/api/org/plumelib/util/DeterministicObject.html", - "https://people.csail.mit.edu/cpacheco/publications/randoop-case-study-abstract.html" + goodUrl << ["http://junit.org:$port/junit4", + "http://plumelib.org:$port/plume-util", + "http://people.csail.mit.edu:$port/cpacheco" ] } @@ -157,7 +143,7 @@ class BrokenHttpLinksCheckerSpec extends Specification { def "single bad link is identified as problem"() { given: "an HTML page with a single (bad) link" - String badhref = "https://arc42.org/ui98jfuhenu87djch" + String badhref = "http://arc42.org:$port/ui98jfuhenu87djch" String HTML = """$HtmlConst.HTML_HEAD nonexisting arc42 link $HtmlConst.HTML_END """ @@ -177,10 +163,10 @@ class BrokenHttpLinksCheckerSpec extends Specification { * where HEAD requests are always answered with 405 instead of 200... */ - //@Ignore("test currently breaks. see issue-219") + def "amazon does not deliver 405 statuscode for links that really exist"() { given: "an HTML page with a single (good) amazon link" - String goodAmazonLink = "https://www.amazon.com/dp/B01A2QL9SS" + String goodAmazonLink = "http://www.amazon.com:$port/dp/B01A2QL9SS" String HTML = """$HtmlConst.HTML_HEAD Amazon $HtmlConst.HTML_END """ @@ -223,7 +209,7 @@ class BrokenHttpLinksCheckerSpec extends Specification { def 'bad link #badLink is recognized as such'() { given: "an HTML page with a single (broken) link" - String goodURL = "https://mock.codes/${badLink}" + String goodURL = "http://mock.codes$port/${badLink}" String HTML = """$HtmlConst.HTML_HEAD ${badLink} $HtmlConst.HTML_END """ diff --git a/htmlSanityCheck-core/src/test/resources/mappings.json b/htmlSanityCheck-core/src/test/resources/mappings.json index 6a6f2e80..eea68ad7 100644 --- a/htmlSanityCheck-core/src/test/resources/mappings.json +++ b/htmlSanityCheck-core/src/test/resources/mappings.json @@ -2,8 +2,20 @@ "mappings" : [ { "request": { - "method": "HEAD", - "urlPattern": "/google" + "method": "GET_OR_HEAD", + "urlPattern": "/(|junit4|plume-util|cpacheco)" + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET", + "urlPattern": "/dp/B01A2QL9SS" }, "response": { "status": 200, @@ -11,6 +23,268 @@ "Content-Type": "text/plain" } } + }, + { + "request": { + "method": "HEAD", + "urlPattern": "/dp/B01A2QL9SS" + }, + "response": { + "status": 405, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/ui98jfuhenu87djch" + }, + "response": { + "status": 400, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/400" + }, + "response": { + "status": 400, + "headers": { + "Content-Type": "text/plain" + } + } + },{ + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "401" + }, + "response": { + "status": 401, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/401" + }, + "response": { + "status": 401, + "headers": { + "Content-Type": "text/plain" + } + } + },{ + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/402" + }, + "response": { + "status": 402, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/403" + }, + "response": { + "status": 403, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/404" + }, + "response": { + "status": 404, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/405" + }, + "response": { + "status": 405, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/406" + }, + "response": { + "status": 406, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/408" + }, + "response": { + "status": 408, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/409" + }, + "response": { + "status": 409, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/410" + }, + "response": { + "status": 410, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/429" + }, + "response": { + "status": 429, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/431" + }, + "response": { + "status": 431, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/500" + }, + "response": { + "status": 500, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/501" + }, + "response": { + "status": 501, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/502" + }, + "response": { + "status": 502, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/504" + }, + "response": { + "status": 504, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/505" + }, + "response": { + "status": 505, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/506" + }, + "response": { + "status": 506, + "headers": { + "Content-Type": "text/plain" + } + } + }, + { + "request": { + "method": "GET_OR_HEAD", + "urlPattern": "/507" + }, + "response": { + "status": 507, + "headers": { + "Content-Type": "text/plain" + } + } } ] } \ No newline at end of file