This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 833
Fixes user authentication when registering via the module API #10257
Merged
justjanne
merged 7 commits into
matrix-org:develop
from
nordeck:module_auth_fix_dispatch
Mar 7, 2023
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a25920f
Fixes authentication when user is registered via module API
71c1f66
Merge branch 'develop' into module_auth_fix_dispatch
maheichyk 1c6d1bf
Merge branch 'develop' into module_auth_fix_dispatch
maheichyk da43b33
Remove "on_logging_in" action
1aff79c
Merge branch 'develop' into module_auth_fix_dispatch
maheichyk e247137
Test is removed
4617c71
Merge branch 'develop' into module_auth_fix_dispatch
maheichyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
Copyright 2023 Mikhail Aheichyk | ||
Copyright 2023 Nordeck IT + Consulting GmbH. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { AccountAuthInfo } from "@matrix-org/react-sdk-module-api/lib/types/AccountAuthInfo"; | ||
import { logger } from "matrix-js-sdk/src/logger"; | ||
|
||
import defaultDispatcher from "../src/dispatcher/dispatcher"; | ||
import { OverwriteLoginPayload } from "../src/dispatcher/payloads/OverwriteLoginPayload"; | ||
import { Action } from "../src/dispatcher/actions"; | ||
import { setLoggedIn } from "../src/Lifecycle"; | ||
import { stubClient } from "./test-utils"; | ||
import { ActionPayload } from "../src/dispatcher/payloads"; | ||
|
||
jest.mock("../src/utils/createMatrixClient", () => ({ | ||
__esModule: true, | ||
default: jest.fn().mockReturnValue({ | ||
clearStores: jest.fn(), | ||
}), | ||
})); | ||
|
||
describe("Lifecycle", () => { | ||
stubClient(); | ||
|
||
jest.spyOn(logger, "error").mockReturnValue(undefined); | ||
jest.spyOn(logger, "warn").mockReturnValue(undefined); | ||
jest.spyOn(logger, "log").mockImplementation(undefined); | ||
|
||
it("should call 'overwrite_login' callback and receive 'on_logged_in'", async () => { | ||
// promise to wait 'on_logged_in' | ||
const loggedInPromise = new Promise((resolve, reject) => { | ||
defaultDispatcher.register((payload: ActionPayload) => { | ||
if (payload.action === Action.OnLoggedIn) { | ||
resolve(undefined); | ||
} | ||
}); | ||
}); | ||
|
||
// dispatch 'overwrite_login' | ||
const accountInfo = {} as unknown as AccountAuthInfo; | ||
defaultDispatcher.dispatch<OverwriteLoginPayload>( | ||
{ | ||
action: Action.OverwriteLogin, | ||
credentials: { | ||
...accountInfo, | ||
guest: false, | ||
}, | ||
}, | ||
true, | ||
); | ||
|
||
await expect(loggedInPromise).resolves.toBeUndefined(); | ||
}); | ||
|
||
it("should setLoggedIn", async () => { | ||
// promise to wait 'on_logging_in' | ||
const loggingInPromise = new Promise((resolve, reject) => { | ||
defaultDispatcher.register((payload: ActionPayload) => { | ||
if (payload.action === "on_logging_in") { | ||
resolve(undefined); | ||
} | ||
}); | ||
}); | ||
|
||
await setLoggedIn({ | ||
accessToken: "some_token", | ||
homeserverUrl: "https://example.com", | ||
userId: "@some_user_id", | ||
}); | ||
|
||
await expect(loggingInPromise).resolves.toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"on_logging_in"
doesn't seem to be used in the react-sdk or element-web codeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When creating new actions, please use the Action enum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added
"on_logging_in"
to Action, but this action wasn't created in this PR. I just added anif
condition around it to fix the dispatcher.