]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11371 Change the banner text with rules missing info
authorPascal Mugnier <pascal.mugnier@sonarsource.com>
Mon, 22 Oct 2018 13:45:02 +0000 (15:45 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 25 Oct 2018 18:21:02 +0000 (20:21 +0200)
server/sonar-web/src/main/js/apps/securityReports/components/App.tsx
server/sonar-web/src/main/js/apps/securityReports/components/__tests__/App-test.tsx
server/sonar-web/src/main/js/apps/securityReports/components/__tests__/__snapshots__/App-test.tsx.snap
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 025b661e6499e071209eb8f592ad7cd9c3e58f94..7f7bc9b1790b07a08337d717fec1d490bc9c1455 100755 (executable)
@@ -125,6 +125,44 @@ export default class App extends React.PureComponent<Props, State> {
     this.setState({ showCWE: checked }, this.fetchSecurityHotspots);
   };
 
+  renderAdditionalRulesMessage = () => {
+    const { component } = this.props;
+    const { findings, type } = this.state;
+    if (findings.length === 0) {
+      return null;
+    }
+
+    const total = findings.map(f => f.totalRules).reduce((sum, count) => sum + count);
+    const active = findings.map(f => f.activeRules).reduce((sum, count) => sum + count);
+    if (active === total) {
+      return null;
+    }
+
+    const standard = translate('security_reports', type, 'page');
+    return (
+      <div className="alert alert-info spacer-top display-inline-block">
+        <FormattedMessage
+          defaultMessage={translate('security_reports.info')}
+          id="security_reports.info"
+          tagName="p"
+          values={{
+            link: (
+              <Link
+                to={getRulesUrl(
+                  { types: [RuleType.Vulnerability, RuleType.Hotspot].join() },
+                  isSonarCloud() ? component.organization : undefined
+                )}>
+                {translate('security_reports.info.link')}
+              </Link>
+            ),
+            standard,
+            total: total - active
+          }}
+        />
+      </div>
+    );
+  };
+
   render() {
     const { branchLike, component, params } = this.props;
     const { loading, findings, showCWE, type } = this.state;
@@ -145,24 +183,7 @@ export default class App extends React.PureComponent<Props, State> {
               to={{ pathname: '/documentation/user-guide/security-reports/' }}>
               {translate('learn_more')}
             </Link>
-            <div className="alert alert-info spacer-top display-inline-block">
-              <FormattedMessage
-                defaultMessage={translate('security_reports.info')}
-                id="security_reports.info"
-                tagName="p"
-                values={{
-                  link: (
-                    <Link
-                      to={getRulesUrl(
-                        { types: [RuleType.Vulnerability, RuleType.Hotspot].join() },
-                        isSonarCloud() ? component.organization : undefined
-                      )}>
-                      {translate('security_reports.info.link')}
-                    </Link>
-                  )
-                }}
-              />
-            </div>
+            {this.renderAdditionalRulesMessage()}
           </div>
         </header>
         <div className="display-inline-flex-center">
index cdc43e9abdfe70c7cd43eba15722208fb0470e57..61c8f98051755210863fd063408c7f5551dccd4b 100644 (file)
@@ -60,6 +60,16 @@ jest.mock('../../../../api/security-reports', () => ({
           toReviewSecurityHotspots: 8,
           openSecurityHotspots: 100,
           wontFixSecurityHotspots: 10
+        },
+        {
+          activeRules: 0,
+          totalRules: 1,
+          category: 'a3',
+          vulnerabilities: 3,
+          vulnerabiliyRating: 3,
+          toReviewSecurityHotspots: 8,
+          openSecurityHotspots: 100,
+          wontFixSecurityHotspots: 10
         }
       ]
     });
@@ -94,10 +104,11 @@ it('renders error on wrong type parameters', () => {
   expect(wrapper).toMatchSnapshot();
 });
 
-it('renders owaspTop10', () => {
+it('renders owaspTop10', async () => {
   const wrapper = shallow(<App component={component} location={location} params={owaspParams} />, {
     context
   });
+  await waitAndUpdate(wrapper);
   expect(getSecurityHotspots).toBeCalledWith({
     project: 'foo',
     standard: 'owaspTop10',
index 840caeee3a101c677649d2cc50868db70b7f6ed6..7f23c59af717dcd94fea5eb149199d98d58a3443 100644 (file)
@@ -38,33 +38,6 @@ exports[`handle checkbox for cwe display 1`] = `
       >
         learn_more
       </Link>
-      <div
-        className="alert alert-info spacer-top display-inline-block"
-      >
-        <FormattedMessage
-          defaultMessage="security_reports.info"
-          id="security_reports.info"
-          tagName="p"
-          values={
-            Object {
-              "link": <Link
-                onlyActiveOnIndex={false}
-                style={Object {}}
-                to={
-                  Object {
-                    "pathname": "/coding_rules",
-                    "query": Object {
-                      "types": "VULNERABILITY,SECURITY_HOTSPOT",
-                    },
-                  }
-                }
-              >
-                security_reports.info.link
-              </Link>,
-            }
-          }
-        />
-      </div>
     </div>
   </header>
   <div
@@ -171,6 +144,8 @@ exports[`handle checkbox for cwe display 2`] = `
               >
                 security_reports.info.link
               </Link>,
+              "standard": "security_reports.owaspTop10.page",
+              "total": 1,
             }
           }
         />
@@ -252,6 +227,16 @@ exports[`handle checkbox for cwe display 2`] = `
             "vulnerabiliyRating": 3,
             "wontFixSecurityHotspots": 10,
           },
+          Object {
+            "activeRules": 0,
+            "category": "a3",
+            "openSecurityHotspots": 100,
+            "toReviewSecurityHotspots": 8,
+            "totalRules": 1,
+            "vulnerabilities": 3,
+            "vulnerabiliyRating": 3,
+            "wontFixSecurityHotspots": 10,
+          },
         ]
       }
       showCWE={true}
@@ -328,6 +313,8 @@ exports[`renders owaspTop10 1`] = `
               >
                 security_reports.info.link
               </Link>,
+              "standard": "security_reports.owaspTop10.page",
+              "total": 1,
             }
           }
         />
@@ -340,7 +327,7 @@ exports[`renders owaspTop10 1`] = `
     <Checkbox
       checked={false}
       className="spacer-left spacer-right vertical-middle"
-      disabled={true}
+      disabled={false}
       id="showCWE"
       onCheck={[Function]}
       thirdState={false}
@@ -358,7 +345,7 @@ exports[`renders owaspTop10 1`] = `
     </Checkbox>
   </div>
   <DeferredSpinner
-    loading={true}
+    loading={false}
     timeout={100}
   >
     <VulnerabilityList
@@ -369,7 +356,58 @@ exports[`renders owaspTop10 1`] = `
           "qualifier": "TRK",
         }
       }
-      findings={Array []}
+      findings={
+        Array [
+          Object {
+            "activeRules": 1,
+            "category": "a1",
+            "distribution": Array [
+              Object {
+                "cwe": "477",
+                "openSecurityHotspots": 10,
+                "toReviewSecurityHotspots": 2,
+                "vulnerabilities": 1,
+                "vulnerabiliyRating": 1,
+                "wontFixSecurityHotspots": 0,
+              },
+              Object {
+                "cwe": "396",
+                "openSecurityHotspots": 10,
+                "toReviewSecurityHotspots": 2,
+                "vulnerabilities": 2,
+                "vulnerabiliyRating": 2,
+                "wontFixSecurityHotspots": 0,
+              },
+            ],
+            "openSecurityHotspots": 10,
+            "toReviewSecurityHotspots": 2,
+            "totalRules": 1,
+            "vulnerabilities": 2,
+            "vulnerabiliyRating": 5,
+            "wontFixSecurityHotspots": 0,
+          },
+          Object {
+            "activeRules": 1,
+            "category": "a2",
+            "openSecurityHotspots": 100,
+            "toReviewSecurityHotspots": 8,
+            "totalRules": 1,
+            "vulnerabilities": 3,
+            "vulnerabiliyRating": 3,
+            "wontFixSecurityHotspots": 10,
+          },
+          Object {
+            "activeRules": 0,
+            "category": "a3",
+            "openSecurityHotspots": 100,
+            "toReviewSecurityHotspots": 8,
+            "totalRules": 1,
+            "vulnerabilities": 3,
+            "vulnerabiliyRating": 3,
+            "wontFixSecurityHotspots": 10,
+          },
+        ]
+      }
       showCWE={false}
       type="owaspTop10"
     />
@@ -415,33 +453,6 @@ exports[`renders sansTop25 1`] = `
       >
         learn_more
       </Link>
-      <div
-        className="alert alert-info spacer-top display-inline-block"
-      >
-        <FormattedMessage
-          defaultMessage="security_reports.info"
-          id="security_reports.info"
-          tagName="p"
-          values={
-            Object {
-              "link": <Link
-                onlyActiveOnIndex={false}
-                style={Object {}}
-                to={
-                  Object {
-                    "pathname": "/coding_rules",
-                    "query": Object {
-                      "types": "VULNERABILITY,SECURITY_HOTSPOT",
-                    },
-                  }
-                }
-              >
-                security_reports.info.link
-              </Link>,
-            }
-          }
-        />
-      </div>
     </div>
   </header>
   <div
@@ -525,33 +536,6 @@ exports[`renders with cwe 1`] = `
       >
         learn_more
       </Link>
-      <div
-        className="alert alert-info spacer-top display-inline-block"
-      >
-        <FormattedMessage
-          defaultMessage="security_reports.info"
-          id="security_reports.info"
-          tagName="p"
-          values={
-            Object {
-              "link": <Link
-                onlyActiveOnIndex={false}
-                style={Object {}}
-                to={
-                  Object {
-                    "pathname": "/coding_rules",
-                    "query": Object {
-                      "types": "VULNERABILITY,SECURITY_HOTSPOT",
-                    },
-                  }
-                }
-              >
-                security_reports.info.link
-              </Link>,
-            }
-          }
-        />
-      </div>
     </div>
   </header>
   <div
index 93e64e0c308392cddda4311f5fe0b52773644c01..5b3b5b031e6e670d0dae3aae9cf7eb20de60a4bb 100644 (file)
@@ -2044,8 +2044,8 @@ organizations_permissions.provisioning.desc=Ability to initialize a project so i
 # SECURITY REPORTS PAGE
 #
 #------------------------------------------------------------------------------
-security_reports.info=Issues counts and ratings below consider only {link} enabled in Quality Profiles.
-security_reports.info.link=security rules
+security_reports.info={total} additional rules related to {standard} Security Standards {link} but not used in this project's profiles.
+security_reports.info.link=are available
 security_reports.owaspTop10.page=OWASP Top 10
 security_reports.sansTop25.page=SANS Top 25
 security_reports.owaspTop10.description=Track Vulnerabilities and Security Hotspots conforming to OWASP Top 10 standard.