Пример #1
0
 def test_input_request_to_homepage_should_be_logged_in_elasticsearch_backend(self, user):
     with log_with_data(related_objects=[user]):
         with capture_security_logs() as logged_data:
             assert_http_ok(self.get('/home/?name=value'))
             elasticsearch_input_request_log = ElasticsearchInputRequestLog.get(
                 id=logged_data.input_request[0].id
             )
             assert_equal_model_fields(
                 elasticsearch_input_request_log,
                 request_headers='{"Cookie": "[Filtered]"}',
                 request_body='',
                 user_id=None,
                 method='GET',
                 host='testserver',
                 path='/home/',
                 queries='{"name": "value"}',
                 is_secure=False,
                 ip='127.0.0.1',
                 view_slug='home',
                 slug=None,
                 time=(elasticsearch_input_request_log.stop - elasticsearch_input_request_log.start).total_seconds(),
                 extra_data={},
                 error_message=None,
                 response_code=200,
                 response_headers='{"Content-Type": "text/html; charset=utf-8", "X-Frame-Options": "DENY"}',
                 response_body='home page response',
                 state=RequestLogState.INFO,
             )
             assert_equal(
                 [rel_obj for rel_obj in elasticsearch_input_request_log.related_objects],
                 ['default|3|{}'.format(user.id)]
             )
Пример #2
0
 def test_input_request_to_homepage_should_be_logged_in_sql_backend(self, user):
     with log_with_data(related_objects=[user]):
         assert_http_ok(self.get('/home/?name=value'))
         assert_equal(SQLInputRequestLog.objects.count(), 1)
         sql_input_request_log = SQLInputRequestLog.objects.get()
         assert_equal_model_fields(
             sql_input_request_log,
             request_headers={'Cookie': '[Filtered]'},
             request_body='',
             user_id=None,
             method='GET',
             host='testserver',
             path='/home/',
             queries={'name': 'value'},
             is_secure=False,
             ip='127.0.0.1',
             view_slug='home',
             slug=None,
             time=(sql_input_request_log.stop - sql_input_request_log.start).total_seconds(),
             extra_data={},
             error_message=None,
             response_code=200,
             response_headers={'Content-Type': 'text/html; charset=utf-8', 'X-Frame-Options': 'DENY'},
             response_body='home page response',
             state=RequestLogState.INFO,
         )
         assert_equal([rel_obj.object for rel_obj in sql_input_request_log.related_objects.all()], [user])
Пример #3
0
 def test_input_request_to_404_page_should_be_logged_in_sql_backend(self):
     assert_http_not_found(self.get('/404/'))
     assert_equal(SQLInputRequestLog.objects.count(), 1)
     sql_input_request_log = SQLInputRequestLog.objects.get()
     assert_equal_model_fields(
         sql_input_request_log,
         response_code=404,
         state=RequestLogState.WARNING,
     )
Пример #4
0
 def test_input_request_to_404_page_should_be_logged_in_elasticsearch_backend(self):
     with capture_security_logs() as logged_data:
         assert_http_not_found(self.get('/404/'))
         elasticsearch_input_request_log = ElasticsearchInputRequestLog.get(
             id=logged_data.input_request[0].id
         )
         assert_equal_model_fields(
             elasticsearch_input_request_log,
             response_code=404,
             state=RequestLogState.WARNING,
         )
Пример #5
0
 def test_input_request_to_error_page_should_be_logged_in_sql_backend(self):
     with assert_raises(RuntimeError):
         self.get('/error/')
     assert_equal(SQLInputRequestLog.objects.count(), 1)
     sql_input_request_log = SQLInputRequestLog.objects.get()
     assert_equal_model_fields(
         sql_input_request_log,
         method='GET',
         path='/error/',
         time=(sql_input_request_log.stop - sql_input_request_log.start).total_seconds(),
         response_code=500,
         state=RequestLogState.ERROR,
     )
     assert_is_not_none(sql_input_request_log.error_message)
