text: import { InsightsSystemRule } from './InsightsSystemRule';
  import { mountWithIntl } from '../../../Helpers/MiscHelper';
  import toJson from 'enzyme-to-json';
  
  const rule = {
      "details": {
        "cmd_any": false,
        "cmdline_dict": {
          "BOOT_IMAGE": [
            "/vmlinuz-3.10.0-1062.el7.x86_64"
          ],
          "LANG": [
            "en_US.UTF-8"
          ],
          "console": [
            "ttyS0,115200n81"
          ],
          "crashkernel": [
            "auto"
          ],
          "rd.lvm.lv": [
            "rhel_sat-r220-01/root",
            "rhel_sat-r220-01/swap"
          ],
          "ro": [
            true
          ],
          "root": [
            "/dev/mapper/rhel_sat--r220--01-root"
          ]
        },
        "cmdline_raw": "BOOT_IMAGE=/vmlinuz-3.10.0-1062.el7.x86_64 root=/dev/mapper/rhel_sat--r220--01-root ro crashkernel=auto rd.lvm.lv=rhel_sat-r220-01/root rd.lvm.lv=rhel_sat-r220-01/swap console=ttyS0,115200n81 LANG=en_US.UTF-8",
        "cves": {
          "CVE-2018-12126": false,
          "CVE-2018-12127": false,
          "CVE-2018-12130": false,
          "CVE-2019-11091": false
        },
        "dmesg_wrapped": false,
        "error_key": "CVE_2018_12130_CPU_KERNEL_VULNERABLE_2",
        "rel": 7,
        "rh6nosmt": false,
        "rh6nosmt1st": false,
        "rt": false,
        "type": "rule",
        "vuln": [
          "Mitigation: Clear CPU buffers; SMT vulnerable"
        ]
      },
      "resolution": {
        "resolution": "Addressing the vulnerabilities reported by the kernel may require further steps such as disabling SMT in the system BIOS or via the kernel command line. See below for links to further documentation and tools to assist in making these changes.{{? pydata.rh6nosmt1st }}\n\nIt appears that you've tried to enable the full mitigation using the `mds=full,nosmt` command line argument. This RHEL6 machine might require an additional separate `nosmt` command line argument to disable SMT:\n\n~~~\n# grubby --update-kernel=ALL --args=nosmt\n~~~\nReboot:\n~~~\n# reboot\n~~~\n{{?}}{{? pydata.dmesg_wrapped }}\n\nThe kernel ring buffer has wrapped, making some information from `dmesg` unreliable. See [How do I increase the kernel log ring buffer size?](https://access.redhat.com/solutions/47276) for further information. Rebooting the system may also overcome this issue.{{?}}\n\n{{? pydata.virtualization }}**Note about virtualization**\n\nIn virtualized environment, there are more steps to mitigate the issue, including:\n* Host needs to have updated kernel and CPU microcode\n* Host needs to have updated virtualization software\n* Guest needs to have updated kernel\n* Hypervisor needs to propagate new CPU features correctly\n\nFor more details about mitigations in virtualized environment see: [https://access.redhat.com/articles/3331571](https://access.redhat.com/articles/3331571){{?}}\n\n{{? pydata.virtualization == \"vmware\" }}For help with setting VMWare to propagate CPU features correctly, refer to the following knowledge-base article: [https://kb.vmware.com/s/article/52085](https://kb.vmware.com/s/article/52085){{?}}"
      },
      "rule": {
        "description": "CVE-2018-12126, CVE-2018-12127, CVE-2018-12130, CVE-2019-11091: \"MDS\" CPU side-channel reported by kernel",
        "more_info": "* For more information about the flaw, see [the vulnerability article](https://access.redhat.com/security/vulnerabilities/mds).\n* For guidance in disabling hyper-threading, see the article [Reviewing and Disabling Hyper-Threading in Red Hat Enterprise Linux](https://access.redhat.com/solutions/rhel-smt).\n* For information about the performance impact of disabling hyperthreading, see the **Disabling Hyper-Threading** section of the article [Performance Considerations for L1 Terminal Fault](https://access.redhat.com/security/vulnerabilities/L1TF-perf).\n* Similar vulnerabilities are listed on the [CPU Side Channel Attack Index Page](https://access.redhat.com/articles/4067611).\n* For information about the microcode availability, see [Is CPU Microcode available to address the CVEs?](https://access.redhat.com/articles/4138151).\n* For information about detecting mitigations in hosted environments, see the article [CPU Side Channel Microcode Detection in Hosted/Cloud Environments](https://access.redhat.com/solution/CPUSideChannelMicrocode).\n* To learn how to upgrade packages, see [What is yum and how do I use it?](https://access.redhat.com/solutions/9934).\n* The Customer Portal page for the [Red Hat Security Team](https://access.redhat.com/security/) contains more information about policies, procedures, and alerts for Red Hat products.\n* The Security Team also maintains a frequently updated blog at [securityblog.redhat.com](https://securityblog.redhat.com).\n",
        "reason": "The system's kernel reports other vulnerable components as follows:\n\n{{=pydata.vuln}}\n\nIt means:\n\n* It has a vulnerable CPU\n{{? pydata.vuln[0].indexOf(\"Vulnerable: Clear CPU buffers attempted\") != -1 }}* CPU microcode update is not detected\n{{?}}{{? ( pydata.vuln[0].indexOf(\"Vulnerable\") != -1 ) && ( pydata.vuln[0].indexOf(\"Vulnerable: Clear CPU buffers attempted\") == -1 ) }}* MDS mitigation is disabled\n{{?}}{{? pydata.vuln[0].indexOf(\"SMT vulnerable\") != -1 }}* SMT is vulnerable\n{{?}}\n\n{{? pydata.vuln[0].indexOf(\"Vulnerable: Clear CPU buffers attempted\") != -1 }}If CPU microcode update is not detected by the kernel it may be caused by either:\n1. Microcode update not installed on the system or its underlying hardware in case of virtual machine\n{{? pydata.virtualization }}2. Outdated virtualization software (hypervisor) on the host system\n3. Virtualization software (hypervisor) on the host system not propagating new CPU features correctly\n{{?}}{{?}}\n",
        "rule_id": "CVE_2018_12130_cpu_kernel|CVE_2018_12130_CPU_KERNEL_VULNERABLE_2",
        "node_id": 34556
      }
    }
  describe('InsightsSystemRule', () => {
      it('Should render without rule ', () => {
          const wrapper = mountWithIntl(<InsightsSystemRule rule={null}/>);
          expect(toJson(wrapper)).toMatchSnapshot();
      });
  
      it('Should render empty message', () => {
          const wrapper = mountWithIntl(<InsightsSystemRule rule={null} cve="CVE_2018_12130"/>);
         expect(wrapper.text()).toBe("This system is affected by CVE_2018_12130, but is not affected by any security rules associated with this CVE.Security rules are written by Red Hat to help you configure your systems.Learn more about security rules")
      });
  
      it('Should render with rule', () => {
          const wrapper = mountWithIntl(<InsightsSystemRule rule={rule} />);
          expect(toJson(wrapper)).toMatchSnapshot();
      });
  
      it('Should render with InsightsRule report', () => {
          const wrapper = mountWithIntl(<InsightsSystemRule rule={rule} />)
          expect(wrapper.find('ReportDetails')).toHaveLength(1)
      })
  
      it('Should render rule ruleID ', () => {
          rule.rule =  {
              "description": null, 
              "reason": "The system's kernel reports other vulnerable components as follows:\n\n{{=pydata.vuln}}\n\nIt means:\n\n* It has a vulnerable CPU\n{{? pydata.vuln[0].indexOf(\"Vulnerable: Clear CPU buffers attempted\") != -1 }}* CPU microcode update is not detected\n{{?}}{{? ( pydata.vuln[0].indexOf(\"Vulnerable\") != -1 ) && ( pydata.vuln[0].indexOf(\"Vulnerable: Clear CPU buffers attempted\") == -1 ) }}* MDS mitigation is disabled\n{{?}}{{? pydata.vuln[0].indexOf(\"SMT vulnerable\") != -1 }}* SMT is vulnerable\n{{?}}\n\n{{? pydata.vuln[0].indexOf(\"Vulnerable: Clear CPU buffers attempted\") != -1 }}If CPU microcode update is not detected by the kernel it may be caused by either:\n1. Microcode update not installed on the system or its underlying hardware in case of virtual machine\n{{? pydata.virtualization }}2. Outdated virtualization software (hypervisor) on the host system\n3. Virtualization software (hypervisor) on the host system not propagating new CPU features correctly\n{{?}}{{?}}\n",
              "rule_id": "CVE_2018_12130_cpu_kernel|CVE_2018_12130_CPU_KERNEL_VULNERABLE_2"
          } 
          const wrapper = mountWithIntl(<InsightsSystemRule rule={rule} cve="CVE_2018_12130" />)
          expect(wrapper.find('.rule-name').text()).toEqual("CVE_2018_12130_cpu_kernel|CVE_2018_12130_CPU_KERNEL_VULNERABLE_2")
      })
  })
  