예제 #1
0
    def test_get_seed_by_id(self, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, SEED_RESOURCE_TYPE)
        self.client.seeds.get_seed_by_id(TEST_SEED_ID)

        mock.assert_called_with(
            f"{SEEDS_URL}/{TEST_SEED_ID}", params={}, timeout=TEST_TIMEOUT
        )
예제 #2
0
    def test_get_logbook_cursor_no_args(self, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, None)
        self.client.events.get_cursor()

        mock.assert_called_with(EVENTS_CURSOR_URL,
                                params={},
                                timeout=TEST_TIMEOUT)
예제 #3
0
    def test_get_seeds_by_type(self, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, SEED_RESOURCE_TYPE)
        self.client.seeds.get_seeds(seed_type=TEST_SEED_TYPE)

        mock.assert_called_with(
            SEEDS_URL, params={"type": TEST_SEED_TYPE}, timeout=TEST_TIMEOUT
        )
예제 #4
0
    def test_delete_seeds_by_label(self, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, SEED_RESOURCE_TYPE)
        self.client.seeds.delete_seeds_by_label(TEST_SEED_LABEL)

        mock.assert_called_with(
            SEEDS_URL, params={"label": TEST_SEED_LABEL}, timeout=TEST_TIMEOUT
        )
예제 #5
0
    def test_replace_seeds_by_label(self, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, SEED_RESOURCE_TYPE)
        self.client.seeds.replace_seeds_by_label(TEST_SEED_LABEL, [TEST_SEED_NO_LABEL])

        mock.assert_called_with(
            SEEDS_URL,
            params={"label": "seed-test-label", "force": False},
            timeout=TEST_TIMEOUT,
            data=json.dumps({"seeds": [TEST_SEED_NO_LABEL]}),
        )
예제 #6
0
    def test_get_events_with_cursor(self, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE,
                                         EVENTS_RESOURCE_TYPE)
        events = self.client.events.get_events(TEST_CURSOR)
        res = [event for event in events]

        self.assertEqual(RESOURCE_PAGING_RESULTS, res)
        mock.assert_called_with(EVENTS_URL,
                                params={"cursor": TEST_CURSOR},
                                timeout=TEST_TIMEOUT)
예제 #7
0
    def test_get_host_by_asset_id(self, asset_type, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, ASSET_TYPE)
        getattr(self.client,
                asset_type).get_asset_by_id(TEST_ASSET_IDS[asset_type])

        mock.assert_called_with(
            f"{ASSETS_URL}/{asset_type}/{TEST_ASSET_IDS[asset_type]}",
            params={},
            timeout=TEST_TIMEOUT,
        )
예제 #8
0
    def test_get_logbook_cursor_with_start_id(self, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, None)
        self.client.events.get_cursor(start=TEST_START_ID)

        mock.assert_called_with(
            EVENTS_CURSOR_URL,
            params={},
            timeout=TEST_TIMEOUT,
            data=json.dumps({"idFrom": TEST_START_ID}),
        )
예제 #9
0
    def test_add_seeds_forced(self, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, SEED_RESOURCE_TYPE)
        self.client.seeds.add_seeds(TEST_SEED_LIST, force=True)

        mock.assert_called_with(
            SEEDS_URL,
            params={"force": True},
            timeout=TEST_TIMEOUT,
            data=json.dumps({"seeds": TEST_SEED_LIST}),
        )
예제 #10
0
    def test_delete_host_tag(self, asset_type, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, ASSET_TYPE)
        getattr(self.client, asset_type).delete_tag(TEST_ASSET_IDS[asset_type],
                                                    TEST_TAG_NAME)

        mock.assert_called_with(
            (f"{ASSETS_URL}/{asset_type}/{TEST_ASSET_IDS[asset_type]}"
             f"/tags/{TEST_TAG_NAME}"),
            params={},
            timeout=TEST_TIMEOUT,
        )
예제 #11
0
    def test_add_host_tag_without_color(self, asset_type, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, ASSET_TYPE)
        getattr(self.client, asset_type).add_tag(TEST_ASSET_IDS[asset_type],
                                                 TEST_TAG_NAME)

        mock.assert_called_with(
            f"{ASSETS_URL}/{asset_type}/{TEST_ASSET_IDS[asset_type]}/tags",
            params={},
            timeout=TEST_TIMEOUT,
            data=json.dumps({"name": TEST_TAG_NAME}),
        )
