Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2571 from jryans/auth-disable-custom-urls
Browse files Browse the repository at this point in the history
Ensure we show registration form when custom URLs are disabled
  • Loading branch information
dbkr authored Feb 5, 2019
2 parents 8598c4f + 71d1a24 commit 74d460b
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 12 deletions.
4 changes: 0 additions & 4 deletions src/components/structures/MatrixChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1891,19 +1891,15 @@ export default React.createClass({
sessionId={this.state.register_session_id}
idSid={this.state.register_id_sid}
email={this.props.startingFragmentQueryParams.email}
referrer={this.props.startingFragmentQueryParams.referrer}
defaultServerDiscoveryError={this.state.defaultServerDiscoveryError}
defaultHsUrl={this.getDefaultHsUrl()}
defaultIsUrl={this.getDefaultIsUrl()}
brand={this.props.config.brand}
customHsUrl={this.getCurrentHsUrl()}
customIsUrl={this.getCurrentIsUrl()}
makeRegistrationUrl={this._makeRegistrationUrl}
defaultDeviceDisplayName={this.props.defaultDeviceDisplayName}
onLoggedIn={this.onRegistered}
onLoginClick={this.onLoginClick}
onRegisterClick={this.onRegisterClick}
onCancelClick={MatrixClientPeg.get() ? this.onReturnToAppClick : null}
onServerConfigChange={this.onServerConfigChange}
/>
);
Expand Down
1 change: 0 additions & 1 deletion src/components/structures/auth/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,6 @@ module.exports = React.createClass({
const ModularServerConfig = sdk.getComponent("auth.ModularServerConfig");
const AccessibleButton = sdk.getComponent("elements.AccessibleButton");

// TODO: May need to adjust the behavior of this config option
if (SdkConfig.get()['disable_custom_urls']) {
return null;
}
Expand Down
11 changes: 4 additions & 7 deletions src/components/structures/auth/Registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,17 @@ module.exports = React.createClass({
defaultIsUrl: PropTypes.string,
brand: PropTypes.string,
email: PropTypes.string,
referrer: PropTypes.string,

// An error passed along from higher up explaining that something
// went wrong when finding the defaultHsUrl.
defaultServerDiscoveryError: PropTypes.string,

defaultDeviceDisplayName: PropTypes.string,

// registration shouldn't know or care how login is done.
onLoginClick: PropTypes.func.isRequired,
onCancelClick: PropTypes.func,
onServerConfigChange: PropTypes.func.isRequired,
},

getInitialState: function() {
const customURLsAllowed = !SdkConfig.get()['disable_custom_urls'];

return {
busy: false,
errorText: null,
Expand All @@ -90,6 +86,8 @@ module.exports = React.createClass({
serverType: null,
hsUrl: this.props.customHsUrl,
isUrl: this.props.customIsUrl,
// Phase of the overall registration dialog.
phase: customURLsAllowed ? PHASE_SERVER_DETAILS : PHASE_REGISTRATION,
flows: null,
};
},
Expand Down Expand Up @@ -367,7 +365,6 @@ module.exports = React.createClass({
const ModularServerConfig = sdk.getComponent("auth.ModularServerConfig");
const AccessibleButton = sdk.getComponent("elements.AccessibleButton");

// TODO: May need to adjust the behavior of this config option
if (SdkConfig.get()['disable_custom_urls']) {
return null;
}
Expand Down
83 changes: 83 additions & 0 deletions test/components/structures/auth/Registration-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
Copyright 2019 New Vector Ltd
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 expect from 'expect';
import sinon from 'sinon';
import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import sdk from 'matrix-react-sdk';
import SdkConfig from '../../../../src/SdkConfig';
import * as TestUtils from '../../../test-utils';

const Registration = sdk.getComponent(
'structures.auth.Registration',
);

describe('Registration', function() {
let parentDiv;

beforeEach(function() {
TestUtils.beforeEach(this);
parentDiv = document.createElement('div');
document.body.appendChild(parentDiv);
});

afterEach(function() {
sinon.restore();
ReactDOM.unmountComponentAtNode(parentDiv);
parentDiv.remove();
});

function render() {
return ReactDOM.render(<Registration
defaultHsUrl="https://matrix.org"
defaultIsUrl="https://vector.im"
makeRegistrationUrl={() => {}}
onLoggedIn={() => {}}
onLoginClick={() => {}}
onServerConfigChange={() => {}}
/>, parentDiv);
}

it('should show server type selector', function() {
const root = render();
const selector = ReactTestUtils.findRenderedComponentWithType(
root,
sdk.getComponent('auth.ServerTypeSelector'),
);
expect(selector).toBeTruthy();
});

it('should show form when custom URLs disabled', function() {
sinon.stub(SdkConfig, "get").returns({
disable_custom_urls: true,
});

const root = render();

// Set non-empty flows to get past the loading spinner
root.setState({
flows: [],
});

const form = ReactTestUtils.findRenderedComponentWithType(
root,
sdk.getComponent('auth.RegistrationForm'),
);
expect(form).toBeTruthy();
});
});

0 comments on commit 74d460b

Please sign in to comment.