def test_validate_input_args_throws_excpetion_for_strings_exceeding_max_length(
):
    arg_value = 'x' * 256
    with pytest.raises(InvalidInputException) as exc_info:
        validate_input_args(arg_value)
    assert f'input value: {arg_value} exceeds allowed length of 255 characters' == str(
        exc_info.value)
Exemple #2
0
def get_single_person_details():
    """
    This endpoint takes person's name as the argument and pulls details for the person from db.
    additionally, it splits person's favourite food into fruits and vegetables
    :return:
    """
    name = request.args.get('name')
    if name is None:
        raise InvalidInputException(
            'Name is missing for person details lookup')

    # apply basic validations, to avoid sql inject, XSS, bffer overflow attacks
    validate_input_args(name)

    people_details = get_details_for_single_person(name)
    return make_response(people_details, 200)
Exemple #3
0
def get_multiple_people_details():
    """
    This endpoint takes 2 query params: name1 and name2 as names of 2 people
    Then it returns details of both the persons as well as their mutual friends that are alive and have brown eyes
    :return:
    """
    name1 = request.args.get('name1')
    name2 = request.args.get('name2')
    if name1 is None or name2 is None:
        raise InvalidInputException('One or both person names are missing')

    # apply basic validations, to avoid sql inject, XSS, bffer overflow attacks
    validate_input_args(name1, name2)

    people_details = get_details_for_two_people(name1=name1, name2=name2)
    return make_response(people_details, 200)
Exemple #4
0
def get_employee_details_company():
    """
    This endpoint takes a company name and return employees associated with tha company
    If no employee is present, then kit returns employee count as 0 and empty list for employees
    :return:
    """
    company_name = request.args.get('company')
    if company_name is None:
        raise InvalidInputException(
            'Mandatory request attribute: company_name is missing')

    # apply basic validations, to avoid sql inject, XSS, bffer overflow attacks
    validate_input_args(company_name)

    employee_details = get_employees_for_company(company_name)
    return make_response(employee_details, 200)
def test_validate_input_args_throws_exception_for_non_allowed_characters():
    arg_value = 'Invalida$arg$value'
    with pytest.raises(InvalidInputException) as exc_info:
        validate_input_args(arg_value)
    assert f'Input value: {arg_value} does not match expected pattern and is not alphanumeric' == str(
        exc_info.value)
def test_validate_input_args_handles_multiple_values():
    arg_values = ['abc', 'x' * 256]
    with pytest.raises(InvalidInputException) as exc_info:
        validate_input_args(*arg_values)
    assert f'input value: {arg_values[1]} exceeds allowed length of 255 characters' == str(
        exc_info.value)