Search in sources :

Example 6 with ContentFilter

use of com.cloudbees.jenkins.support.filter.ContentFilter in project support-core-plugin by jenkinsci.

the class FileDescriptorLimitTest method addContentsFiltered.

@Test
public void addContentsFiltered() throws Exception {
    Assume.assumeTrue(!Functions.isWindows());
    Assume.assumeTrue(SystemPlatform.LINUX == SystemPlatform.current());
    ContentFilters.get().setEnabled(true);
    ContentMapping mapping = ContentMapping.of(SENSITIVE_WORD, FILTERED_SENSITIVE_WORD);
    ContentMappings.get().getMappingOrCreate(mapping.getOriginal(), original -> mapping);
    ContentFilter filter = SupportPlugin.getContentFilter().orElseThrow(AssertionFailedError::new);
    FreeStyleProject p = j.createFreeStyleProject(SENSITIVE_JOB_NAME);
    String output;
    // Hold an open File Descriptor
    try (FileInputStream ignored = new FileInputStream(p.getConfigFile().getFile())) {
        output = SupportTestUtils.invokeComponentToString(new FileDescriptorLimit(), filter);
    }
    MatcherAssert.assertThat(output, containsString("core file size"));
    MatcherAssert.assertThat(output, containsString("Open File Descriptor Count:"));
    MatcherAssert.assertThat(output, containsString("All open files\n=============="));
    MatcherAssert.assertThat(output, not(containsString(SENSITIVE_JOB_NAME)));
    MatcherAssert.assertThat(output, containsString(FILTERED_JOB_NAME));
}
Also used : ContentMapping(com.cloudbees.jenkins.support.filter.ContentMapping) Matchers.containsString(org.hamcrest.Matchers.containsString) AssertionFailedError(junit.framework.AssertionFailedError) FreeStyleProject(hudson.model.FreeStyleProject) ContentFilter(com.cloudbees.jenkins.support.filter.ContentFilter) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

ContentFilter (com.cloudbees.jenkins.support.filter.ContentFilter)6 PrintWriter (java.io.PrintWriter)4 ContentMapping (com.cloudbees.jenkins.support.filter.ContentMapping)2 FreeStyleProject (hudson.model.FreeStyleProject)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 ThreadInfo (java.lang.management.ThreadInfo)2 Date (java.util.Date)2 Jenkins (jenkins.model.Jenkins)2 AssertionFailedError (junit.framework.AssertionFailedError)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Test (org.junit.Test)2 SupportPlugin (com.cloudbees.jenkins.support.SupportPlugin)1 Content (com.cloudbees.jenkins.support.api.Content)1 PrefilteredPrintedContent (com.cloudbees.jenkins.support.api.PrefilteredPrintedContent)1 UnfilteredStringContent (com.cloudbees.jenkins.support.api.UnfilteredStringContent)1 FilteredOutputStream (com.cloudbees.jenkins.support.filter.FilteredOutputStream)1 PrefilteredContent (com.cloudbees.jenkins.support.filter.PrefilteredContent)1 FileListCap (com.cloudbees.jenkins.support.timer.FileListCap)1