def test_report_filename(self): """Ensure check results summary filename property is set.""" report = co.ComplianceOscalObservations( 'https://repo', 'creds', 'branch', 'repo-path' ) self.assertEqual( report.report_filename, 'compliance_oscal_observations.json' )
def _expect_no_report_content(self, kubernetes_cluster_resource): """Expect 'No report content.' exception.""" tgt = 'arboretum.kubernetes.reports.compliance_oscal_observations.' tgt += 'ComplianceOscalObservations.get_file_content' with patch(tgt, Mock(side_effect=[kubernetes_cluster_resource])): report = co.ComplianceOscalObservations( 'https://repo', 'creds', 'branch', 'repo-path' ) with self.assertRaises(RuntimeError) as e: report.generate_report() self.assertEqual(str(e.exception), 'No report content.')
def test_generate_report_exception_no_cluster_resource_content(self): """Ensure proper handling of no cluster_resource content.""" report = co.ComplianceOscalObservations( 'https://repo', 'creds', 'branch', 'repo-path', cluster_resource='bogus' ) with self.assertRaises(RuntimeError) as e: report.generate_report() self.assertEqual(str(e.exception), 'No report content.')
def test_generate_report_bad_dates(self): """Ensure proper handling bad start and end dates.""" report = co.ComplianceOscalObservations( 'https://repo', 'creds', 'branch', 'repo-path', start='20210101', end='20201231' ) with self.assertRaises(ValueError) as e: report.generate_report() self.assertEqual( str(e.exception), 'Cannot have start date before end date.' )
def test_generate_report(self): """Ensure proper report creation.""" with open('./test/fixtures/kubernetes_cluster_resource.json', 'r') as f: kubernetes_cluster_resource = f.read() tgt = 'arboretum.kubernetes.reports.compliance_oscal_observations.' tgt += 'ComplianceOscalObservations.get_file_content' with patch(tgt, Mock(side_effect=[kubernetes_cluster_resource])): report = co.ComplianceOscalObservations( 'https://repo', 'creds', 'branch', 'repo-path' ) result = report.generate_report() self.assertEqual( 'ff4b5c1576e226aca4108b3a6a335969', hashlib.md5(result.encode('utf-8')).hexdigest() )
def test_generate_report_with_metadata(self): """Ensure proper report creation with oscal metadata.""" with open('./test/fixtures/compliance_oscal_metadata.yaml', 'r') as f: compliance_oscal_metadata = f.read() with open('./test/fixtures/kubernetes_cluster_resource.json', 'r') as f: kubernetes_cluster_resource = f.read() tgt = 'arboretum.kubernetes.reports.compliance_oscal_observations.' tgt += 'ComplianceOscalObservations.get_file_content' with patch(tgt, Mock(side_effect=[kubernetes_cluster_resource, compliance_oscal_metadata])): report = co.ComplianceOscalObservations( 'https://github.mycorp.com/myuser/evidence-locker', 'creds', 'branch', 'repo-path', oscal_metadata='compliance_oscal_metadata.yaml' ) result = report.generate_report() self.assertEqual( '28f797591fcf61f0edb6f4ad17a0a98d', hashlib.md5(result.encode('utf-8')).hexdigest() )