예제 #12
0
    def test_add_host_comment(self, asset_type, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, COMMENT_TYPE)
        getattr(self.client,
                asset_type).add_comment(TEST_ASSET_IDS[asset_type],
                                        TEST_COMMENT_TEXT)

        mock.assert_called_with(
            f"{ASSETS_URL}/{asset_type}/{TEST_ASSET_IDS[asset_type]}/{COMMENT_TYPE}",
            params={},
            timeout=TEST_TIMEOUT,
            data=json.dumps({"markdown": TEST_COMMENT_TEXT}),
        )
예제 #13
0
    def test_get_comment_by_id(self, asset_type, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, COMMENT_TYPE)
        getattr(self.client,
                asset_type).get_comment_by_id(TEST_ASSET_IDS[asset_type],
                                              TEST_COMMENT_ID)

        mock.assert_called_with(
            (f"{ASSETS_URL}/{asset_type}/{TEST_ASSET_IDS[asset_type]}"
             f"/{COMMENT_TYPE}/{TEST_COMMENT_ID}"),
            params={},
            timeout=TEST_TIMEOUT,
        )
예제 #14
0
    def test_get_logbook_cursor_with_filters(self, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, None)
        filters = [Filters.HOST, Filters.DOMAIN]
        self.client.events.get_cursor(filters=filters)

        mock.assert_called_with(
            EVENTS_CURSOR_URL,
            params={},
            timeout=TEST_TIMEOUT,
            data=json.dumps({"filter": {
                "type": filters
            }}),
        )
예제 #15
0
    def test_get_assets(self, asset_type, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, ASSET_TYPE)
        assets = getattr(self.client, asset_type).get_assets()
        res = [asset for asset in assets]

        self.assertEqual(RESOURCE_PAGING_RESULTS, res)
        mock.assert_called_with(
            f"{ASSETS_URL}/{asset_type}",
            params={
                "pageNumber": 3,
                "pageSize": 500
            },
            timeout=TEST_TIMEOUT,
        )
예제 #16
0
    def test_get_host_comments(self, asset_type, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, COMMENT_TYPE)
        comments = getattr(self.client,
                           asset_type).get_comments(TEST_ASSET_IDS[asset_type])
        res = [comment for comment in comments]

        self.assertEqual(RESOURCE_PAGING_RESULTS, res)
        mock.assert_called_with(
            f"{ASSETS_URL}/{asset_type}/{TEST_ASSET_IDS[asset_type]}/{COMMENT_TYPE}",
            params={
                "pageNumber": 3,
                "pageSize": 500
            },
            timeout=TEST_TIMEOUT,
        )
예제 #17
0
    def test_get_logbook_cursor_with_filters_and_start_id(self, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, None)
        filters = [Filters.HOST, Filters.HOST_CERT]
        self.client.events.get_cursor(start=TEST_START_ID, filters=filters)

        mock.assert_called_with(
            EVENTS_CURSOR_URL,
            params={},
            timeout=TEST_TIMEOUT,
            data=json.dumps({
                "filter": {
                    "type": filters
                },
                "idFrom": TEST_START_ID
            }),
        )
예제 #18
0
    def test_get_hosts_by_page(self, asset_type, mock):
        mock.return_value = MockResponse(TEST_SUCCESS_CODE, ASSET_TYPE,
                                         TEST_PAGE_NUMBER)
        assets = getattr(self.client,
                         asset_type).get_assets(page_number=TEST_PAGE_NUMBER,
                                                page_size=TEST_PAGE_SIZE)
        res = [asset for asset in assets]

        self.assertEqual(RESOURCE_PAGING_RESULTS[:6], res)
        self.assertNotEqual(1,
                            mock.call_args_list[0][1]["params"]["pageNumber"])
        mock.assert_called_with(
            f"{ASSETS_URL}/{asset_type}",
            params={
                "pageNumber": 3,
                "pageSize": 2
            },
            timeout=TEST_TIMEOUT,
        )