This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 822
Support registration tokens #7275
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
5b10be8
Support token authenticated registration
govynnus 39c258a
Backwards compatibility with unstable auth type
govynnus 8d3e1d9
Make LOGIN_TYPE public and readonly
govynnus 1ddf830
Update registration-tokens to latest develop
govynnus f9a3fe8
Remove line related to skinning
govynnus 47e3a7a
Change empty string to null
govynnus 3a30db6
Use "public"s for new code style
govynnus e76180e
Merge branch 'develop' into registration-tokens
govynnus 939a5ec
Change input to AccessibleButton
govynnus 6fa9204
Add more detail regarding source of token
govynnus 8e911d6
Merge remote-tracking branch 'upstream/develop' into registration-tokens
govynnus f489cd5
Fix lint error
govynnus 6cb3260
Change null back to ""
govynnus 3ebb998
Disable submit button when no token entered
govynnus a19b417
Add test for registration tokens
govynnus 73e0f8a
Merge remote-tracking branch 'upstream/develop' into registration-tokens
govynnus 43a3e4e
Merge remote-tracking branch 'upstream/develop' into registration-tokens
govynnus 1881fa5
Merge remote-tracking branch 'upstream/master' into registration-tokens
govynnus 04911e1
Merge remote-tracking branch 'upstream/develop' into registration-tokens
govynnus aea870d
Fix linting errors
govynnus 3636932
Fix test for registration tokens
govynnus a632da7
Merge remote-tracking branch 'upstream/develop' into registration-tokens
govynnus 3a944c0
Merge branch 'develop' into registration-tokens
andybalaam 284ba03
Add missing type
andybalaam 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 hidden or 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 hidden or 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 hidden or 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,106 @@ | ||
/* | ||
Copyright 2016 OpenMarket Ltd | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Copyright 2022 Callum Brown | ||
|
||
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 React from "react"; | ||
import { act } from "react-dom/test-utils"; | ||
// eslint-disable-next-line deprecate/import | ||
import { mount, ReactWrapper } from "enzyme"; | ||
|
||
import InteractiveAuthComponent from "../../../../src/components/structures/InteractiveAuth"; | ||
import { flushPromises, getMockClientWithEventEmitter, unmockClientPeg } from "../../../test-utils"; | ||
|
||
describe("InteractiveAuthComponent", function () { | ||
const mockClient = getMockClientWithEventEmitter({ | ||
generateClientSecret: jest.fn().mockReturnValue("t35tcl1Ent5ECr3T"), | ||
}); | ||
|
||
const defaultProps = { | ||
matrixClient: mockClient, | ||
makeRequest: jest.fn().mockResolvedValue(undefined), | ||
onAuthFinished: jest.fn(), | ||
}; | ||
const getComponent = (props = {}) => mount(<InteractiveAuthComponent {...defaultProps} {...props} />); | ||
|
||
beforeEach(function () { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
afterAll(() => { | ||
unmockClientPeg(); | ||
}); | ||
|
||
const getSubmitButton = (wrapper: ReactWrapper) => wrapper.find('AccessibleButton[kind="primary"]').at(0); | ||
const getRegistrationTokenInput = (wrapper: ReactWrapper) => | ||
wrapper.find('input[name="registrationTokenField"]').at(0); | ||
|
||
it("Should successfully complete a registration token flow", async () => { | ||
const onAuthFinished = jest.fn(); | ||
const makeRequest = jest.fn().mockResolvedValue({ a: 1 }); | ||
|
||
const authData = { | ||
session: "sess", | ||
flows: [{ stages: ["m.login.registration_token"] }], | ||
}; | ||
|
||
const wrapper = getComponent({ makeRequest, onAuthFinished, authData }); | ||
|
||
const registrationTokenNode = getRegistrationTokenInput(wrapper); | ||
const submitNode = getSubmitButton(wrapper); | ||
const formNode = wrapper.find("form").at(0); | ||
|
||
expect(registrationTokenNode).toBeTruthy(); | ||
expect(submitNode).toBeTruthy(); | ||
expect(formNode).toBeTruthy(); | ||
|
||
// submit should be disabled | ||
expect(submitNode.props().disabled).toBe(true); | ||
|
||
// put something in the registration token box | ||
act(() => { | ||
registrationTokenNode.simulate("change", { target: { value: "s3kr3t" } }); | ||
wrapper.setProps({}); | ||
}); | ||
|
||
expect(getRegistrationTokenInput(wrapper).props().value).toEqual("s3kr3t"); | ||
expect(getSubmitButton(wrapper).props().disabled).toBe(false); | ||
|
||
// hit enter; that should trigger a request | ||
act(() => { | ||
formNode.simulate("submit"); | ||
}); | ||
|
||
// wait for auth request to resolve | ||
await flushPromises(); | ||
|
||
expect(makeRequest).toHaveBeenCalledTimes(1); | ||
expect(makeRequest).toBeCalledWith( | ||
expect.objectContaining({ | ||
session: "sess", | ||
type: "m.login.registration_token", | ||
token: "s3kr3t", | ||
}), | ||
); | ||
|
||
expect(onAuthFinished).toBeCalledTimes(1); | ||
expect(onAuthFinished).toBeCalledWith( | ||
true, | ||
{ a: 1 }, | ||
{ clientSecret: "t35tcl1Ent5ECr3T", emailSid: undefined }, | ||
); | ||
}); | ||
}); |
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.
Uh oh!
There was an error while loading. Please reload this page.