From eead3551792ff62d03633f55618347807147dfcf Mon Sep 17 00:00:00 2001 From: Jeff Thompson Date: Wed, 15 Jan 2020 11:15:45 -0700 Subject: [PATCH] Add a couple more tests and some comments about the error source. --- .../StackTraceSuppressionFilterTest.java | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/test/src/test/java/jenkins/security/StackTraceSuppressionFilterTest.java b/test/src/test/java/jenkins/security/StackTraceSuppressionFilterTest.java index 04a3029a02..d44a13f5f9 100644 --- a/test/src/test/java/jenkins/security/StackTraceSuppressionFilterTest.java +++ b/test/src/test/java/jenkins/security/StackTraceSuppressionFilterTest.java @@ -70,7 +70,9 @@ public class StackTraceSuppressionFilterTest { // @Test // public void nonexistentAdjunct() throws Exception { -// // This test belongs in Stapler but it's easy to put it together here. +// /* This test belongs in Stapler but it's easy to put it together here. +// This test is based upon Stapler throwing an exception for this broken request. +// If Stapler is improved to better handle this error, this test may erroneously fail. */ // JenkinsRule.WebClient wc = j.createWebClient(); // // wc.setThrowExceptionOnFailingStatusCode(false); @@ -83,7 +85,9 @@ public class StackTraceSuppressionFilterTest { // // @Test // public void nonexistentAdjunctShowsTrace() throws Exception { -// // This test belongs in Stapler but it's easy to put it together here. +// /* This test belongs in Stapler but it's easy to put it together here. +// This test is based upon Stapler throwing an exception for this broken request. +// If Stapler is improved to better handle this error, this test may erroneously fail. */ // JenkinsRule.WebClient wc = j.createWebClient(); // HttpResponses.SHOW_STACK_TRACE = true; // @@ -97,6 +101,9 @@ public class StackTraceSuppressionFilterTest { @Test public void exception() throws Exception { + /* This test is based upon an incomplete / incorrect project implementation + throwing an uncaught exception. + If Jenkins is improved to better handle this error, this test may erroneously fail. */ FreeStyleProject projectError = createBrokenProject(); JenkinsRule.WebClient wc = j.createWebClient(); @@ -110,6 +117,9 @@ public class StackTraceSuppressionFilterTest { @Test public void exceptionShowsTrace() throws Exception { + /* This test is based upon an incomplete / incorrect project implementation + throwing an uncaught exception. + If Jenkins is improved to better handle this error, this test may erroneously fail. */ FreeStyleProject projectError = createBrokenProject(); StackTraceSuppressionFilter.SHOW_STACK_TRACE = true; @@ -122,6 +132,33 @@ public class StackTraceSuppressionFilterTest { assertThat(content, not(containsString("An error occurred processing your request. Ask your Jenkins administrator to look up details."))); } + @Test + public void exceptionEndpoint() throws Exception { + /* This test is based upon a testing endpoint that really shouldn't exist in production code. + If Jenkins is improved to eliminate this endpoint, this test may erroneously fail. */ + JenkinsRule.WebClient wc = j.createWebClient(); + wc.setThrowExceptionOnFailingStatusCode(false); + HtmlPage page = wc.goTo("exception"); + + String content = page.getWebResponse().getContentAsString(); + assertThat(content, containsString("An error occurred processing your request. Ask your Jenkins administrator to look up details.")); + assertThat(content, not(containsString("Oops!"))); + } + + @Test + public void exceptionEndpointShowsTrace() throws Exception { + /* This test is based upon a testing endpoint that really shouldn't exist in production code. + If Jenkins is improved to eliminate this endpoint, this test may erroneously fail. */ + StackTraceSuppressionFilter.SHOW_STACK_TRACE = true; + JenkinsRule.WebClient wc = j.createWebClient(); + wc.setThrowExceptionOnFailingStatusCode(false); + HtmlPage page = wc.goTo("exception"); + + String content = page.getWebResponse().getContentAsString(); + assertThat(content, containsString("Oops!")); + assertThat(content, not(containsString("An error occurred processing your request. Ask your Jenkins administrator to look up details."))); + } + private FreeStyleProject createBrokenProject() throws IOException { TopLevelItemDescriptor descriptor = new TopLevelItemDescriptor(FreeStyleProject.class) { @Override