コード例 #1
0
    def test_bro(self):
        response = self.client.get('/admin/bro/bro/add/', follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(Bro.get_all()), 1)
        response = self.client.post('/admin/bro/bro/add/', {
            'name': 'test',
            'secure_deployment': True,
            'scheduled_rules_deployment_enabled': True,
            'scheduled_rules_deployment_crontab': 4,
            'scheduled_check_enabled': True,
            'scheduled_check_crontab': 3,
            'server': 1,
            'rulesets': 101,
            'configuration': 101,
            'installed': True
        },
                                    follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn(' was added successfully', str(response.content))
        self.assertEqual(len(Bro.get_all()), 2)
        response = self.client.post(
            '/admin/bro/bro/', {
                'action': 'test_rules',
                '_selected_action': Bro.get_by_name('test').id
            },
            follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('Test rules OK', str(response.content))

        response = self.client.post('/admin/bro/scriptbro/add/', {
            'rev': '0',
            'rule_full': 'erererooepeoerrrr',
            'name': 'fail script test',
        },
                                    follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertNotIn('was added successfully', str(response.content))
        self.assertIn('Test script failed', str(response.content))

        response = self.client.post('/admin/bro/signaturebro/add/', {
            'rev': '0',
            'rule_full': '1',
            'sid': '666',
            'msg': 'fail test',
        },
                                    follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('was added successfully', str(response.content))
        self.assertIn('Test signature failed', str(response.content))
        sig = SignatureBro.get_by_msg('fail test')
        ruleset = RuleSetBro.get_by_id(101)
        ruleset.signatures.add(sig)
        ruleset.save()
        response = self.client.post(
            '/admin/bro/bro/', {
                'action': 'test_rules',
                '_selected_action': Bro.get_by_name('test').id
            },
            follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('Test rules failed', str(response.content))

        self.assertTrue(Bro.get_by_name('test').installed)
        response = self.client.post(
            '/admin/bro/bro/' + str(Bro.get_by_name('test').id) + '/change/', {
                'name': 'test',
                'secure_deployment': True,
                'scheduled_rules_deployment_enabled': True,
                'scheduled_rules_deployment_crontab': 4,
                'scheduled_check_enabled': True,
                'scheduled_check_crontab': 3,
                'server': 1,
                'rulesets': 101,
                'configuration': 101,
                'installed': False
            },
            follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn(' was changed successfully', str(response.content))
        self.assertFalse(Bro.get_by_name('test').installed)
        response = self.client.post(
            '/admin/bro/bro/', {
                'action': 'delete_selected',
                '_selected_action': Bro.get_by_name('test').id
            },
            follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('Are you sure you want to delete the selected ',
                      str(response.content))
        response = self.client.post(
            '/admin/bro/bro/', {
                'action': 'delete_selected',
                '_selected_action': Bro.get_by_name('test').id,
                'post': 'yes'
            },
            follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('Successfully deleted 1 ', str(response.content))

        self.assertEqual(len(Bro.get_all()), 1)

        response = self.client.post('/admin/bro/bro/add/', {
            'name': 'test',
            'secure_deployment': True,
            'scheduled_rules_deployment_enabled': True,
            'scheduled_rules_deployment_crontab': 4,
            'scheduled_check_enabled': True,
            'scheduled_check_crontab': 3,
            'server': 1,
            'rulesets': 101,
            'configuration': 101,
            'installed': True
        },
                                    follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn(' was added successfully', str(response.content))
        response = self.client.get(
            '/admin/bro/bro/' + str(Bro.get_by_name('test').id) + '/delete/',
            follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('Are you sure ', str(response.content))
        response = self.client.post(
            '/admin/bro/bro/' + str(Bro.get_by_name('test').id) + '/delete/',
            {'post': 'yes'},
            follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertIn('was deleted successfully', str(response.content))
        self.assertEqual(len(Bro.get_all()), 1)
コード例 #2
0
    def test_bro(self):
        response = self.client.get('/api/v1/bro/bro/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], 1)

        data = {'name': 'test',
                'secure_deployment': True,
                'scheduled_rules_deployment_enabled': True,
                'scheduled_rules_deployment_crontab': 4,
                'scheduled_check_enabled': True,
                'scheduled_check_crontab': 3,
                'server': 1,
                'rulesets': [101, ],
                'configuration': 101,
                'installed': True}

        data_put = {'name': 'test',
                    'secure_deployment': True,
                    'server': 1,
                    'rulesets': [101, ],
                    'configuration': 101,
                    'installed': False}

        data_patch = {'installed': True}

        response = self.client.post('/api/v1/bro/bro/', data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        response = self.client.post('/api/v1/bro/bro/', {'name': 'test'})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

        response = self.client.get('/api/v1/bro/bro/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], 2)

        self.assertTrue(PeriodicTask.objects.get(name="test_deploy_rules_" + str(CrontabSchedule.objects.get(id=4))))
        self.assertTrue(PeriodicTask.objects.get(name="test_check_task"))

        response = self.client.put('/api/v1/bro/bro/' + str(Bro.get_by_name('test').id) + '/', data_put)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertFalse(Bro.get_by_name('test').installed)

        response = self.client.put('/api/v1/bro/bro/' + str(Bro.get_by_name('test').id) + '/', {'name': 'test'})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

        response = self.client.patch('/api/v1/bro/bro/' + str(Bro.get_by_name('test').id) + '/', {'configuration': 'test'})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

        response = self.client.patch('/api/v1/bro/bro/' + str(Bro.get_by_name('test').id) + '/', data_patch)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(Bro.get_by_name('test').installed)

        response = self.client.patch('/api/v1/bro/bro/' + str(Bro.get_by_name('test').id) + '/',
                                     {'scheduled_rules_deployment_enabled': False})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(Bro.get_by_name('test').scheduled_rules_deployment_enabled)

        response = self.client.delete('/api/v1/bro/bro/' + str(Bro.get_by_name('test').id) + '/')
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        response = self.client.get('/api/v1/bro/bro/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], 1)

        with self.assertRaises(ObjectDoesNotExist):
            PeriodicTask.objects.get(name="test_deploy_rules_" + str(CrontabSchedule.objects.get(id=4)))
        with self.assertRaises(ObjectDoesNotExist):
            PeriodicTask.objects.get(name="test_check_task")

        response = self.client.get('/api/v1/bro/bro/101/test_rules/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(response.data['status'])

        response = self.client.get('/api/v1/bro/bro/101/start/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(response.data['status'])

        response = self.client.get('/api/v1/bro/bro/101/stop/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(response.data['status'])

        response = self.client.get('/api/v1/bro/bro/101/restart/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(response.data['status'])

        response = self.client.get('/api/v1/bro/bro/101/reload/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(response.data['status'])

        response = self.client.get('/api/v1/bro/bro/101/status/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(response.data['status'])

        response = self.client.get('/api/v1/bro/bro/101/uptime/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(response.data['uptime'])

        response = self.client.get('/api/v1/bro/bro/101/deploy_rules/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(response.data['status'])

        response = self.client.get('/api/v1/bro/bro/101/deploy_conf/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(response.data['status'])