def create_group_ldap(distinguished_name, sawtooth_entry, ldap_conn):
    """Create new AD group using attributes from sawtooth_entry."""
    LOGGER.info("Creating new AD group: %s", distinguished_name)
    sawtooth_entry_filtered = outbound_group_filter(sawtooth_entry["data"], "ldap")
    validated_entry = validate_create_entry(
        sawtooth_entry_filtered, sawtooth_entry["data_type"]
    )
    ldap_conn.add(
        dn=distinguished_name,
        object_class={"group", "top"},
        attributes={"groupType": validated_entry["groupType"]},
    )
    modify_ad_attributes(distinguished_name, validated_entry, ldap_conn)
def create_user_ldap(distinguished_name, sawtooth_entry, ldap_conn):
    """Create new AD user using attributes from sawtooth_entry."""
    LOGGER.info("Creating new AD user: %s", distinguished_name)
    sawtooth_entry_filtered = outbound_user_filter(sawtooth_entry["data"], "ldap")
    validated_entry = validate_create_entry(
        sawtooth_entry_filtered, sawtooth_entry["data_type"]
    )
    ldap_conn.add(
        dn=distinguished_name,
        object_class={"person", "organizationalPerson", "user"},
        attributes={
            "cn": validated_entry["cn"],
            "userPrincipalName": validated_entry["userPrincipalName"],
        },
    )
    modify_ad_attributes(distinguished_name, validated_entry, ldap_conn)
def test_validate_create_entry_errors(payload, data_type, err_msg):
    """Test that invalid payloads raise an error."""
    with pytest.raises(ValidationException) as err:
        validate_create_entry(payload, data_type)
        assert str(err.value) == err_msg
def test_validate_create_entry(payload, data_type, expected):
    """Test that valid payloads returns a valid payload."""
    result = validate_create_entry(payload, data_type)
    assert result == expected