Commits

Bob Swift committed b8dc7cb

GINT-57: always filter password properties on xmlReport. No longer default report filter to log filter

  • Participants
  • Parent commits 70b1813

Comments (0)

Files changed (3)

File src/itest/groovy/gintTest2.gant

             file: gint.getTestReportsDirectory() + System.properties.'file.separator' + 'good1.xml',
             data: [
                 "failures='0' errors='0' skipped='0' tests='1' name='good1'>",
-                (mailLevel || imLevel) ? ~/(?i).*property name='.*password.*'.*value=.*/ : null,  // should find at least one of these if im or mail is configured
+                (mailLevel || imLevel) ? ~/(?i).*property name='xmlReport.*'.*value=.*/ : null,  // should find at least one of these if im or mail is configured
             ],
         ],
     ],
                 "failures='0' errors='0' skipped='0' tests='1' name='good1'>",
             ],
             failData: [
-                ~/(?i).*property name='.*password.*'.*value=.*/,  // should filter out all properties in the XML report
+                ~/(?i).*property name='.*'.*value=.*/,  // should filter out all properties in the XML report
             ]
         ],
     ],
     [name: 'xmlReportNamed', file: gint.getInputFile('good1.gant'),
         description: 'Check XML report output to correct location and missing password properties.',
-        arguments: "-Dclean -DreportFilter=password -DxmlReport=${gint.getTestReportsDirectory() + System.properties.'file.separator'}xmlReportNamed.xml",
+        arguments: "-Dclean -DreportFilter=xmlReport -DxmlReport=${gint.getTestReportsDirectory() + System.properties.'file.separator'}xmlReportNamed.xml",
         level: mailLevel,  // to find passwords, need configuration for mail
         output: [
             file: gint.getTestReportsDirectory() + System.properties.'file.separator' + 'xmlReportNamed.xml',
                 "failures='0' errors='0' skipped='0' tests='1' name='good1'>",
             ],
             failData: [
-                ~/(?i).*property name='.*password.*'.*value=.*>/,  // see above testcase for opposite check
+                ~/(?i).*property name='xmlReport'.*value=.*>/,  // see above testcase for opposite check
             ],
         ],
     ],
     [name: 'xmlReportFailed', file: gint.getInputFile('stopOnFailOverride.gant'),
-        description: 'Check XML report output shows failed.  Show setting logFilter same as reportFilter',
-        arguments: "-Dclean -DxmlReport -DlogFilter=password",
+        description: 'Check XML report output shows failed.', // now passwords automatically filtered out
+        arguments: "-Dclean -DxmlReport",
         expected: -13,
         output: [
             file: gint.getTestReportsDirectory() + System.properties.'file.separator' + 'stopOnFailOverride.xml',

File src/main/groovy/org/swift/tools/Gint.groovy

     }
 
     /**
-     * Get the report filter if set, otherwise default to the log filter
+     * Get the report filter
      * @return closure to filter out properties in the report
      */
     public Closure getReportFilter() {
-        return this.reportFilter ?: this.helper.getLogFilter()
+        return this.reportFilter
     }
 
     /**
 
                     try {
                         def filter = getReportFilter()
+                        def passwordFilter = helper.getPasswordFilter() // ALWAYS apply the password filter (not optional)
                         binding.ant.project.properties.each { entry ->
-                            if ((filter == null) || !filter(entry.key)) { // exclude some or all properties from the report file
+                            if (((filter == null) || !filter(entry.key)) && !passwordFilter(entry.key)) { // exclude some or all properties from the report file
                                 builder.property(name: entry.key, value: entry.value)
                             }
                         }

File src/main/groovy/org/swift/tools/Helper.groovy

     }
 
     /**
+     * Closure to filter out values containing the word password. Closure returns true if text look like a password
+     * @return closure that looks for passwords
+     */
+    public Closure getPasswordFilter() {
+        return { text ->
+            this.stringContains(text, "password", Pattern.CASE_INSENSITIVE | Pattern.LITERAL)
+        }
+    }
+
+    /**
      * Get the default text field length used for formatted output functions like logWithFormat
      * @return default text field length
      */