Esempio n. 1
0
    def test_report_job(self):
        create_workflow(label='test workflow')
        test_workflow = Workflow.query.first()
        self.assertIsNotNone(test_workflow.workflowId)

        create_sysConfig(
            label='test sysconfig',
            nixConfigFilename='test.nix',
            nixConfig='{ nix: config }',
            workflowId=test_workflow.workflowId
        )
        test_sysconfig = SystemConfigurationInput.query.first()

        create_reportJob(
            label='first report',
            sysConfigId=test_sysconfig.sysConfigId,
            workflowId=test_workflow.workflowId,
            statusId=JobStatus().query.order_by(JobStatus.statusId.desc()).first().statusId
        )
        create_reportJob(
            label='second report',
            sysConfigId=test_sysconfig.sysConfigId,
            workflowId=test_workflow.workflowId,
            statusId=JobStatus().query.first().statusId
        )
        test_report_jobs = ReportJob.query.all()
        self.assertIsNotNone(test_report_jobs)
        self.assertEqual(len(test_report_jobs), 2, msg='Expected only two report jobs to exist')

        test_workflow = Workflow.query.first()
        self.assertEqual(len(test_workflow.reportJobs), 2, msg='Expected to be able to find two report jobs for our workflow')
        first_report = test_workflow.reportJobs[0]
        self.assertEqual(first_report.label, 'first report')
Esempio n. 2
0
    def test_sysconfig_input(self):

        create_workflow(label='test workflow')
        test_workflow = Workflow.query.first()
        self.assertIsNotNone(test_workflow.workflowId)

        create_sysConfig(
            label='test sysconfig',
            nixConfigFilename='test.nix',
            nixConfig='{ nix: config }',
            workflowId=test_workflow.workflowId
        )
        self.assertIsNotNone(test_workflow.systemConfigurationInput)
        self.assertEqual(test_workflow.systemConfigurationInput.label, 'test sysconfig')
    def test_create(self):
        test_workflow_label = 'TEST WORKFLOW'
        wf = create_workflow(label=test_workflow_label)

        self.assertIsNotNone(wf.workflowId)
        self.assertIsNone(wf.updatedAt)

        r = SystemConfigurationInput().query.all()
        self.assertListEqual(r, [])

        label = f'created system-config-input {datetime.utcnow()}'
        response = self.client.post(self.BASE_ENDPOINT,
                                    headers=DEFAULT_HEADERS,
                                    data=json.dumps(
                                        dict(label=label,
                                             nixConfigFilename='foo.nix',
                                             nixConfig='{ nix: config }',
                                             workflowId=1)))

        self.assertEqual(response.status_code, 200)
        created_sysconfig = SystemConfigurationInput.query.filter_by(
            label=label).first()
        self.assertIsNotNone(created_sysconfig)

        updated_wf = Workflow.query.filter_by(workflowId=wf.workflowId).first()
        self.assertIsNotNone(updated_wf.updatedAt)
    def test_update_label(self):
        wf = create_workflow(label='test-wf')

        sc = SystemConfigurationInput().query.all()
        self.assertListEqual(sc, [])
        sc = create_sysConfig(label='sc1',
                              nixConfigFilename='foo.nix',
                              nixConfig='{ config: nix }',
                              workflowId=wf.workflowId)

        self.assertEqual(len(SystemConfigurationInput().query.all()), 1)

        response = self.client.put(
            f'{self.BASE_ENDPOINT}/{sc.sysConfigId}',
            headers=DEFAULT_HEADERS,
            data=json.dumps(
                dict(sysConfigId=sc.sysConfigId,
                     label=sc.label + '-NEW',
                     nixConfigFilename=sc.nixConfigFilename,
                     nixConfig=sc.nixConfig,
                     workflowId=sc.workflowId)))

        self.assertEqual(response.status_code, 200)
        updated_sysconfig = SystemConfigurationInput.query.filter_by(
            label='sc1-NEW').first()
        self.assertIsNotNone(updated_sysconfig)
    def setUp(self):
        super(TestReportJobApi, self).setUp()

        JobStatus.load_allowed_statuses()

        w = create_workflow(label='test workflow')

        self.workflowId = w.workflowId
        self.status = JobStatus().query.filter_by(label='running').first()
    def test_get_model(self):
        test_uid = 'TEST_UID'
        test_filename = 'test.fm.json'
        test_conftree = load_test_fmjson()

        fm = create_featureModel(uid=test_uid,
                                 filename=test_filename,
                                 source=test_conftree,
                                 conftree=json.loads(test_conftree))
        create_workflow(label='test workflow')

        wf = Workflow.query.filter_by(label='test workflow').first()
        self.assertIsNotNone(wf)
        fm = FeatureModel.query.filter_by(uid=test_uid).first()
        self.assertIsNotNone(fm)

        vc = create_vulnerabilityConfig(label='test vuln config',
                                        featureModelUid=test_uid,
                                        workflowId=wf.workflowId,
                                        vulnClass='BufferErrors')

        vc = VulnerabilityConfigurationInput.query.filter_by(
            featureModelUid=test_uid).first()
        self.assertIsNotNone(vc)

        response = self.client.post('/api/feature-model/fetch-by-uid',
                                    headers=DEFAULT_HEADERS,
                                    data=json.dumps(dict(model_uid=test_uid)))

        self.assertEqual(response.status_code,
                         200,
                         msg='expected success in request for feature_model')

        json_response = json.loads(response.data)

        self.assertEqual(json_response['uid'],
                         test_uid,
                         msg='expected to get the uid in the return')
        self.assertIsNotNone(json_response['conftree'],
                             msg='expected "conftree" to be populated')
        self.assertDictEqual(json_response['conftree'],
                             json.loads(test_conftree),
                             msg='expected "conftree" to be fully hydrated')
    def test_workflow_relationship(self):
        wf = create_workflow(label='wf')

        test_label = 'test sysconfig'
        create_sysConfig(
            label=test_label,
            nixConfigFilename='foo.nix',
            nixConfig='{ some: config }',
            workflowId=wf.workflowId
        )

        sc = SystemConfigurationInput.query.filter_by(label=test_label).first()

        self.assertIsNotNone(sc)
        self.assertIsNotNone(sc.workflow)
        self.assertEqual(sc.workflow.label, 'wf')
