Beispiel #1
0
def test_validate_empty_distinguished_name():
    """ensures a failure occurs when 'distinguished_name' field is empty"""
    with pytest.raises(LdapValidationException) as response:
        next_payload = {
            "data": {
                "distinguished_name": ""
            },
            "data_type": "user"
        }
        ldap_message_validator.validate_next_payload(next_payload)
        assert response == "'data'.'distinguished_name' cannot be empty"
Beispiel #2
0
def test_validate_invalid_data_type():
    """ensures a failure occurs when 'data_type' field is invalid"""
    with pytest.raises(LdapValidationException) as response:
        next_payload = {
            "data": {
                "distinguished_name": "yo"
            },
            "data_type": "no"
        }
        ldap_message_validator.validate_next_payload(next_payload)
        assert (
            response ==
            "Invalid value for 'data_type'. 'data_type' must be in: ['user', 'group']"
        )
Beispiel #3
0
def validate_and_export(next_payload):
    """Validates and exports the NEXT payload to Active Directory"""
    # TODO: Determine what to do with inadequate ldap data in the queue. Log and drop?

    LOGGER.debug("Validating: %s", str(next_payload))
    validate_next_payload(next_payload)

    try:
        LOGGER.info("Transmitting: %s", str(next_payload))
        yield from (connect_and_transfer(next_payload))
        return True
    except LdapConnectionException as lce:
        LOGGER.error(lce)

    return False
Beispiel #4
0
def _validate_and_export_to_active_dir(content):
    """Validates and exports the NEXT payload to Active Directory"""
    # TODO: Determine what to do with inadequate ldap data in the queue. Log and drop?

    LOGGER.debug("Validating: %s", str(content))
    validate_next_payload(content)

    try:
        LOGGER.debug("Transmitting: %s", str(content))
        yield from _transfer_outbound_record_to_active_dir(content)

        return True
    except (LdapConnectionException, LDAPSocketOpenError) as lce:
        LOGGER.error("Error connecting to LDAP: %s", lce)

    return False
Beispiel #5
0
def test_validate_missing_distinguished_name():
    """ensures a failure occurs when 'distinguished_name' field is missing"""
    with pytest.raises(LdapValidationException) as response:
        next_payload = {"data": {}, "data_type": "user"}
        ldap_message_validator.validate_next_payload(next_payload)
        assert response == "'data' is missing an entry for: 'distinguished_name'"
Beispiel #6
0
def test_validate_missing_data_field():
    """ensures a failure occurs when 'data' field is missing"""
    with pytest.raises(LdapValidationException) as response:
        next_payload = {"data_type": "user"}
        ldap_message_validator.validate_next_payload(next_payload)
        assert response == "Required field: 'data' is missing"