Пример #6
0
 def test_input_request_to_error_page_should_be_logged_in_elasticsearch_backend(self):
     with capture_security_logs() as logged_data:
         with assert_raises(RuntimeError):
             self.get('/error/')
         elasticsearch_input_request_log = ElasticsearchInputRequestLog.get(
             id=logged_data.input_request[0].id
         )
         assert_equal_model_fields(
             elasticsearch_input_request_log,
             method='GET',
             path='/error/',
             time=(elasticsearch_input_request_log.stop - elasticsearch_input_request_log.start).total_seconds(),
             response_code=500,
             state=RequestLogState.ERROR,
         )
         assert_is_not_none(elasticsearch_input_request_log.error_message)
Пример #7
0
 def test_error_command_should_be_logged_in_sql_backend(self, user):
     with log_with_data(related_objects=[user]):
         with assert_raises(RuntimeError):
             test_call_command('test_error_command')
         assert_equal(SQLCommandLog.objects.count(), 1)
         sql_command_log = SQLCommandLog.objects.get()
         assert_equal_model_fields(
             sql_command_log,
             name='test_error_command',
             input='',
             is_executed_from_command_line=False,
             time=(sql_command_log.stop - sql_command_log.start).total_seconds(),
             state=CommandState.FAILED,
             output=None,
         )
         assert_is_not_none(sql_command_log.error_message)
         assert_equal([rel_obj.object for rel_obj in sql_command_log.related_objects.all()], [user])
Пример #8
0
 def test_command_should_be_logged_in_sql_backend(self, user):
     with log_with_data(related_objects=[user]):
         test_call_command('test_command', verbosity=0)
         assert_equal(SQLCommandLog.objects.count(), 1)
         sql_command_log = SQLCommandLog.objects.get()
         assert_equal_model_fields(
             sql_command_log,
             name='test_command',
             input='verbosity=0',
             is_executed_from_command_line=False,
             time=(sql_command_log.stop - sql_command_log.start).total_seconds(),
             state=CommandState.SUCCEEDED,
             error_message=None,
         )
         assert_is_not_none(sql_command_log.output)
         assert_equal([rel_obj.object for rel_obj in sql_command_log.related_objects.all()], [user])
         assert_equal(get_logs_related_with_object(LoggerName.COMMAND, user), [sql_command_log])
Пример #9
0
 def test_error_command_should_be_logged_in_elasticsearch_backend(self, user):
     with capture_security_logs() as logged_data:
         with log_with_data(related_objects=[user]):
             with assert_raises(RuntimeError):
                 test_call_command('test_error_command')
             elasticsearch_command_log = ElasticsearchCommandLog.get(
                 id=logged_data.command[0].id
             )
             assert_equal_model_fields(
                 elasticsearch_command_log,
                 name='test_error_command',
                 input='',
                 is_executed_from_command_line=False,
                 time=(elasticsearch_command_log.stop - elasticsearch_command_log.start).total_seconds(),
                 state=CommandState.FAILED,
                 output=None,
             )
             assert_is_not_none(elasticsearch_command_log.error_message)
             assert_equal(
                 [rel_obj for rel_obj in elasticsearch_command_log.related_objects],
                 ['default|3|{}'.format(user.id)]
             )
Пример #10
0
 def test_command_should_be_logged_in_elasticsearch_backend(self, user):
      with capture_security_logs() as logged_data:
         with log_with_data(related_objects=[user]):
             test_call_command('test_command', verbosity=0)
             elasticsearch_command_log = ElasticsearchCommandLog.get(
                 id=logged_data.command[0].id
             )
             assert_equal_model_fields(
                 elasticsearch_command_log,
                 name='test_command',
                 input='verbosity=0',
                 is_executed_from_command_line=False,
                 time=(elasticsearch_command_log.stop - elasticsearch_command_log.start).total_seconds(),
                 state=CommandState.SUCCEEDED,
                 error_message=None,
             )
             assert_is_not_none(elasticsearch_command_log.output)
             assert_equal(
                 [rel_obj for rel_obj in elasticsearch_command_log.related_objects],
                 ['default|3|{}'.format(user.id)]
             )
             ElasticsearchCommandLog._index.refresh()
             assert_equal(get_logs_related_with_object(LoggerName.COMMAND, user), [elasticsearch_command_log])