コード例 #1
0
def _insert_users_into_inbound_queue(ldap_users):
    """Validates, transforms, and inserts users"""

    db_connection = yield from _get_db_connection(DB_HOST, DB_PORT, DB_NAME)

    for ldap_user in ldap_users:
        json_user = json.loads(ldap_user.entry_to_json())["attributes"]

        ldap_message_validator.validate_ldap_payload(json_user)

        # entry_data = json.loads(entry.entry_to_json())["attributes"]

        ldap_record = ldap_payload_mapper.to_next_user_create(ldap_user)

        current_time = yield from _get_current_time()

        inbound_entry = {
            "data": ldap_record,
            "data_type": DB_VALUE_DATA_TYPE_USER,
            "timestamp": current_time,
            "provider_id": ENV_VAR_PROVIDER_ID,
        }

        yield from r.table(DB_TABLE_QUEUE_INBOUND).insert(inbound_entry).run(
            db_connection
        )

    LOGGER.info("Inserted %s records into inbound_queue.", str(len(ldap_users)))
コード例 #2
0
def test_validate_invalid_data_type():
    """ensures a failure occurs when 'data_type' field is invalid"""
    with pytest.raises(LdapMessageValidationException) as response:
        ldap_payload = {"data": {"distinguished_name": "yo"}, "data_type": "no"}
        ldap_message_validator.validate_ldap_payload(ldap_payload)
        assert (
            response
            == "Invalid value for 'data_type'. 'data_type' must be in: ['user', 'group']"
        )
コード例 #3
0
def test_validate_empty_distinguished_name():
    """ensures a failure occurs when 'distinguished_name' field is empty"""
    with pytest.raises(LdapMessageValidationException) as response:
        ldap_payload = {"data": {"distinguished_name": ""}, "data_type": "user"}
        ldap_message_validator.validate_ldap_payload(ldap_payload)
        assert response == "'data'.'distinguished_name' cannot be empty"
コード例 #4
0
def test_validate_missing_distinguished_name():
    """ensures a failure occurs when 'distinguished_name' field is missing"""
    with pytest.raises(LdapMessageValidationException) as response:
        ldap_payload = {"data": {}, "data_type": "user"}
        ldap_message_validator.validate_ldap_payload(ldap_payload)
        assert response == "'data' is missing an entry for: 'distinguished_name'"
コード例 #5
0
def test_validate_missing_data_field():
    """ensures a failure occurs when 'data' field is missing"""
    with pytest.raises(LdapMessageValidationException) as response:
        ldap_payload = {"data_type": "user"}
        ldap_message_validator.validate_ldap_payload(ldap_payload)
        assert response == "Required field: 'data' is missing"