Exemplo n.º 1
0
    def test_chain_retrieval_failure(self):
        err_msg = "Chain does not exist"

        with requests_mock.mock() as mock_http:
            mock_http.get(
                "{}/alerttriagechain".format(self.mock_api_base),
                status_code=500,
                json={
                    "error": err_msg,
                    "identifiers": [],
                    "created": "2020/02/19 1:23:45",
                    "modified": "2020/02/19 1:23:45",
                },
            )

            try:
                bot._retrieve_duplicate_chain(
                    bot.RESTConfig(self.mock_api_base, self.mock_api_token),
                    bot.AlertLabel.SSH_ACCESS_SIGN_RELENG,
                    bot.Email("*****@*****.**"),
                )
            except bot.APIError as err:
                assert err.message == err_msg
                return

            assert False  # Shouldn't get here
Exemplo n.º 2
0
    def test_chain_update(self):
        with requests_mock.mock() as mock_http:
            mock_http.put("{}/alerttriagechain".format(self.mock_api_base),
                          json={"error": None})

            success = bot._update_duplicate_chain(
                bot.RESTConfig(self.mock_api_base, self.mock_api_token),
                bot.AlertLabel.DUO_BYPASS_CODES_GENERATED,
                bot.Email("*****@*****.**"),
                ["testid123"],
            )

            assert success
Exemplo n.º 3
0
    def test_chain_update_failure(self):
        err_msg = "No such chain exists"

        with requests_mock.mock() as mock_http:
            mock_http.put(
                "{}/alerttriagechain".format(self.mock_api_base),
                json={"error": err_msg},
            )

            try:
                bot._update_duplicate_chain(
                    bot.RESTConfig(self.mock_api_base, self.mock_api_token),
                    bot.AlertLabel.SENSITIVE_HOST_SESSION,
                    bot.Email("*****@*****.**"),
                    ["testid123"],
                )
            except bot.APIError as err:
                assert err.message == err_msg
                return

            assert False  # Shouldn't get here
Exemplo n.º 4
0
    def test_chain_retrieval(self):
        with requests_mock.mock() as mock_http:
            mock_http.get(
                "{}/alerttriagechain".format(self.mock_api_base),
                json={
                    "error": None,
                    "identifiers": ["id123"],
                    "created": "2020/02/19 1:23:45",
                    "modified": "2020/02/19 1:23:45",
                },
            )

            chain = bot._retrieve_duplicate_chain(
                bot.RESTConfig(self.mock_api_base, self.mock_api_token),
                bot.AlertLabel.SENSITIVE_HOST_SESSION,
                bot.Email("*****@*****.**"),
            )

            assert len(chain.identifiers) == 1
            assert chain.identifiers[0] == "id123"
            assert chain.created.year == 2020
            assert chain.modified.day == 19