-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* SCAP report and remediation * Fix missing attribute error when called without limit * Comments addressed
- Loading branch information
Showing
5 changed files
with
223 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from wait_for import wait_for | ||
|
||
from airgun.entities.base import BaseEntity | ||
from airgun.navigation import NavigateStep, navigator | ||
from airgun.utils import retry_navigation | ||
from airgun.views.oscapreport import ( | ||
RemediateModal, | ||
SCAPReportDetailsView, | ||
SCAPReportView, | ||
) | ||
|
||
|
||
class OSCAPReportEntity(BaseEntity): | ||
endpoint_path = '/compliance/arf_reports' | ||
|
||
def search(self, search_string): | ||
"""Search for SCAP Report | ||
:param search_string: how to find the SCAP Report | ||
:return: result of the SCAP Report search | ||
""" | ||
view = self.navigate_to(self, 'All') | ||
return view.search(search_string) | ||
|
||
def details(self, search_string, widget_names=None, limit=None): | ||
"""Read the content from corresponding SCAP Report dashboard, | ||
clicking on the link in Reported At column of | ||
SCAP Report list | ||
:param search_string: | ||
:param limit: how many rules results to fetch at most | ||
:return: list of dictionaries with values from SCAP Report Details View | ||
""" | ||
view = self.navigate_to(self, 'Details', search_string=search_string) | ||
return view.read(widget_names=widget_names, limit=limit) | ||
|
||
def remediate(self, search_string, resource): | ||
"""Remediate the failed rule using automatic remediation through Ansible | ||
:param search_string: | ||
""" | ||
view = self.navigate_to(self, 'Details', search_string=search_string) | ||
view.table.row(resource=resource).actions.fill('Remediation') | ||
view = RemediateModal(self.browser) | ||
view.wait_displayed() | ||
self.browser.plugin.ensure_page_safe() | ||
wait_for(lambda: view.title.is_displayed, timeout=10, delay=1) | ||
view.fill({'select_remediation_method.snippet': 'Ansible'}) | ||
view.select_capsule.run.click() | ||
|
||
|
||
@navigator.register(OSCAPReportEntity, 'All') | ||
class ShowAllSCAPReports(NavigateStep): | ||
"""Navigate to Compliance Reports screen.""" | ||
|
||
VIEW = SCAPReportView | ||
|
||
@retry_navigation | ||
def step(self, *args, **kwargs): | ||
self.view.menu.select('Hosts', 'Compliance', 'Reports') | ||
|
||
|
||
@navigator.register(OSCAPReportEntity, 'Details') | ||
class DetailsSCAPReport(NavigateStep): | ||
"""To get data from ARF report view | ||
Args: | ||
search_string: what to fill to find the SCAP report | ||
""" | ||
|
||
VIEW = SCAPReportDetailsView | ||
|
||
def prerequisite(self, *args, **kwargs): | ||
return self.navigate_to(self.obj, 'All') | ||
|
||
def step(self, *args, **kwargs): | ||
search_string = kwargs.get('search_string') | ||
self.parent.search(search_string) | ||
self.parent.table.row()['Reported At'].widget.click() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from widgetastic.widget import Text, View | ||
from widgetastic_patternfly4 import Button | ||
from widgetastic_patternfly4.ouia import FormSelect | ||
|
||
from airgun.views.common import BaseLoggedInView, SearchableViewMixin, WizardStepView | ||
from airgun.widgets import ( | ||
ActionsDropdown, | ||
SatTable, | ||
) | ||
|
||
|
||
class SCAPReportView(BaseLoggedInView, SearchableViewMixin): | ||
title = Text("//h1[normalize-space(.)='Compliance Reports']") | ||
table = SatTable( | ||
'.//table', | ||
column_widgets={ | ||
'Host': Text(".//a[contains(@href,'/new/hosts')]"), | ||
'Reported At': Text(".//a[contains(@href,'/compliance/arf_reports')]"), | ||
'Policy': Text(".//a[contains(@href,'/compliance/policies')]"), | ||
'Openscap Capsule': Text(".//a[contains(@href,'/smart_proxies')]"), | ||
'Passed': Text(".//span[contains(@class,'label-info')]"), | ||
'Failed': Text(".//span[contains(@class,'label-danger')]"), | ||
'Other': Text(".//span[contains(@class,'label-warning')]"), | ||
'Actions': ActionsDropdown("./div[contains(@class, 'btn-group')]"), | ||
}, | ||
) | ||
|
||
@property | ||
def is_displayed(self): | ||
return self.browser.wait_for_element(self.title, exception=False) is not None | ||
|
||
|
||
class SCAPReportDetailsView(BaseLoggedInView): | ||
show_log_messages_label = Text('//span[normalize-space(.)="Show log messages:"]') | ||
table = SatTable( | ||
'.//table', | ||
column_widgets={ | ||
'Result': Text('./span[1]'), | ||
'Message': Text('./span[2]'), | ||
'Resource': Text('./span[3]'), | ||
'Severity': Text('./img[1]'), | ||
'Actions': ActionsDropdown("./div[contains(@class, 'btn-group')]"), | ||
}, | ||
) | ||
|
||
@property | ||
def is_displayed(self): | ||
return ( | ||
self.browser.wait_for_element(self.show_log_messages_label, exception=False) is not None | ||
) | ||
|
||
|
||
class RemediateModal(View): | ||
""" | ||
Class representing the "Remediate" modal. | ||
It contains multiple nested classes each representing a step of the wizard. | ||
""" | ||
|
||
ROOT = '//div[contains(@data-ouia-component-id, "OUIA-Generated-Modal-large-")]' | ||
|
||
title = Text('.//h2[contains(@class, "pf-c-title")]') | ||
close_modal = Button(locator='.//button[@aria-label="Close"]') | ||
|
||
@View.nested | ||
class select_remediation_method(WizardStepView): | ||
expander = Text( | ||
'.//button[contains(@class,"pf-c-wizard__nav-link") and contains(.,"Select snippet")]' | ||
) | ||
snippet = FormSelect('snippet-select') | ||
|
||
@View.nested | ||
class name_source(WizardStepView): | ||
expander = Text( | ||
'.//button[contains(@class,"pf-c-wizard__nav-link") and contains(.,"Review hosts")]' | ||
) | ||
host_table = SatTable(".//table") | ||
|
||
@View.nested | ||
class select_capsule(WizardStepView): | ||
expander = Text( | ||
'.//button[contains(@class,"pf-c-wizard__nav-link") and contains(.,"Review remediation")]' | ||
) | ||
run = Button(locator='.//button[normalize-space(.)="Run"]') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters