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

Appservice login #2936

Closed
wants to merge 17 commits into from
Closed

Conversation

vijfhoek
Copy link
Contributor

@vijfhoek vijfhoek commented Jan 10, 2023

Fixes #2723

This is my first contribution to this code base, so I hope I did everything correctly :)

I did move validateApplicationService (now ValidateApplicationService) from routing to internal to be able to reuse it - is this the right place for it?

Pull Request Checklist

Signed-off-by: Sijmen Schoon <me@sijman.nl>

@vijfhoek vijfhoek requested a review from a team as a code owner January 10, 2023 16:50
@codecov
Copy link

codecov bot commented Jan 10, 2023

Codecov Report

Base: 40.30% // Head: 40.47% // Increases project coverage by +0.17% 🎉

Coverage data is based on head (dc14738) compared to base (2debabf).
Patch coverage: 85.59% of modified lines in pull request are covered.

❗ Current head dc14738 differs from pull request most recent head 902eb1e. Consider uploading reports for the commit 902eb1e to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2936      +/-   ##
==========================================
+ Coverage   40.30%   40.47%   +0.17%     
==========================================
  Files         519      520       +1     
  Lines       56436    56457      +21     
==========================================
+ Hits        22745    22851     +106     
+ Misses      30968    30896      -72     
+ Partials     2723     2710      -13     
Flag Coverage Δ
unittests 40.47% <85.59%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
clientapi/auth/user_interactive.go 78.62% <ø> (ø)
clientapi/routing/register.go 62.18% <0.00%> (+0.41%) ⬆️
clientapi/auth/login_application_service.go 61.53% <61.53%> (ø)
internal/validate.go 92.18% <87.34%> (-7.82%) ⬇️
clientapi/auth/login.go 86.27% <100.00%> (+4.69%) ⬆️
clientapi/routing/login.go 69.49% <100.00%> (+21.95%) ⬆️
roomserver/storage/sqlite3/event_json_table.go 80.85% <0.00%> (-6.39%) ⬇️
syncapi/streams/stream_presence.go 58.26% <0.00%> (-2.37%) ⬇️
syncapi/notifier/notifier.go 62.46% <0.00%> (-0.78%) ⬇️
roomserver/internal/query/query.go 31.44% <0.00%> (ø)
... and 17 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

clientapi/routing/login.go Outdated Show resolved Hide resolved
@vijfhoek vijfhoek force-pushed the sijmens/appservice_login branch 2 times, most recently from c52f212 to 23fa52f Compare January 11, 2023 09:26
Signed-off-by: Sijmen <me@sijman.nl>
Signed-off-by: Sijmen Schoon <me@sijman.nl>
Signed-off-by: Sijmen <me@sijman.nl>
Signed-off-by: Sijmen Schoon <me@sijman.nl>
Signed-off-by: Sijmen <me@sijman.nl>
Signed-off-by: Sijmen Schoon <me@sijman.nl>
Signed-off-by: Sijmen <me@sijman.nl>
Signed-off-by: Sijmen Schoon <me@sijman.nl>
Signed-off-by: Sijmen <me@sijman.nl>
Signed-off-by: Sijmen Schoon <me@sijman.nl>
Signed-off-by: Sijmen Schoon <me@sijman.nl>
@S7evinK S7evinK added C-Client-API spec-compliance Fix something that doesn't comply with the specs T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements. F-App-Service labels Jan 16, 2023
Copy link
Contributor

@S7evinK S7evinK left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks for adding tests as well :)

clientapi/auth/login_test.go Outdated Show resolved Hide resolved
clientapi/auth/login_test.go Outdated Show resolved Hide resolved
Copy link
Member

@kegsay kegsay left a comment

Choose a reason for hiding this comment

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

Otherwise this looks great, thanks!

