]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11983 Move Standards type to the global scope, and add the new sonarsource...
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Tue, 16 Apr 2019 06:33:43 +0000 (08:33 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 7 May 2019 07:54:27 +0000 (09:54 +0200)
server/sonar-web/src/main/js/api/security-reports.ts
server/sonar-web/src/main/js/app/types.d.ts
server/sonar-web/src/main/js/apps/issues/sidebar/Sidebar.tsx
server/sonar-web/src/main/js/apps/issues/sidebar/StandardFacet.tsx
server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/StandardFacet-test.tsx
server/sonar-web/src/main/js/apps/securityReports/components/App.tsx
server/sonar-web/src/main/js/apps/securityReports/components/VulnerabilityList.tsx
server/sonar-web/src/main/js/apps/securityReports/utils.ts

index 31eb7b5530e0a5dde2ec4802992507e0089a56a6..d709b33ca7ea9d9e989ff6532a7b25a6ab896a0f 100644 (file)
@@ -22,7 +22,7 @@ import throwGlobalError from '../app/utils/throwGlobalError';
 
 export function getSecurityHotspots(data: {
   project: string;
-  standard: 'owaspTop10' | 'sansTop25' | 'cwe';
+  standard: T.StandardType;
   includeDistribution?: boolean;
   branch?: string;
 }): Promise<{ categories: T.SecurityHotspot[] }> {
index fe4c3c304190723746363a984a2e44ec4e374b8e..d97e54174f30225c59a3b6ee388f3d7abb104632 100644 (file)
@@ -850,6 +850,12 @@ declare namespace T {
     uuid: string;
   }
 
+  export type Standards = {
+    [key in StandardType]: T.Dict<{ title: string; description?: string }>
+  };
+
+  export type StandardType = 'owaspTop10' | 'sansTop25' | 'cwe' | 'sonarsourceSecurity';
+
   export interface SubscriptionPlan {
     maxNcloc: number;
     price: number;
index c40f1889559f2928f56dee26338b3d5f7ea530e8..a4eaf6f0c4a9ac93897a884ab7634a7babcc4ab3 100644 (file)
@@ -198,6 +198,11 @@ export default class Sidebar extends React.PureComponent<Props> {
           sansTop25={query.sansTop25}
           sansTop25Open={!!openFacets.sansTop25}
           sansTop25Stats={facets.sansTop25}
+          sonarsourceSecurity={
+            [
+              /* TODO */
+            ]
+          }
         />
         <TagFacet
           component={component}
index 534482898a9a55e0c297ba4170db0253ec38aad4..066ebcdefe8bd37bfe2af96b57e08abd4290ca33 100644 (file)
@@ -28,8 +28,7 @@ import FacetItem from '../../../components/facet/FacetItem';
 import {
   renderOwaspTop10Category,
   renderSansTop25Category,
-  renderCWECategory,
-  Standards
+  renderCWECategory
 } from '../../securityReports/utils';
 import DeferredSpinner from '../../../components/common/DeferredSpinner';
 import MultipleSelectionHint from '../../../components/facet/MultipleSelectionHint';
@@ -54,22 +53,23 @@ export interface Props {
   sansTop25: string[];
   sansTop25Open: boolean;
   sansTop25Stats: T.Dict<number> | undefined;
+  sonarsourceSecurity: string[];
 }
 
 interface State {
   cweQuery: string;
-  standards: Standards;
+  standards: T.Standards;
 }
 
 type StatsProp = 'owaspTop10Stats' | 'cweStats' | 'sansTop25Stats';
-type ValuesProp = 'owaspTop10' | 'sansTop25' | 'cwe';
+type ValuesProp = T.StandardType;
 
 export default class StandardFacet extends React.PureComponent<Props, State> {
   mounted = false;
   property = STANDARDS;
   state: State = {
     cweQuery: '',
-    standards: { owaspTop10: {}, sansTop25: {}, cwe: {} }
+    standards: { owaspTop10: {}, sansTop25: {}, cwe: {}, sonarsourceSecurity: {} }
   };
 
   componentDidMount() {
@@ -100,9 +100,9 @@ export default class StandardFacet extends React.PureComponent<Props, State> {
     import('../../../helpers/standards.json')
       .then(x => x.default)
       .then(
-        ({ owaspTop10, sansTop25, cwe }: Standards) => {
+        ({ owaspTop10, sansTop25, cwe, sonarsourceSecurity }: T.Standards) => {
           if (this.mounted) {
-            this.setState({ standards: { owaspTop10, sansTop25, cwe } });
+            this.setState({ standards: { owaspTop10, sansTop25, cwe, sonarsourceSecurity } });
           }
         },
         () => {}
@@ -176,7 +176,7 @@ export default class StandardFacet extends React.PureComponent<Props, State> {
   renderList = (
     statsProp: StatsProp,
     valuesProp: ValuesProp,
-    renderName: (standards: Standards, category: string) => string,
+    renderName: (standards: T.Standards, category: string) => string,
     onClick: (x: string, multiple?: boolean) => void
   ) => {
     const stats = this.props[statsProp];
@@ -193,8 +193,8 @@ export default class StandardFacet extends React.PureComponent<Props, State> {
     stats: any,
     values: string[],
     categories: string[],
-    renderName: (standards: Standards, category: string) => React.ReactNode,
-    renderTooltip: (standards: Standards, category: string) => string,
+    renderName: (standards: T.Standards, category: string) => React.ReactNode,
+    renderTooltip: (standards: T.Standards, category: string) => string,
     onClick: (x: string, multiple?: boolean) => void
   ) => {
     if (!categories.length) {
index f366eb792c4015f1e8f800a118fb433bc70f1b0c..d9ebbc68f0cf8f8d88ec5848301a2e01ef7f444c 100644 (file)
@@ -154,6 +154,7 @@ function shallowRender(props: Partial<Props> = {}) {
       sansTop25={[]}
       sansTop25Open={false}
       sansTop25Stats={{}}
+      sonarsourceSecurity={[]}
       {...props}
     />,
     // disable loading of standards.json
index 4b7d090e331864e2202f366c10e2029b9e698a47..6dc80000947cdbd4fc6e12732a3d74665c396e0f 100755 (executable)
@@ -30,7 +30,6 @@ import NotFound from '../../../app/components/NotFound';
 import { getSecurityHotspots } from '../../../api/security-reports';
 import { isLongLivingBranch } from '../../../helpers/branches';
 import DocTooltip from '../../../components/docs/DocTooltip';
-import { StandardType } from '../utils';
 import { Alert } from '../../../components/ui/Alert';
 import { withRouter, Location, Router } from '../../../components/hoc/withRouter';
 import '../style.css';
@@ -47,7 +46,7 @@ interface State {
   loading: boolean;
   findings: T.SecurityHotspot[];
   hasVulnerabilities: boolean;
-  type: StandardType;
+  type: T.StandardType;
   showCWE: boolean;
 }
 
@@ -60,7 +59,7 @@ export class App extends React.PureComponent<Props, State> {
       loading: false,
       findings: [],
       hasVulnerabilities: false,
-      type: props.params.type === 'owasp_top_10' ? 'owaspTop10' : 'sansTop25',
+      type: this.getType(props.params.type),
       showCWE: props.location.query.showCWE === 'true'
     };
   }
@@ -73,7 +72,7 @@ export class App extends React.PureComponent<Props, State> {
   componentWillReceiveProps(newProps: Props) {
     if (newProps.location.pathname !== this.props.location.pathname) {
       const showCWE = newProps.location.query.showCWE === 'true';
-      const type = newProps.params.type === 'owasp_top_10' ? 'owaspTop10' : 'sansTop25';
+      const type = this.getType(newProps.params.type);
       this.setState({ type, showCWE }, this.fetchSecurityHotspots);
     }
   }
@@ -82,6 +81,16 @@ export class App extends React.PureComponent<Props, State> {
     this.mounted = false;
   }
 
+  getType = (type: string): T.StandardType => {
+    if (type === 'owasp_top_10') {
+      return 'owaspTop10';
+    } else if (type === 'sans_top_25') {
+      return 'sansTop25';
+    } else {
+      return 'sonarsource';
+    }
+  };
+
   fetchSecurityHotspots = () => {
     const { branchLike, component } = this.props;
     this.setState({ loading: true });
index 22bf4655635a4582ca0b442e5d8c18ec5bdd1421..a508d30c1209d7c7a186998fec8ada0ba8e7d414 100755 (executable)
@@ -27,13 +27,7 @@ import { getBranchLikeQuery } from '../../../helpers/branches';
 import HelpTooltip from '../../../components/controls/HelpTooltip';
 import VulnerabilityIcon from '../../../components/icons-components/VulnerabilityIcon';
 import SecurityHotspotIcon from '../../../components/icons-components/SecurityHotspotIcon';
-import {
-  renderOwaspTop10Category,
-  renderSansTop25Category,
-  renderCWECategory,
-  Standards,
-  StandardType
-} from '../utils';
+import { renderOwaspTop10Category, renderSansTop25Category, renderCWECategory } from '../utils';
 import DetachIcon from '../../../components/icons-components/DetachIcon';
 import Tooltip from '../../../components/controls/Tooltip';
 import { getRatingTooltip } from '../../../helpers/measures';
@@ -46,22 +40,23 @@ interface Props {
   component: T.Component;
   findings: T.SecurityHotspot[];
   showCWE: boolean;
-  type: StandardType;
+  type: T.StandardType;
 }
 
 interface State {
-  standards: Standards;
+  standards: T.Standards;
 }
 
 const STANDARDS_TAGS = {
   owaspTop10: 'owasp',
   sansTop25: 'sans-top25',
-  cwe: 'cwe'
+  cwe: 'cwe',
+  sonarsourceSecurity: 'sonarsourceSecurity'
 };
 
 export default class VulnerabilityList extends React.PureComponent<Props, State> {
   mounted = false;
-  state: State = { standards: { owaspTop10: {}, sansTop25: {}, cwe: {} } };
+  state: State = { standards: { owaspTop10: {}, sansTop25: {}, cwe: {}, sonarsourceSecurity: {} } };
 
   componentDidMount() {
     this.mounted = true;
@@ -76,21 +71,24 @@ export default class VulnerabilityList extends React.PureComponent<Props, State>
     import('../../../helpers/standards.json')
       .then(x => x.default)
       .then(
-        ({ owaspTop10, sansTop25, cwe }: Standards) => {
+        ({ owaspTop10, sansTop25, cwe, sonarsourceSecurity }: T.Standards) => {
           if (this.mounted) {
-            this.setState({ standards: { owaspTop10, sansTop25, cwe } });
+            this.setState({ standards: { owaspTop10, sansTop25, cwe, sonarsourceSecurity } });
           }
         },
         () => {}
       );
   };
 
-  getName(finding: T.SecurityHotspot, type: StandardType) {
+  getName(finding: T.SecurityHotspot, type: T.StandardType) {
     const category = finding.category || finding.cwe || 'unknown';
     const renderers = {
       owaspTop10: renderOwaspTop10Category,
       sansTop25: renderSansTop25Category,
-      cwe: renderCWECategory
+      cwe: renderCWECategory,
+      sonarsourceSecurity: () => {
+        /* TODO */
+      }
     };
     return (
       <>
@@ -118,7 +116,7 @@ export default class VulnerabilityList extends React.PureComponent<Props, State>
 
   // We redirect the user to the rules page, using languages, types, keywords and tags filters
   // to display the correct list of rules
-  renderMoreRulesOverlay = (type: StandardType, category: string) => {
+  renderMoreRulesOverlay = (type: T.StandardType, category: string) => {
     const languages = this.props.component.qualityProfiles
       ? this.props.component.qualityProfiles.map(qp => qp.language).join(',')
       : '';
index 023f7f76dbaa98220d1873b603cd9e5d311d09a2..e53518ab2f427771d2c72a589cb39a0f8f5b0103 100755 (executable)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-export type StandardType = 'owaspTop10' | 'sansTop25' | 'cwe';
-
-export interface Standards {
-  owaspTop10: T.Dict<{ title: string; description?: string }>;
-  sansTop25: T.Dict<{ title: string; description?: string }>;
-  cwe: T.Dict<{ title: string; description?: string }>;
-}
-
 export function renderOwaspTop10Category(
-  standards: Standards,
+  standards: T.Standards,
   category: string,
   withPrefix = false
 ): string {
@@ -40,7 +32,7 @@ export function renderOwaspTop10Category(
   }
 }
 
-export function renderCWECategory(standards: Standards, category: string): string {
+export function renderCWECategory(standards: T.Standards, category: string): string {
   const record = standards.cwe[category];
   if (!record) {
     return `CWE-${category}`;
@@ -52,7 +44,7 @@ export function renderCWECategory(standards: Standards, category: string): strin
 }
 
 export function renderSansTop25Category(
-  standards: Standards,
+  standards: T.Standards,
   category: string,
   withPrefix = false
 ): string {