Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix : fix user_entry validation control #1871

Merged
merged 7 commits into from
Jan 1, 2023

Conversation

tomamplius
Copy link
Contributor

search_s return list or None (see https://www.python-ldap.org/en/python-ldap-3.4.3/reference/ldap.html?highlight=search_s#ldap.LDAPObject.search_s)

On my case search_s never return None
User exists

>>> user_entry = conn.search_s(
... "DC=lan,DC=lgy,DC=fr",
... ldap.SCOPE_SUBTREE,
... f"(&(objectClass=user)(|(cn=thomas)(sAMAccountName=thomas)(mail=thomas@lgy.fr)))",
... ["name", "mail"],
... )
>>> user_entry
[('CN=thomas,CN=Users,DC=lan,DC=lgy,DC=fr', {'name': [b'thomas'], 'mail': [b'thomas@lgy.fr']}), (None, ['ldaps://lan.lgy.fr/CN=Configuration,DC=lan,DC=lgy,DC=fr']), (None, ['ldaps://lan.lgy.fr/DC=DomainDnsZones,DC=lan,DC=lgy,DC=fr']), (None, ['ldaps://lan.lgy.fr/DC=ForestDnsZones,DC=lan,DC=lgy,DC=fr'])]
>>> not user_entry
False

User not exists


>>> user_entry2 = conn.search_s(
... "DC=lan,DC=lgy,DC=fr",
... ldap.SCOPE_SUBTREE,
... f"(&(objectClass=user)(|(cn=none)(sAMAccountName=none)(mail=none@lgy.fr)))",
... ["name", "mail"],
... )
>>> user_entry2
[(None, ['ldaps://lan.lgy.fr/CN=Configuration,DC=lan,DC=lgy,DC=fr']), (None, ['ldaps://lan.lgy.fr/DC=DomainDnsZones,DC=lan,DC=lgy,DC=fr']), (None, ['ldaps://lan.lgy.fr/DC=ForestDnsZones,DC=lan,DC=lgy,DC=fr'])]
>>> not user_entry2
False

@tomamplius
Copy link
Contributor Author

Check with new syntaxe

root@thomas-XPS15:/usr/share/mealie# poetry run black . --check
All done! ✨ 🍰 ✨
338 files would be left unchanged.

@tomamplius
Copy link
Contributor Author

i think this PR fix #1775

@tomamplius
Copy link
Contributor Author

Sorry first time i use poetry

cat mealie/core/security/security.py | tail -n 70 | head -n 20
        ldap.SCOPE_SUBTREE,
        f"(&(objectClass=user)(|(cn={username})(sAMAccountName={username})(mail={username})))",
        ["name", "mail"],
    )
    if not user_entry is None and not user_entry[0][0] is None:
        user_dn, user_attr = user_entry[0]
    else:
        return False

    if user is None:
        user = db.users.create(
            {
                "username": username,
                "password": "LDAP",
                "full_name": user_attr["name"][0],
                "email": user_attr["mail"][0],
                "admin": False,
            },
        )

root@thomas-XPS15:/usr/share/mealie# poetry run black . --check
All done! ✨ 🍰 ✨
858 files would be left unchanged.

@tomamplius
Copy link
Contributor Author

@hay-kot please approve running workflow

@hay-kot hay-kot merged commit 25ebe2d into mealie-recipes:mealie-next Jan 1, 2023
@hay-kot
Copy link
Collaborator

hay-kot commented Jan 1, 2023

Thanks for following up on this!

@tomamplius tomamplius deleted the ldapfix branch January 1, 2023 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants