Exemplo n.º 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"))
Exemplo n.º 2
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"))