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

fix: 2FA bug fixes #19260

Merged
merged 17 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {
zoom: 'Zoom',
password: 'Password',
magicCode: 'Magic code',
twoFactorCode: 'Two factor code',
twoFactorCode: 'Two-factor code',
workspaces: 'Workspaces',
profile: 'Profile',
payments: 'Payments',
Expand Down Expand Up @@ -186,7 +186,7 @@ export default {
requestNewCode: 'You can also',
requestNewCodeLink: 'request a new code here',
successfulNewCodeRequest: 'Code requested. Please check your device.',
tfaRequiredTitle: 'Two factor authentication\nrequired',
tfaRequiredTitle: 'Two-factor authentication\nrequired',
tfaRequiredDescription: 'Please enter the two-factor authentication code\nwhere you are trying to sign in.',
},
moneyRequestConfirmationList: {
Expand Down Expand Up @@ -514,7 +514,7 @@ export default {
stepCodes: 'Recovery codes',
keepCodesSafe: 'Keep these recovery codes safe!',
codesLoseAccess:
'If you lose access to your authenticator app and don’t have these codes, you will lose access to your account. \n\nNote: Setting up two factor authentication will log you out of all other active sessions.',
'If you lose access to your authenticator app and don’t have these codes, you will lose access to your account. \n\nNote: Setting up two-factor authentication will log you out of all other active sessions.',
stepVerify: 'Verify',
scanCode: 'Scan the QR code using your',
authenticatorApp: 'authenticator app',
Expand All @@ -529,8 +529,8 @@ export default {
},
twoFactorAuthForm: {
error: {
pleaseFillTwoFactorAuth: 'Please enter your two factor code',
incorrect2fa: 'Incorrect two factor authentication code. Please try again.',
pleaseFillTwoFactorAuth: 'Please enter your two-factor code',
incorrect2fa: 'Incorrect two-factor authentication code. Please try again.',
},
},
passwordConfirmationScreen: {
Expand Down Expand Up @@ -667,20 +667,20 @@ export default {
error: {
pleaseFillMagicCode: 'Please enter your magic code',
incorrectMagicCode: 'Incorrect magic code.',
pleaseFillTwoFactorAuth: 'Please enter your two factor code',
pleaseFillTwoFactorAuth: 'Please enter your two-factor code',
},
},
passwordForm: {
pleaseFillOutAllFields: 'Please fill out all fields',
pleaseFillPassword: 'Please enter your password',
pleaseFillTwoFactorAuth: 'Please enter your two factor code',
enterYourTwoFactorAuthenticationCodeToContinue: 'Enter your two factor authentication code to continue',
pleaseFillTwoFactorAuth: 'Please enter your two-factor code',
enterYourTwoFactorAuthenticationCodeToContinue: 'Enter your two-factor authentication code to continue',
forgot: 'Forgot?',
requiredWhen2FAEnabled: 'Required when 2FA is enabled',
error: {
incorrectPassword: 'Incorrect password. Please try again.',
incorrectLoginOrPassword: 'Incorrect login or password. Please try again.',
incorrect2fa: 'Incorrect two factor authentication code. Please try again.',
incorrect2fa: 'Incorrect two-factor authentication code. Please try again.',
twoFactorAuthenticationEnabled: 'You have 2FA enabled on this account. Please sign in using your email or phone number.',
invalidLoginOrPassword: 'Invalid login or password. Please try again or reset your password.',
unableToResetPassword:
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReimbursementAccount/ValidationStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const propTypes = {

/** User's account who is setting up bank account */
account: PropTypes.shape({
/** If user has Two factor authentication enabled */
/** If user has two-factor authentication enabled */
requiresTwoFactorAuth: PropTypes.bool,
}),
};
Expand Down
13 changes: 7 additions & 6 deletions src/pages/ValidateLoginPage/index.website.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,21 @@ class ValidateLoginPage extends Component {
}

render() {
const isTfaRequired = lodashGet(this.props, 'account.requiresTwoFactorAuth', false);
const is2FARequired = lodashGet(this.props, 'account.requiresTwoFactorAuth', false);
const isSignedIn = Boolean(lodashGet(this.props, 'session.authToken', null));
const currentAuthState = this.getAutoAuthState();
return (
<>
{this.getAutoAuthState() === CONST.AUTO_AUTH_STATE.FAILED && <ExpiredValidateCodeModal />}
{this.getAutoAuthState() === CONST.AUTO_AUTH_STATE.JUST_SIGNED_IN && (!isTfaRequired || isSignedIn) && <AbracadabraModal />}
{this.getAutoAuthState() === CONST.AUTO_AUTH_STATE.JUST_SIGNED_IN && isTfaRequired && !isSignedIn && <TfaRequiredModal />}
{this.getAutoAuthState() === CONST.AUTO_AUTH_STATE.NOT_STARTED && (
{currentAuthState === CONST.AUTO_AUTH_STATE.FAILED && <ExpiredValidateCodeModal />}
{currentAuthState === CONST.AUTO_AUTH_STATE.JUST_SIGNED_IN && is2FARequired && !isSignedIn && <TfaRequiredModal />}
{currentAuthState === CONST.AUTO_AUTH_STATE.NOT_STARTED && isSignedIn && <AbracadabraModal />}
{currentAuthState === CONST.AUTO_AUTH_STATE.NOT_STARTED && !isSignedIn && (
Copy link
Contributor

Choose a reason for hiding this comment

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

@BeeMargarida Do you remember why we had to add the !isSignedIn condition here? This caused a regression #21258

Copy link
Contributor Author

@BeeMargarida BeeMargarida Jun 26, 2023

Choose a reason for hiding this comment

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

@s77rt Yes, it came from this commit to fix this bug mentioned in this slack thread.

Before, it was necessary because the check for AbracadabraModal (now JustSignedInModal) used NOT_STARTED state (this is because the state was cleaned on startup - mentioned in the proposal), so we needed to differentiate between that one and the one for ValidateCodeModal. At the time, the only difference was that for the abracadabra, the isSignedIn was true and false for the ValidateCodeModal.
I don't think it was a regression from here specifically, since this changed a lot after this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

@BeeMargarida Thank you!

<ValidateCodeModal
accountID={this.getAccountID()}
code={this.getValidateCode()}
/>
)}
{this.getAutoAuthState() === CONST.AUTO_AUTH_STATE.SIGNING_IN && <FullScreenLoadingIndicator />}
{currentAuthState === CONST.AUTO_AUTH_STATE.SIGNING_IN && <FullScreenLoadingIndicator />}
</>
);
}
Expand Down
7 changes: 5 additions & 2 deletions src/pages/settings/Security/TwoFactorAuth/CodesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import compose from '../../../../libs/compose';
import ROUTES from '../../../../ROUTES';
import FullPageOfflineBlockingView from '../../../../components/BlockingViews/FullPageOfflineBlockingView';
import * as Illustrations from '../../../../components/Icon/Illustrations';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../../components/withWindowDimensions';
import styles from '../../../../styles/styles';
import FixedFooter from '../../../../components/FixedFooter';
import Button from '../../../../components/Button';
Expand All @@ -24,6 +25,7 @@ import * as TwoFactorAuthActions from '../../../../libs/actions/TwoFactorAuthAct

const propTypes = {
...withLocalizePropTypes,
...windowDimensionsPropTypes,
account: PropTypes.shape({
/** User recovery codes for setting up 2-FA */
recoveryCodes: PropTypes.string,
Expand Down Expand Up @@ -73,7 +75,7 @@ function CodesPage(props) {
<View style={styles.mv3}>
<Text>{props.translate('twoFactorAuth.codesLoseAccess')}</Text>
</View>
<View style={styles.twoFactorAuthCodesBox}>
<View style={[styles.twoFactorAuthCodesBox, {paddingHorizontal: props.isSmallScreenWidth ? styles.ph10 : styles.ph15}]}>
{props.account.isLoading ? (
<View style={styles.twoFactorLoadingContainer}>
<ActivityIndicator color={themeColors.spinner} />
Expand Down Expand Up @@ -102,7 +104,7 @@ function CodesPage(props) {
style={styles.twoFactorAuthCodesButton}
/>
<Button
text="Download"
text={props.translate('common.download')}
medium
onPress={() => {
localFileDownload('two-factor-auth-codes', props.account.recoveryCodes);
Expand Down Expand Up @@ -133,6 +135,7 @@ CodesPage.defaultProps = defaultProps;

export default compose(
withLocalize,
withWindowDimensions,
withOnyx({
account: {key: ONYXKEYS.ACCOUNT},
}),
Expand Down
5 changes: 5 additions & 0 deletions src/pages/settings/Security/TwoFactorAuth/VerifyPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Navigation from '../../../../libs/Navigation/Navigation';
import ScreenWrapper from '../../../../components/ScreenWrapper';
import withLocalize, {withLocalizePropTypes} from '../../../../components/withLocalize';
import compose from '../../../../libs/compose';
import * as Session from '../../../../libs/actions/Session';
import ROUTES from '../../../../ROUTES';
import FullPageOfflineBlockingView from '../../../../components/BlockingViews/FullPageOfflineBlockingView';
import styles from '../../../../styles/styles';
Expand Down Expand Up @@ -51,6 +52,10 @@ const defaultProps = {
};

function VerifyPage(props) {
useEffect(() => {
Session.clearAccountMessages();
}, []);

useEffect(() => {
if (!props.account.requiresTwoFactorAuth) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/signin/PasswordForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const propTypes = {

/** The details about the account that the user is signing in with */
account: PropTypes.shape({
/** Whether or not two factor authentication is required */
/** Whether or not two-factor authentication is required */
requiresTwoFactorAuth: PropTypes.bool,

/** Whether or not a sign on form is loading (being submitted) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const propTypes = {

/** The details about the account that the user is signing in with */
account: PropTypes.shape({
/** Whether or not two factor authentication is required */
/** Whether or not two-factor authentication is required */
requiresTwoFactorAuth: PropTypes.bool,

/** Whether or not a sign on form is loading (being submitted) */
Expand Down
1 change: 0 additions & 1 deletion src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2137,7 +2137,6 @@ const styles = {
justifyContent: 'center',
backgroundColor: themeColors.highlightBG,
paddingVertical: 28,
paddingHorizontal: 60,
borderRadius: 16,
marginTop: 32,
},
Expand Down
4 changes: 4 additions & 0 deletions src/styles/utilities/spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ export default {
paddingHorizontal: 40,
},

ph15: {
paddingHorizontal: 60,
},

ph25: {
paddingHorizontal: 100,
},
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/ValidationUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ const ValidationUtils = require('../../src/libs/ValidationUtils');

describe('ValidationUtils', () => {
describe('isValidTwoFactorCode', () => {
test('numeric two factor code', () => {
test('numeric two-factor code', () => {
expect(ValidationUtils.isValidTwoFactorCode('123456')).toBe(true);
});

test('numeric two factor code with leading zeroes', () => {
test('numeric two-factor code with leading zeroes', () => {
expect(ValidationUtils.isValidTwoFactorCode('000001')).toBe(true);
});

test('alphanumeric two factor code', () => {
test('alphanumeric two-factor code', () => {
expect(ValidationUtils.isValidTwoFactorCode('abc123')).toBe(false);
});

test('special characters two factor code', () => {
test('special characters two-factor code', () => {
expect(ValidationUtils.isValidTwoFactorCode('!@#$%^')).toBe(false);
});

test('partial special characters two factor code', () => {
test('partial special characters two-factor code', () => {
expect(ValidationUtils.isValidTwoFactorCode('123$%^')).toBe(false);
});
});
Expand Down