You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

security-standard-test.ts 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import { Standards } from '../../types/security';
  21. import {
  22. renderCWECategory,
  23. renderOwaspTop10Category,
  24. renderSansTop25Category,
  25. renderSonarSourceSecurityCategory
  26. } from '../security-standard';
  27. describe('renderCWECategory', () => {
  28. const standards: Standards = {
  29. cwe: {
  30. '1004': {
  31. title: "Sensitive Cookie Without 'HttpOnly' Flag"
  32. },
  33. unknown: {
  34. title: 'No CWE associated'
  35. }
  36. },
  37. owaspTop10: {},
  38. sansTop25: {},
  39. sonarsourceSecurity: {}
  40. };
  41. it('should render cwe categories correctly', () => {
  42. expect(renderCWECategory(standards, '1004')).toEqual(
  43. "CWE-1004 - Sensitive Cookie Without 'HttpOnly' Flag"
  44. );
  45. expect(renderCWECategory(standards, '124')).toEqual('CWE-124');
  46. expect(renderCWECategory(standards, 'unknown')).toEqual('No CWE associated');
  47. });
  48. });
  49. describe('renderOwaspTop10Category', () => {
  50. const standards: Standards = {
  51. cwe: {},
  52. owaspTop10: {
  53. a1: {
  54. title: 'Injection'
  55. }
  56. },
  57. sansTop25: {},
  58. sonarsourceSecurity: {}
  59. };
  60. it('should render owasp categories correctly', () => {
  61. expect(renderOwaspTop10Category(standards, 'a1')).toEqual('A1 - Injection');
  62. expect(renderOwaspTop10Category(standards, 'a1', true)).toEqual('OWASP A1 - Injection');
  63. expect(renderOwaspTop10Category(standards, 'a2')).toEqual('A2');
  64. expect(renderOwaspTop10Category(standards, 'a2', true)).toEqual('OWASP A2');
  65. });
  66. });
  67. describe('renderSansTop25Category', () => {
  68. const standards: Standards = {
  69. cwe: {},
  70. owaspTop10: {},
  71. sansTop25: {
  72. 'insecure-interaction': {
  73. title: 'Insecure Interaction Between Components'
  74. }
  75. },
  76. sonarsourceSecurity: {}
  77. };
  78. it('should render sans categories correctly', () => {
  79. expect(renderSansTop25Category(standards, 'insecure-interaction')).toEqual(
  80. 'Insecure Interaction Between Components'
  81. );
  82. expect(renderSansTop25Category(standards, 'insecure-interaction', true)).toEqual(
  83. 'SANS Insecure Interaction Between Components'
  84. );
  85. expect(renderSansTop25Category(standards, 'unknown')).toEqual('unknown');
  86. expect(renderSansTop25Category(standards, 'unknown', true)).toEqual('SANS unknown');
  87. });
  88. });
  89. describe('renderSonarSourceSecurityCategory', () => {
  90. const standards: Standards = {
  91. cwe: {},
  92. owaspTop10: {},
  93. sansTop25: {},
  94. sonarsourceSecurity: {
  95. xss: {
  96. title: 'Cross-Site Scripting (XSS)'
  97. },
  98. others: {
  99. title: 'Others'
  100. }
  101. }
  102. };
  103. it('should render sonarsource categories correctly', () => {
  104. expect(renderSonarSourceSecurityCategory(standards, 'xss')).toEqual(
  105. 'Cross-Site Scripting (XSS)'
  106. );
  107. expect(renderSonarSourceSecurityCategory(standards, 'xss', true)).toEqual(
  108. 'SONAR Cross-Site Scripting (XSS)'
  109. );
  110. expect(renderSonarSourceSecurityCategory(standards, 'others')).toEqual('Others');
  111. expect(renderSonarSourceSecurityCategory(standards, 'others', true)).toEqual('Others');
  112. });
  113. });