internal/validate_test.go Outdated Show resolved Hide resolved
// Access token is correct, acting as user_id that matches but is invalid
asID, resp = ValidateApplicationService(&fakeConfig.ClientAPI, "@_appservice_bob::", fakeApplicationService.ASToken)
if resp == nil || asID == fakeApplicationService.ID {
t.Errorf("user_id should not have been valid: @_appservice_bob::")
Copy link
Member

Choose a reason for hiding this comment

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

Good tests overall, but please make them table-driven as it's significantly easier to see the inputs / expected outputs https://dave.cheney.net/2019/05/07/prefer-table-driven-tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something like this?

internal/validate.go Outdated Show resolved Hide resolved
internal/validate.go Outdated Show resolved Hide resolved
internal/validate.go Outdated Show resolved Hide resolved
internal/validate.go Show resolved Hide resolved
JSON: flows{
Flows: []flow{
{Type: authtypes.LoginTypePassword},
{Type: authtypes.LoginTypeApplicationService},
Copy link
Member

Choose a reason for hiding this comment

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

This is only true if Dendrite has been configured with appservices surely.

@kegsay
Copy link
Member

kegsay commented Mar 6, 2023

Please fix the linter errors.

@sebastian-de
Copy link

Hey @vijfhoek, thanks for your work - I'm currently testing your PR on my dendrite instance with mautrix-signal and so far it works great!

I rebased your PR on the current main branch: https://github.com/sebastian-de/dendrite/commits/appservice

Feel free to use this tree, if you'd like to push again.

@sebastian-de
Copy link

It seems mautrix-signal has problems to connect, when encryption is enabled. This a log from mautrix-signal.service:

[2023-03-24 13:21:20,969] [INFO@mau.user.@user:example.com] Automatically enabling custom puppet
[2023-03-24 13:21:20,979] [INFO@mau.init] Startup actions complete in 0.2 seconds, now running forever
[2023-03-24 13:21:20,983] [WARNING@mau.user.@user:example.com] New IDENTIFIED websocket state from signald CONNECTING
[2023-03-24 13:21:20,987] [WARNING@mau.user.@user:example.com] New UNIDENTIFIED websocket state from signald CONNECTING
[2023-03-24 13:21:21,110] [WARNING@mau.user.@user:example.com] Failed to enable custom puppet: Didn't get an access token: The username or password was incorrect or the account does not exist.

The dendrite logs don't reveal anything regarding that error.
The user does exist and I'm using registration_shared_secret which worked well so far with mautrix-signal.
Are there additional configuration steps neccessary to make appservice login work?

@sebastian-de
Copy link

It seems mautrix-signal has problems to connect

This was a configuration error in mautrix-signal - the bridge seems to mix things up, when shared secret auth is enabled.
Sorry for the noise.

@Fijxu
Copy link

Fijxu commented Apr 6, 2023

I was trying this branch with encryption support but it seems to fails for me using mautrix-whatsapp.

The bot returns this when trying to do a request to _matrix/client/v3/sendToDevice/m.room_key_request/mautrix-go

{
    "errcode": "M_UNKNOWN_TOKEN",
    "error": "Unknown token"
}

image

and it fails retrieving encryption keys for the encrypted chat. Although it connects good to the Dendrite instance and it detects that the server supports appservice encryption. And in the configuration file of the Bot i need to change from appservice: false to appservice: true or it will fail to connect to the instance.

https://github.com/mautrix/whatsapp/blob/master/example-config.yaml#L353

@kegsay kegsay added the stale This issue or PR is at risk of being closed without further feedback label Apr 25, 2023
@kegsay
Copy link
Member

kegsay commented Apr 25, 2023

This PR is at risk of being closed. Unfortunately the lint errors haven't been fixed yet, and now there's a lot of merge conflicts.

@vijfhoek
Copy link
Contributor Author

I haven't had too much time lately, sorry. The merge conflicts seem to be fairly simple to solve at first sight though

@kuhnchris
Copy link
Contributor

Hey @vijfhoek - hope you're doing good - I took the liberty to rebase your branch and opened a new PR, if you'd prefer to have it in your repo, let me know and I'll add a PR to that instead. Thanks for your work and cheers ❤️

@vijfhoek
Copy link
Contributor Author

vijfhoek commented Jul 3, 2023

Closing because this one's superseded by #3078

@vijfhoek vijfhoek closed this Jul 3, 2023
S7evinK added a commit that referenced this pull request Nov 24, 2023
Rebase of #2936 as @vijfhoek wrote he got no time to work on this, and I
kind of needed it for my experiments.
I checked the tests, and it is working with my example code (i.e.
impersonating, registering, creating channel, invite people, write
messages).
I'm not a huge `go` pro, and still learning, but I tried to fix and/or
integrate the changes as best as possible with the current `main` branch
changes.
If there is anything left, let me know and I'll try to figure it out.

Signed-off-by: `Kuhn Christopher <kuhnchris+git@kuhnchris.eu>`

---------

Signed-off-by: Sijmen <me@sijman.nl>
Signed-off-by: Sijmen Schoon <me@sijman.nl>
Co-authored-by: Sijmen Schoon <me@sijman.nl>
Co-authored-by: Sijmen Schoon <me@vijf.life>
Co-authored-by: Till <2353100+S7evinK@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Client-API F-App-Service spec-compliance Fix something that doesn't comply with the specs stale This issue or PR is at risk of being closed without further feedback T-Enhancement New features, changes in functionality, improvements in performance, or user-facing enhancements.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement appservice login
6 participants