Esempio n. 8
0
    def test_basic_functionality(self):

        wf = create_workflow(label='test workflow')
        jobStatusId = JobStatus.query.filter_by(
            label='running').first().statusId

        self.assertIsNotNone(jobStatusId)

        create_reportJob(label='test report 1',
                         workflowId=wf.workflowId,
                         statusId=jobStatusId)

        testReportJob = ReportJob.query.filter_by(
            workflowId=wf.workflowId).first()

        self.assertIsNotNone(testReportJob)
        self.assertEqual(testReportJob.status.label, 'running')
    def test_update(self):
        test_workflow_label = 'TEST WORKFLOW'
        wf = create_workflow(label=test_workflow_label)

        self.assertIsNotNone(wf.workflowId)
        self.assertIsNone(wf.updatedAt)

        sc = SystemConfigurationInput().query.all()
        self.assertListEqual(sc, [])
        sc = create_sysConfig(label='sc1',
                              nixConfigFilename='foo.nix',
                              nixConfig='{ config: nix }',
                              workflowId=wf.workflowId)

        self.assertEqual(len(SystemConfigurationInput().query.all()), 1)

        label = f'{sc.label}-{datetime.now()}'
        config = f'{sc.nixConfig}-{datetime.now()}'
        filename = f'new-{sc.nixConfigFilename}'
        response = self.client.put(f'{self.BASE_ENDPOINT}/{sc.sysConfigId}',
                                   headers=DEFAULT_HEADERS,
                                   data=json.dumps(
                                       dict(sysConfigId=sc.sysConfigId,
                                            label=label,
                                            nixConfigFilename=filename,
                                            nixConfig=config,
                                            workflowId=sc.workflowId)))

        self.assertEqual(response.status_code, 200)
        updated_sysconfig = SystemConfigurationInput.query.filter_by(
            label=label).first()
        self.assertIsNotNone(updated_sysconfig)
        self.assertEqual(updated_sysconfig.label, label)
        self.assertEqual(updated_sysconfig.nixConfig, config)
        self.assertEqual(updated_sysconfig.nixConfigFilename, filename)
        self.assertNotEqual(updated_sysconfig.updatedAt, db.null())

        updated_wf = Workflow.query.filter_by(workflowId=wf.workflowId).first()
        self.assertIsNotNone(updated_wf.updatedAt)
    def test_attempt_to_change_workflow(self):
        wf = create_workflow(label='INITIAL WORKFLOW')
        self.assertIsNotNone(wf)
        sc = create_sysConfig(
            workflowId=wf.workflowId,
            label='TEST sysconfig',
            nixConfigFilename='test.nix',
            nixConfig='{ nix: "config" }',
        )
        self.assertIsNotNone(sc)

        response = self.client.put(f'{self.BASE_ENDPOINT}/{sc.sysConfigId}',
                                   headers=DEFAULT_HEADERS,
                                   data=json.dumps(
                                       dict(workflowId=sc.workflowId + 1,
                                            sysConfigId=sc.sysConfigId,
                                            label=sc.label,
                                            nixConfigFilename='test.nix',
                                            nixConfig='{ config: "nix" }')))
        self.assertEqual(response.status_code, 400)
        self.assertEqual(response.get_json(), {
            'message': 'Cannot change workflow association',
        })