Beispiel #1
0
    def test_dcd_not_found_if_not_super_user(
        self,
        monkeypatch: MonkeyPatch,
        mock_livestatus: MockLiveStatusConnection,
    ):
        """
        This test ensures that test_index_is_built_as_super_user makes sense, ie. that if we do not
        build as a super user, the entry "Custom host attributes" is not found.
        """

        @contextmanager
        def SuperUserContext() -> Iterator[None]:
            yield

        monkeypatch.setattr(
            search,
            "SuperUserContext",
            SuperUserContext,
        )

        with _UserContext(LoggedInNobody()):
            builder = IndexBuilder(real_match_item_generator_registry)
            with self._livestatus_mock(mock_livestatus):
                builder.build_full_index()

        searcher = IndexSearcher()
        searcher._redis_client = builder._redis_client
        assert not list(searcher.search("custom host attributes"))
    def test_real_search_without_exception(self, mock_livestatus) -> None:
        builder = IndexBuilder(real_match_item_generator_registry)

        with self._livestatus_mock(mock_livestatus):
            builder.build_full_index()

        assert builder.index_is_built(builder._redis_client)

        searcher = IndexSearcher()
        searcher._redis_client = builder._redis_client

        assert len(list(searcher.search("Host"))) > 4
Beispiel #3
0
    def test_real_search_without_exception(
        self,
        mock_livestatus: MockLiveStatusConnection,
    ) -> None:
        builder = IndexBuilder(real_match_item_generator_registry)

        with self._livestatus_mock(mock_livestatus):
            builder.build_full_index()

        assert builder.index_is_built(builder._redis_client)

        searcher = IndexSearcher(
            PermissionsHandler(URLChecker[ModeEditHost](ModeEditHost)))
        searcher._redis_client = builder._redis_client

        assert len(list(searcher.search("Host"))) > 4
Beispiel #4
0
    def test_index_is_built_as_super_user(
        self,
        mock_livestatus: MockLiveStatusConnection,
    ):
        """
        We test that the index is always built as a super user.
        """

        with _UserContext(LoggedInNobody()):
            builder = IndexBuilder(real_match_item_generator_registry)
            with self._livestatus_mock(mock_livestatus):
                builder.build_full_index()

        searcher = IndexSearcher()
        searcher._redis_client = builder._redis_client

        # if the search index did not internally use the super user while building, this item would
        # be missing, because the match item generator for the setup menu only yields entries which
        # the current user is allowed to see
        assert list(searcher.search("custom host attributes"))
Beispiel #5
0
def fixture_index_searcher(index_builder: IndexBuilder) -> IndexSearcher:
    index_searcher = IndexSearcher()
    index_searcher._redis_client = index_builder._redis_client
    return index_searcher
Beispiel #6
0
def fixture_index_searcher(index_builder: IndexBuilder) -> IndexSearcher:
    index_searcher = IndexSearcher(
        PermissionsHandler(URLChecker[ModeEditHost](ModeEditHost)))
    index_searcher._redis_client = index_builder._redis_client
    return index_searcher