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

panicked at 'called Option::unwrap() on a None value' #303

Closed
cite opened this issue Sep 26, 2022 · 6 comments · Fixed by #304
Closed

panicked at 'called Option::unwrap() on a None value' #303

cite opened this issue Sep 26, 2022 · 6 comments · Fixed by #304

Comments

@cite
Copy link

cite commented Sep 26, 2022

Query with two "OR" conditions works fine:

$ ldapsearch -H ldap://lldap:3890  -b "dc=incertum,dc=net" -D "cn=binduser,ou=people,dc=incertum,dc=net" -w secret "(&(|(objectclass=groupOfUniqueNames))(|(cn=git)(cn=jitsi)))" cn
# extended LDIF
#
# LDAPv3
# base <dc=incertum,dc=net> with scope subtree
# filter: (&(|(objectclass=groupOfUniqueNames))(|(cn=git)(cn=jitsi)))
# requesting: cn 
#

# git, groups, incertum.net
dn: cn=git,ou=groups,dc=incertum,dc=net
cn: git

# jitsi, groups, incertum.net
dn: cn=jitsi,ou=groups,dc=incertum,dc=net
cn: jitsi

# search result
search: 2
result: 0 Success

# numResponses: 3
# numEntries: 2

However, adding a third "OR" condition panics:

$  ldapsearch -H ldap://lldap:3890  -b "dc=incertum,dc=net" -D "cn=binduser,ou=people,dc=incertum,dc=net" -w secret "(&(|(objectclass=groupOfUniqueNames))(|(cn=git)(cn=jitsi)(cn=nextcloud)))" cn
# extended LDIF
#
# LDAPv3
# base <dc=incertum,dc=net> with scope subtree
# filter: (&(|(objectclass=groupOfUniqueNames))(|(cn=git)(cn=jitsi)(cn=nextcloud)))
# requesting: cn 
#


# numResponses: 0
ldap_result: Can't contact LDAP server (-1)

container log:

