def setUp(self): testuser = User.objects.get(username='******') token = Token.objects.get(user=testuser) self.client = APIClient() self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key) self.url = reverse(self.viewname + '-list') self.current_findings = self.client.get(self.url, format='json').data["results"] finding = Finding.objects.get(id=self.current_findings[0]['id']) self.base_url = f"{self.url}{self.current_findings[0]['id']}/metadata/" metadata = DojoMeta(finding=finding, name="test_meta", value="20") metadata.save()
def add_meta_data(request, pid): prod = Product.objects.get(id=pid) if request.method == 'POST': form = DojoMetaDataForm(request.POST, instance=DojoMeta(product=prod)) if form.is_valid(): form.save() messages.add_message(request, messages.SUCCESS, 'Metadata added successfully.', extra_tags='alert-success') if 'add_another' in request.POST: return HttpResponseRedirect( reverse('add_meta_data', args=(pid, ))) else: return HttpResponseRedirect( reverse('view_product', args=(pid, ))) else: form = DojoMetaDataForm() product_tab = Product_Tab(pid, title="Add Metadata", tab="settings") return render(request, 'dojo/add_product_meta_data.html', { 'form': form, 'product_tab': product_tab, 'product': prod, })
def add_meta_data(request, eid): endpoint = Endpoint.objects.get(id=eid) if request.method == 'POST': form = DojoMetaDataForm(request.POST, instance=DojoMeta(endpoint=endpoint)) if form.is_valid(): form.save() messages.add_message(request, messages.SUCCESS, 'Metadata added successfully.', extra_tags='alert-success') if 'add_another' in request.POST: return HttpResponseRedirect( reverse('add_meta_data', args=(eid, ))) else: return HttpResponseRedirect( reverse('view_endpoint', args=(eid, ))) else: form = DojoMetaDataForm() add_breadcrumb(parent=endpoint, title="Add Metadata", top_level=False, request=request) product_tab = Product_Tab(endpoint.product.id, "Add Metadata", tab="endpoints") return render(request, 'dojo/add_endpoint_meta_data.html', { 'form': form, 'product_tab': product_tab, 'endpoint': endpoint, })
def handle(self, *args, **options): ctp = ContentType.objects.get_for_model(Product.objects.all()[0]) cte = ContentType.objects.get_for_model(Endpoint.objects.all()[0]) legacy_meta_prod = CustomField.objects.filter(content_type=ctp) legacy_meta_ep = CustomField.objects.filter(content_type=cte) for cf in legacy_meta_prod: cfv = CustomFieldValue.objects.filter(field=cf, ) dm = DojoMeta(name=cf.name, value=cfv.first().value, model_name='Product', model_id=cfv.first().object_id) dm.save() for cf in legacy_meta_ep: cfv = CustomFieldValue.objects.filter(field=cf, ) dm = DojoMeta(name=cf.name, value=cfv.first().value, model_name='Endpoint', model_id=cfv.first().object_id) dm.save()
def validate(self, data): DojoMeta(**data).clean() return data