def test_custom_fields_field_name_cant_be_changed(self, session, test_client): add_text_field = CustomFieldsSchemaFactory.create( table_name='vulnerability', field_name='cvss', field_type='str', field_order=1, field_display_name='CVSS', ) session.add(add_text_field) session.commit() data = { u'field_name': u'cvss 2', u'field_type': 'int', u'talbe_name': 'sarasa', u'field_display_name': u'CVSS new', u'field_order': 1 } res = test_client.put(self.url(add_text_field.id), data=data) assert res.status_code == 200 custom_field_obj = session.query(CustomFieldsSchema).filter_by( id=add_text_field.id).first() assert custom_field_obj.field_name == 'cvss' assert custom_field_obj.table_name == 'vulnerability' assert custom_field_obj.field_type == 'str' assert custom_field_obj.field_display_name == 'CVSS new'
def test_update_custom_field(self, api, session, test_client): workspace = WorkspaceFactory.create() custom_field = CustomFieldsSchemaFactory.create( table_name='vulnerability', field_name='cfield', field_type='str', field_order=1, field_display_name='CField', ) vuln = VulnerabilityFactory.create(workspace=workspace, severity='low', confirmed=True) vuln.custom_fields = {'cfield': 'test'} session.add(workspace) session.add(custom_field) session.add(vuln) session.commit() assert vuln.confirmed is True searcher = Searcher(api(workspace, test_client, session)) rules = [{ 'id': 'CHANGE_CUSTOM_FIELD', 'model': 'Vulnerability', 'object': "severity=low", 'conditions': ['confirmed=True'], 'actions': ["--UPDATE:cfield=CUSTOM_FIELD_UPDATED"] }] searcher.process(rules) vulns_count = session.query(Vulnerability).filter_by(workspace=workspace).count() assert vulns_count == 1 vuln = session.query(Vulnerability).filter_by(workspace=workspace).first() assert vuln.custom_fields['cfield'] == 'CUSTOM_FIELD_UPDATED' check_command(vuln, session)
def test_custom_fields_data(self, session, test_client): add_text_field = CustomFieldsSchemaFactory.create( table_name='vulnerability', field_name='cvss', field_type='text', field_order=1, field_display_name='CVSS', ) session.add(add_text_field) session.commit() res = test_client.get(self.url()) assert res.status_code == 200 assert {'table_name': 'vulnerability', 'id': add_text_field.id, 'field_type': 'text', 'field_name': 'cvss', 'field_display_name': 'CVSS', 'field_metadata': None, 'field_order': 1} in res.json
def test_add_custom_fields_with_metadata(self, session, test_client): add_choice_field = CustomFieldsSchemaFactory.create( table_name='vulnerability', field_name='gender', field_type='choice', field_metadata=['Male', 'Female'], field_order=1, field_display_name='Gender', ) session.add(add_choice_field) session.commit() res = test_client.get(self.url()) assert res.status_code == 200 assert {'table_name': 'vulnerability', 'id': add_choice_field.id, 'field_type': 'choice', 'field_name': 'gender', 'field_display_name': 'Gender', 'field_metadata': "['Male', 'Female']", 'field_order': 1} in res.json