thread 'actix-rt|system:0|arbiter:0' panicked at 'called `Option::unwrap()` on a `None` value', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/sea-query-0.25.2/src/backend/query_builder.rs:1545:64
2022-09-26T09:32:00.834119513+00:00 INFO     LDAP session [ 89.9ms | 0.09% / 100.00% ]
2022-09-26T09:32:00.834155690+00:00 INFO     ┝━ LDAP request [ 89.7ms | 0.08% / 99.79% ]
2022-09-26T09:32:00.834168785+00:00 DEBUG    │  ┝━ 🐛 [debug]:  | msg: LdapMsg { msgid: 1, op: BindRequest(LdapBindRequest { dn: "cn=binduser,ou=people,dc=incertum,dc=net", cred: Simple("********") }), ctrl: [] }
2022-09-26T09:32:00.834171099+00:00 DEBUG    │  ┝━ do_bind [ 89.7ms | 0.02% / 99.71% ]
2022-09-26T09:32:00.834173985+00:00 DEBUG    │  │  ┝━ 🐛 [debug]: DN: cn=f_user,ou=people,dc=incertum,dc=net
2022-09-26T09:32:00.834179455+00:00 DEBUG    │  │  ┝━ bind [ 89.6ms | 0.07% / 99.59% ]
2022-09-26T09:32:00.834304259+00:00 DEBUG    │  │  │  ┕━ passwords_match [ 89.5ms | 99.51% ]
2022-09-26T09:32:00.923809259+00:00 DEBUG    │  │  ┝━ get_user_groups [ 91.1µs | 0.10% ]
2022-09-26T09:32:00.923816233+00:00 DEBUG    │  │  │  ┝━ 🐛 [debug]:  | user_id: UserId("binduser")
2022-09-26T09:32:00.923844155+00:00 DEBUG    │  │  │  ┝━ 🐛 [debug]:  | query: SELECT "groups"."group_id", "display_name", "creation_date", "uuid" FROM "groups" INNER JOIN "memberships" ON "groups"."group_id" = "memberships"."group_id" WHERE "user_id" = ?
2022-09-26T09:32:00.923981492+00:00 DEBUG    │  │  │  ┕━ 🐛 [debug]:  | return: {GroupDetails { group_id: GroupId(3), display_name: "lldap_strict_readonly", creation_date: 2022-09-24T12:53:17.427205284Z, uuid: Uuid("8eacd503-9575-3ca4-a8ba-7d13ca0f6f3e") }}
2022-09-26T09:32:00.923983937+00:00 DEBUG    │  │  ┕━ 🐛 [debug]: Success!
2022-09-26T09:32:00.923989367+00:00 DEBUG    │  ┕━ 🐛 [debug]:  | response: BindResponse(LdapBindResponse { res: LdapResult { code: Success, matcheddn: "", message: "", referral: [] }, saslcreds: None })
2022-09-26T09:32:00.924207196+00:00 INFO     ┕━ LDAP request [ 116µs | 0.02% / 0.13% ]
2022-09-26T09:32:00.924213818+00:00 DEBUG       ┝━ 🐛 [debug]:  | msg: LdapMsg { msgid: 2, op: SearchRequest(LdapSearchRequest { base: "dc=incertum,dc=net", scope: Subtree, aliases: Never, sizelimit: 0, timelimit: 0, typesonly: false, filter: And([Or([Equality("objectclass", "groupOfUniqueNames")]), Or([Equality("cn", "git"), Equality("cn", "jitsi"), Equality("cn", "nextcloud")])]), attrs: ["cn"] }), ctrl: [] }
2022-09-26T09:32:00.924215211+00:00 DEBUG       ┕━ do_search [ 102µs | 0.01% / 0.11% ]
2022-09-26T09:32:00.924220771+00:00 DEBUG          ┝━ 🐛 [debug]:  | request.base: "dc=incertum,dc=net" | scope: Global
2022-09-26T09:32:00.924221422+00:00 DEBUG          ┕━ get_user_list [ 89.9µs | 0.02% / 0.10% ]
2022-09-26T09:32:00.924224077+00:00 DEBUG             ┝━ 🐛 [debug]:  | ldap_filter: And([Or([Equality("objectclass", "groupOfUniqueNames")]), Or([Equality("cn", "git"), Equality("cn", "jitsi"), Equality("cn", "nextcloud")])])
2022-09-26T09:32:00.924230049+00:00 DEBUG             ┝━ 🐛 [debug]:  | parsed_filters: And([Or([Not(And([]))]), Or([Equality("display_name", "git"), Equality("display_name", "jitsi"), Equality("display_name", "nextcloud")])])
2022-09-26T09:32:00.924230710+00:00 DEBUG             ┝━ expand_attribute_wildcards [ 3.61µs | 0.00% ]
2022-09-26T09:32:00.924233946+00:00 DEBUG             │  ┕━ 🐛 [debug]:  | ldap_attributes: ["cn"] | resolved_attributes: ["cn"]
2022-09-26T09:32:00.924236050+00:00 DEBUG             ┕━ list_users [ 71.2µs | 0.08% ]
2022-09-26T09:32:00.924239366+00:00 DEBUG                ┕━ 🐛 [debug]:  | filters: Some(And([Or([Not(And([]))]), Or([Equality("display_name", "git"), Equality("display_name", "jitsi"), Equality("display_name", "nextcloud")])])) | get_groups: false

Version 0.4.0, lldap:stable image.

@nitnelave
Copy link
Member

Hi! Thanks for the bug report, a panic is definitely not something intended. I can't look into it right now, but just to put my mind at ease, can you check with just "git" and "nextcloud", or "jitsi" and "nextcloud"? To make sure it's due to the 3 arguments and not due to something weird with the nextcloud group in your setup.

@cite
Copy link
Author

cite commented Sep 26, 2022

The queries work with the other two groups, there's nothing special about the nextcloud group.

While at it, thanks for this little gem, makes LDAP so easy :-)

@nitnelave
Copy link
Member

Alright, managed to reproduce it, it requires the exact structure you provided: And(Or(cond), Or(cond, cond, cond)). It seems to be a bug in sea-query, I'll look into it, report it and potentially fix it.

@nitnelave
Copy link
Member

I think I might have been misusing their API? It shouldn't have resulted in a panic anyway.

I updated the code to use a more recent API (that incidentally I introduced in their code last year), and it should work now, I added a unit test to make sure.

@nitnelave
Copy link
Member

Alright, it should work in :latest

@cite
Copy link
Author

cite commented Sep 27, 2022

Thanks a lot for that quick fix!

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 a pull request may close this issue.

2 participants