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

fix(sdk): Can't assert identity without session #832

Merged

Conversation

johannescpk
Copy link
Contributor

@johannescpk johannescpk commented Jul 11, 2022

Fixes #821

Part of #228

@codecov
Copy link

codecov bot commented Jul 11, 2022

Codecov Report

Merging #832 (420ca26) into main (2d06538) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #832   +/-   ##
=======================================
  Coverage   78.20%   78.20%           
=======================================
  Files         101      101           
  Lines       14223    14223           
=======================================
  Hits        11123    11123           
  Misses       3100     3100           
Impacted Files Coverage Δ
crates/matrix-sdk/src/client/builder.rs 71.57% <ø> (ø)
crates/matrix-sdk/src/http_client.rs 88.75% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2d06538...420ca26. Read the comment docs.

Copy link
Member

@Hywan Hywan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the patch avoids to fall in the else branch with a session set to None, which will avoid to return an Err(HttpError::UserIdRequired) (from session). The new path could build a request without a user ID and with SendAccessToken::None instead.

All of this sounds sensible to me. I don't know if it's correct though, and it could be comfortable to get a second review to validate this new flow.

cc @poljar @gnunicorn

@Hywan Hywan added the bug Something isn't working label Jul 12, 2022
Copy link
Contributor

@gnunicorn gnunicorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an appservice only feature, and I don't fully understand when and how the assert_identity is used by the service, but I assume you have better knowledge about that and know about the potential problems here. That said, it'd be great if 1) you could update the code docs of ClientBuilder.assert_identity, as they say it would fail without a session (which it wouldn't anymore now) and 2) in a PR like this you'd give a bit more context, like stating that this is an appservice only feature and educate us more, why our current code is wrong :) (the issue linked also only describes the bug, not really why that behavior is considered a bug).

@johannescpk johannescpk force-pushed the sdk/identity-assertion-session branch from efc9654 to 420ca26 Compare July 12, 2022 08:45
@johannescpk
Copy link
Contributor Author

johannescpk commented Jul 12, 2022

Thanks for the reviews and docs catch, updated accordingly.

Right, I somehow was thinking about identity assertion as independent feature - but forgot that it actually is tied to appservices only, in terms of spec.

It's considered a bug because using the appservice crate currently will error at runtime if you try to use it, regardless of what you try to do with it. That's because server_versions passes None as session - which is called as part of HttpClient::send - since a refactoring, and the else block always expects a session to be available. We unfortunately have no test that covers identity assertion proper for this scenario yet, which would've have surfaced it sooner.

The given PR was the only fix I found without large refactorings, because a lot depends on Store::session now returning Option<&Session> instead of Arc<OnceCell<Session>>.

@johannescpk
Copy link
Contributor Author

In terms of correctness: It doesn't seem to make sense anyway to do identity assertion for endpoints that don't require authentication, since endpoints that don't require authentication don't have any knowledge about the user or session, and so wouldn't act differently either way. So maybe a refactoring including a test could take that into account.

@gnunicorn
Copy link
Contributor

thanks for the clarifications!

@gnunicorn gnunicorn enabled auto-merge July 12, 2022 10:08
@gnunicorn gnunicorn merged commit 15be2dc into matrix-org:main Jul 12, 2022
@johannescpk johannescpk deleted the sdk/identity-assertion-session branch July 12, 2022 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Client::send fails with assert_identity enabled [regression]
3 participants