示例#1
0
    def test_validate_fetch_incidents_params_when_first_fetch_is_invalid(self):
        """Test case scenario when argument named first_fetch is invalid."""
        from Flashpoint import validate_fetch_incidents_params

        with pytest.raises(ValueError) as err:
            validate_fetch_incidents_params({"first_fetch": "abc"}, {})
        assert str(err.value) == INVALID_DATE_MESSAGE

        with pytest.raises(ValueError) as err:
            validate_fetch_incidents_params({"first_fetch": None}, {})
        assert str(err.value) == MESSAGES['INVALID_FIRST_FETCH']
示例#2
0
    def test_validate_fetch_incidents_params_when_max_fetch_is_invalid(self):
        """Test case scenario when argument named max_fetch is invalid."""
        from Flashpoint import validate_fetch_incidents_params

        with pytest.raises(ValueError) as err:
            validate_fetch_incidents_params({"max_fetch": "abc"}, {})
        assert str(err.value) == '"abc" is not a valid number'

        with pytest.raises(ValueError) as err:
            validate_fetch_incidents_params({"max_fetch": ""}, {})
        assert str(err.value) == MESSAGES['INVALID_MAX_FETCH'].format('None')
示例#3
0
    def test_validate_fetch_incidents_params_when_valid_params_are_provided(
            self):
        """Test case scenario when the arguments provided are valid."""
        from Flashpoint import validate_fetch_incidents_params

        params = {
            'fetch_type': 'Alerts',
            'first_fetch': START_DATE,
            'max_fetch': '20',
            'is_fresh_compromised_credentials': False
        }
        fetch_params = {
            'size': 20,
            'since': START_DATE,
        }
        expected_params = {
            'fetch_type': 'Alerts',
            'start_time': START_DATE,
            'fetch_params': fetch_params
        }

        assert validate_fetch_incidents_params(params, {}) == expected_params

        del params['fetch_type']
        start_time = '2021-08-04T10:10:00Z'
        last_run = {
            'fetch_count': 1,
            'end_time': '2021-08-05T03:43:52Z',
            'start_time': start_time,
            'fetch_sum': 20
        }
        fetch_params = {
            'limit':
            20,
            'query':
            '+basetypes:(credential-sighting) +header_.indexed_at: [1628071800'
            ' TO 1628135032]',
            'skip':
            20,
            'sort':
            'header_.indexed_at:asc'
        }
        expected_params = {
            'fetch_type': 'Compromised Credentials',
            'start_time': start_time,
            'fetch_params': fetch_params
        }

        assert validate_fetch_incidents_params(params,
                                               last_run) == expected_params