Skip to content

Commit

Permalink
MM-12757: discard session expiry on form submit (mattermost#2011)
Browse files Browse the repository at this point in the history
* MM-12757: discard session expiry on form submit

* simplify unit tests
  • Loading branch information
lieut-data authored and hmhealey committed Nov 14, 2018
1 parent 71eefcf commit 3fccde3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
21 changes: 15 additions & 6 deletions components/login/login_controller/login_controller.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ class LoginController extends React.Component {
preSubmit = (e) => {
e.preventDefault();

// Discard any session expiry notice once the user interacts with the login page.
this.onDismissSessionExpired();

const {location} = this.props;
const newQuery = location.search.replace(/(extra=password_change)&?/i, '');
if (newQuery !== location.search) {
Expand All @@ -186,14 +189,20 @@ class LoginController extends React.Component {

// password managers don't always call onInput handlers for form fields so it's possible
// for the state to get out of sync with what the user sees in the browser
let loginId = this.refs.loginId.value;
if (loginId !== this.state.loginId) {
this.setState({loginId});
let loginId = this.state.loginId;
if (this.refs.loginId) {
loginId = this.refs.loginId.value;
if (loginId !== this.state.loginId) {
this.setState({loginId});
}
}

const password = this.refs.password.value;
if (password !== this.state.password) {
this.setState({password});
let password = this.state.password;
if (this.refs.password) {
password = this.refs.password.value;
if (password !== this.state.password) {
this.setState({password});
}
}

// don't trim the password since we support spaces in passwords
Expand Down
21 changes: 21 additions & 0 deletions components/login/login_controller/login_controller.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,25 @@ describe('components/login/LoginController', () => {

expect(wrapper).toMatchSnapshot();
});

it('should discard session expiry notification on failed sign in', () => {
const props = {
...baseProps,
initializing: false,
location: {
search: '?extra=' + Constants.SIGNIN_CHANGE,
},
};

const wrapper = shallowWithIntl(
<LoginController {...props}/>
).dive();

wrapper.setState({sessionExpired: true});

const e = {preventDefault: jest.fn()};
wrapper.instance().preSubmit(e);

expect(wrapper.state('sessionExpired')).toBe(false);
});
});

0 comments on commit 3fccde3

Please sign in to comment.