Example #1
0
    def test_clean_indicators_ip(self):
        post = {}
        post['indicators'] = self.ip_indicator
        post['record_type'] = "ip"
        form = MonitorSubmission(post)

        # This creates the cleaned_data attribute on the form. This is how Django normalizes and stores form input.
        form.is_valid()

        # This method uses cleaned_data.get() to return the lower case indicator value.
        self.assertTrue(self.ip_indicator in form.valid_ips)
Example #2
0
    def test_clean_indicators_single(self):
        post = {}
        post['indicators'] = "TWITTER.COM"
        post['record_type'] = "domain"
        form = MonitorSubmission(post)

        # This creates the cleaned_data attribute on the form. This is how Django normalizes and stores form input.
        form.is_valid()

        # This method uses cleaned_data.get() to return the lower case indicator value.
        self.assertTrue("twitter.com" in form.valid_domains)
        self.assertFalse("TWITTER.COM" in form.valid_domains)
Example #3
0
    def test_clean_indicators_distinguish_ip_from_domain(self):
        post = {}
        post['indicators'] = self.ip_indicator
        post['record_type'] = "ip"
        form = MonitorSubmission(post)

        # This creates the cleaned_data attribute on the form. This is how Django normalizes and stores form input.
        form.is_valid()

        # This method uses cleaned_data.get() to return the lower case indicator value.
        # The IP indicator should not be in the domain list.
        self.assertFalse(self.ip_indicator in form.valid_domains)
        self.assertTrue(self.ip_indicator in form.valid_ips)
Example #4
0
    def test_save_submission_domain(self):
        factory = RequestFactory()
        url = reverse("add_indicators")
        request = factory.get(url)

        # Even though we have a request, we still need to submit a post with an indicator to save.
        post = {}
        post['indicators'] = self.indicator
        post['record_type'] = "domain"
        form = MonitorSubmission(post)

        # This creates the cleaned_data attribute on the form. This is how Django normalizes and stores form input.
        form.is_valid()

        # Attach a user to the request, save the record, and then retreive it.
        request.user = Profile.objects.create_user(email='*****@*****.**', password='******', is_admin=False)
        MonitorSubmission.save_submission(form, request)
        record = DomainMonitor.objects.filter(owner=request.user)
        self.assertIsNotNone(record)
Example #5
0
 def test_valid_monitor_submission_form(self):
     post = {}
     post['indicators'] = self.indicator
     post['indicator_type'] = "domain"
     form = MonitorSubmission(post)
     self.assertTrue(form.is_valid())