@alphapoint/apex-web 5.5.6 → 5.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/apex.integration.test.js +435 -0
- package/lib/apex.js +37 -1
- package/lib/apex.test.js +138 -0
- package/lib/components/2FA/PasskeyOption.js +126 -0
- package/lib/components/2FA/TwoFactorAuthComponent.js +24 -5
- package/lib/components/2FA/TwoFactorAuthComponent.test.js +94 -0
- package/lib/components/2FA/TwoFactorAuthContainer.js +139 -27
- package/lib/components/2FA/TwoFactorAuthContainer.test.js +627 -0
- package/lib/components/AccountsDropdown/AccountsDropdownComponent.css +6 -0
- package/lib/components/AccountsDropdown/AccountsDropdownComponent.js +6 -2
- package/lib/components/AccountsDropdown/AccountsDropdownComponent.test.js +43 -0
- package/lib/components/AccountsDropdown/AccountsDropdownContainer.js +3 -1
- package/lib/components/BalancesList/BalancesListContainer.js +4 -1
- package/lib/components/ConfirmBlockTradeModal/ConfirmBlockTradeModalContainer.js +34 -6
- package/lib/components/ConfirmBlockTradeModal/ConfirmBlockTradeModalContainer.test.js +298 -0
- package/lib/components/ConfirmOrderModal/ConfirmOrderModalComponent.js +26 -4
- package/lib/components/ConfirmOrderModal/ConfirmOrderModalContainer.js +4 -1
- package/lib/components/DigitalAssets/digitalAssetsPriceLabel.test.js +238 -0
- package/lib/components/EnableTwoFactorAuth/Disable2FAForm.js +22 -7
- package/lib/components/EnableTwoFactorAuth/Disable2FAModal.js +15 -5
- package/lib/components/EnableTwoFactorAuth/Disable2FAModal.test.js +460 -0
- package/lib/components/EnableTwoFactorAuth/Disable2FAModalContainer.js +108 -16
- package/lib/components/EnableTwoFactorAuth/EnableTwoFactorAuthComponent.js +7 -0
- package/lib/components/EnableTwoFactorAuth/EnableTwoFactorAuthComponent.test.js +105 -0
- package/lib/components/EnableTwoFactorAuth/EnableTwoFactorAuthContainerFactory.js +15 -3
- package/lib/components/FusionAuth/UnlinkOAuthIdentityModal.css +13 -0
- package/lib/components/FusionAuth/UnlinkOAuthIdentityModal.js +246 -0
- package/lib/components/FusionAuth/UnlinkOAuthIdentityModal.test.js +521 -0
- package/lib/components/InstrumentPositions/InstrumentPositionsContainer.js +4 -1
- package/lib/components/Login/LoginFormComponent.js +1 -1
- package/lib/components/MarginBalances/MarginDepositWithdraw/MarginDepositModal/MarginDepositFormContainer.js +2 -1
- package/lib/components/NoAccountBanner/NoAccountBanner.css +9 -0
- package/lib/components/NoAccountBanner/NoAccountBanner.js +58 -0
- package/lib/components/NoAccountBanner/index.js +16 -0
- package/lib/components/NoAccountPlaceholder/NoAccountPlaceholder.css +31 -0
- package/lib/components/NoAccountPlaceholder/NoAccountPlaceholder.js +33 -0
- package/lib/components/NoAccountPlaceholder/index.js +9 -0
- package/lib/components/OrderEntryComponents/advancedForm/AdvancedOrderFormContainer.js +2 -0
- package/lib/components/OrderEntryComponents/common/FormAmountFields.js +5 -0
- package/lib/components/OrderEntryComponents/common/TwapScheduleFields.js +98 -0
- package/lib/components/OrderEntryComponents/defaultForm/OrderEntryAnchoring.js +86 -39
- package/lib/components/OrderEntryComponents/defaultForm/OrderEntryAnchoring.test.js +326 -0
- package/lib/components/OrderEntryComponents/defaultForm/OrderEntryContainer.js +10 -2
- package/lib/components/OrderHistoryComponents/DepositsStatus/DepositsStatusComponent.js +1 -1
- package/lib/components/OrderHistoryComponents/DepositsStatus/DepositsStatusComponent.test.js +99 -0
- package/lib/components/OrderHistoryComponents/InactiveOrders/InactiveOrdersComponent.js +1 -1
- package/lib/components/OrderHistoryComponents/OpenOrders/OpenOrdersComponent.js +1 -1
- package/lib/components/OrderHistoryComponents/WithdrawStatus/WithdrawStatusComponent.js +1 -1
- package/lib/components/OrderHistoryComponents/WithdrawStatus/WithdrawStatusComponent.test.js +113 -0
- package/lib/components/Settings/ProfileAndSecurity/PasskeysSettingsCard/PasskeysSettingsCard.css +108 -0
- package/lib/components/Settings/ProfileAndSecurity/PasskeysSettingsCard/PasskeysSettingsCard.test.js +983 -0
- package/lib/components/Settings/ProfileAndSecurity/PasskeysSettingsCard/PasskeysSettingsCardComponent.js +500 -0
- package/lib/components/Settings/ProfileAndSecurity/PasskeysSettingsCard/index.js +9 -0
- package/lib/components/Settings/ProfileAndSecurity/ProfileSettingsCard/ProfileForm/SsoLinkRowComponent.css +4 -0
- package/lib/components/Settings/ProfileAndSecurity/ProfileSettingsCard/ProfileForm/SsoLinkRowComponent.js +29 -17
- package/lib/components/Settings/ProfileAndSecurity/ProfileSettingsCard/ProfileForm/SsoLinkRowComponent.test.js +135 -0
- package/lib/components/Settings/ProfileAndSecurity/TwoFactorAuthSettingsCard/EnableTwoFactorAuth/EnableTwoFactorAuthComponent.js +12 -4
- package/lib/components/Settings/ProfileAndSecurity/TwoFactorAuthSettingsCard/EnableTwoFactorAuth/EnableTwoFactorAuthComponent.test.js +268 -0
- package/lib/components/TwoFactorAuthForm/TwoFactorAuthForm.test.js +475 -0
- package/lib/components/TwoFactorAuthForm/TwoFactorAuthFormComponent.js +26 -5
- package/lib/components/TwoFactorAuthForm/TwoFactorAuthFormContainer.js +50 -32
- package/lib/components/common/APAutoTabInput/APAutoTabInput.js +5 -2
- package/lib/components/common/APSelect/APSelect.js +3 -1
- package/lib/components/common/ErrorBoundary/ErrorBoundary.css +35 -0
- package/lib/components/common/ErrorBoundary/ErrorBoundary.js +87 -0
- package/lib/config/CONFIG.md +4 -0
- package/lib/config/configDefault.json +2 -1
- package/lib/constants/sendOrder/orderEntryFormConstants.js +23 -4
- package/lib/constants/sendOrder/timeInForceConstants.js +3 -1
- package/lib/constants/sendOrder/twapRejectReasons.js +26 -0
- package/lib/helpers/errorTextFormatter.js +13 -4
- package/lib/helpers/errorTextFormatter.test.js +26 -0
- package/lib/helpers/orderHistoryHelper.js +13 -1
- package/lib/helpers/orderHistoryHelper.test.js +58 -13
- package/lib/helpers/passkeyApi.js +228 -0
- package/lib/helpers/passkeyApi.test.js +171 -0
- package/lib/helpers/placeOrderHelper.js +76 -61
- package/lib/helpers/placeOrderHelper.test.js +169 -10
- package/lib/helpers/recalculateOrderHelper.js +4 -1
- package/lib/helpers/recalculateOrderHelper.test.js +88 -2
- package/lib/helpers/twapOrderHelper.js +265 -0
- package/lib/helpers/twapOrderHelper.test.js +467 -0
- package/lib/helpers/twoFactorAuthCancellation.js +38 -0
- package/lib/helpers/webauthnHelper.js +300 -0
- package/lib/helpers/webauthnHelper.test.js +199 -0
- package/lib/hocs/forAccount.js +33 -0
- package/lib/hocs/forAccount.test.js +50 -0
- package/lib/hocs/forVerified.js +16 -2
- package/lib/hocs/withAuthentication.js +3 -1
- package/lib/hocs/withOneSubmission.js +168 -0
- package/lib/index.js +3 -2
- package/lib/layouts/HeaderLayout/HeaderLayout.js +2 -1
- package/lib/layouts/WalletsLayout/WalletsLayoutContainer.js +3 -1
- package/lib/layouts/WalletsLayout/WalletsLayoutContainer.test.js +84 -0
- package/lib/redux/actions/apiActions.js +77 -9
- package/lib/redux/actions/apiActions.test.js +233 -0
- package/lib/redux/actions/authActions.js +514 -198
- package/lib/redux/actions/authActions.test.js +627 -47
- package/lib/redux/actions/depositActions.js +1 -1
- package/lib/redux/actions/depositActions.test.js +100 -30
- package/lib/redux/actions/fusionAuthActions.test.js +265 -84
- package/lib/redux/actions/interestAccountActions.js +12 -3
- package/lib/redux/actions/interestAccountActions.test.js +73 -0
- package/lib/redux/actions/modalActions.js +1 -0
- package/lib/redux/actions/orderEntryActions.blockTrade.test.js +306 -0
- package/lib/redux/actions/orderEntryActions.js +74 -22
- package/lib/redux/actions/orderEntryActions.test.js +63 -11
- package/lib/redux/actions/orderHistoryActions.js +20 -8
- package/lib/redux/actions/orderHistoryActions.test.js +63 -0
- package/lib/redux/actions/userActions.js +379 -179
- package/lib/redux/actions/userActions.test.js +925 -234
- package/lib/redux/actions/withdrawActions.js +62 -29
- package/lib/redux/actions/withdrawActions.test.js +246 -73
- package/lib/redux/actions/withdrawActions.travelRule.test.js +17 -3
- package/lib/redux/margin/actions/marginActions.js +6 -3
- package/lib/redux/margin/actions/marginActions.test.js +166 -0
- package/lib/redux/middlewares/authMiddleware.js +5 -0
- package/lib/redux/middlewares/authMiddleware.test.js +88 -29
- package/lib/redux/reducers/authReducer.js +1 -0
- package/lib/redux/reducers/authReducer.test.js +38 -0
- package/lib/redux/reducers/userReducer.js +10 -0
- package/lib/redux/reducers/userReducer.test.js +29 -0
- package/lib/redux/selectors/orderEntrySelector.js +19 -8
- package/lib/redux/selectors/orderEntrySelector.test.js +209 -0
- package/lib/redux/selectors/orderTotalSelector.test.js +40 -1
- package/lib/redux/selectors/recentActivitySelector.js +8 -2
- package/lib/redux/selectors/recentActivitySelector.v2.test.js +33 -0
- package/lib/redux/selectors/userSelectors.js +6 -1
- package/lib/redux/selectors/userSelectors.test.js +28 -0
- package/lib/services/fms/fms.js +2 -0
- package/lib/services/fms/fms.test.js +35 -0
- package/package.json +4 -4
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
5
|
+
var _client = require("react-dom/client");
|
|
6
|
+
var _reactRedux = require("react-redux");
|
|
7
|
+
var _redux = require("redux");
|
|
8
|
+
var _SsoLinkRowComponent = _interopRequireDefault(require("./SsoLinkRowComponent"));
|
|
9
|
+
var _modalActions = require("../../../../../redux/actions/modalActions");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
12
|
+
jest.mock('react-i18next', function () {
|
|
13
|
+
return {
|
|
14
|
+
useTranslation: function useTranslation() {
|
|
15
|
+
return {
|
|
16
|
+
t: function t(key, vars) {
|
|
17
|
+
return vars && vars.provider ? "".concat(key, " ").concat(vars.provider) : key;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// the dialogs are not under test; they need the modal slice of a full store
|
|
25
|
+
jest.mock('../../../../FusionAuth/LinkOAuthIdentityModal', function () {
|
|
26
|
+
return function () {
|
|
27
|
+
return null;
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
jest.mock('../../../../FusionAuth/UnlinkOAuthIdentityModal', function () {
|
|
31
|
+
return function () {
|
|
32
|
+
return null;
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
36
|
+
var render = function render(userInfo) {
|
|
37
|
+
var dispatched = [];
|
|
38
|
+
var store = (0, _redux.createStore)((0, _redux.combineReducers)({
|
|
39
|
+
user: function user() {
|
|
40
|
+
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
41
|
+
userInfo: userInfo
|
|
42
|
+
};
|
|
43
|
+
return state;
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
var dispatch = store.dispatch;
|
|
47
|
+
store.dispatch = function (action) {
|
|
48
|
+
dispatched.push(action);
|
|
49
|
+
return dispatch(action);
|
|
50
|
+
};
|
|
51
|
+
var container = document.createElement('div');
|
|
52
|
+
document.body.appendChild(container);
|
|
53
|
+
var root = (0, _client.createRoot)(container);
|
|
54
|
+
(0, _react.act)(function () {
|
|
55
|
+
root.render(/*#__PURE__*/_react["default"].createElement(_reactRedux.Provider, {
|
|
56
|
+
store: store
|
|
57
|
+
}, /*#__PURE__*/_react["default"].createElement(_SsoLinkRowComponent["default"], null)));
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
container: container,
|
|
61
|
+
dispatched: dispatched,
|
|
62
|
+
unmount: function unmount() {
|
|
63
|
+
(0, _react.act)(function () {
|
|
64
|
+
return root.unmount();
|
|
65
|
+
});
|
|
66
|
+
container.remove();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
var click = function click(el) {
|
|
71
|
+
return (0, _react.act)(function () {
|
|
72
|
+
return el.dispatchEvent(new MouseEvent('click', {
|
|
73
|
+
bubbles: true
|
|
74
|
+
}));
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
describe('SsoLinkRowComponent', function () {
|
|
78
|
+
var mounted;
|
|
79
|
+
afterEach(function () {
|
|
80
|
+
if (mounted) mounted.unmount();
|
|
81
|
+
mounted = null;
|
|
82
|
+
});
|
|
83
|
+
it('offers Disable SSO when the user is linked and the exchange allows it, and opens the unlink dialog', function () {
|
|
84
|
+
mounted = render({
|
|
85
|
+
IsOAuthUser: true,
|
|
86
|
+
OAuthProvider: 'FusionAuth',
|
|
87
|
+
SelfServiceSsoUnlinkEnabled: true
|
|
88
|
+
});
|
|
89
|
+
expect(mounted.container.textContent).toContain('Linked to {{provider}} FusionAuth');
|
|
90
|
+
expect(mounted.container.querySelector('button[name="linkOAuthIdentity"]')).toBeNull();
|
|
91
|
+
var button = mounted.container.querySelector('button[name="unlinkOAuthIdentity"]');
|
|
92
|
+
expect(button.textContent).toBe('Disable SSO');
|
|
93
|
+
click(button);
|
|
94
|
+
expect(mounted.dispatched).toContainEqual({
|
|
95
|
+
type: _modalActions.OPEN_MODAL,
|
|
96
|
+
payload: {
|
|
97
|
+
name: _modalActions.MODAL_TYPES.UNLINK_OAUTH_IDENTITY,
|
|
98
|
+
modalProps: undefined
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
it('shows only the linked provider when the exchange has self-service unlinking off', function () {
|
|
103
|
+
mounted = render({
|
|
104
|
+
IsOAuthUser: true,
|
|
105
|
+
OAuthProvider: 'FusionAuth',
|
|
106
|
+
SelfServiceSsoUnlinkEnabled: false
|
|
107
|
+
});
|
|
108
|
+
expect(mounted.container.textContent).toContain('Linked to {{provider}} FusionAuth');
|
|
109
|
+
expect(mounted.container.querySelector('button[name="unlinkOAuthIdentity"]')).toBeNull();
|
|
110
|
+
expect(mounted.container.querySelector('button[name="linkOAuthIdentity"]')).toBeNull();
|
|
111
|
+
});
|
|
112
|
+
it('treats a missing flag as off', function () {
|
|
113
|
+
mounted = render({
|
|
114
|
+
IsOAuthUser: true,
|
|
115
|
+
OAuthProvider: 'FusionAuth'
|
|
116
|
+
});
|
|
117
|
+
expect(mounted.container.querySelector('button[name="unlinkOAuthIdentity"]')).toBeNull();
|
|
118
|
+
});
|
|
119
|
+
it('offers Link with SSO Provider when the user is not linked', function () {
|
|
120
|
+
mounted = render({
|
|
121
|
+
IsOAuthUser: false
|
|
122
|
+
});
|
|
123
|
+
expect(mounted.container.querySelector('button[name="unlinkOAuthIdentity"]')).toBeNull();
|
|
124
|
+
var button = mounted.container.querySelector('button[name="linkOAuthIdentity"]');
|
|
125
|
+
expect(button.textContent).toBe('Link with SSO Provider');
|
|
126
|
+
click(button);
|
|
127
|
+
expect(mounted.dispatched).toContainEqual({
|
|
128
|
+
type: _modalActions.OPEN_MODAL,
|
|
129
|
+
payload: {
|
|
130
|
+
name: _modalActions.MODAL_TYPES.LINK_OAUTH_IDENTITY,
|
|
131
|
+
modalProps: undefined
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -18,7 +18,7 @@ require("./EnableTwoFactorAuthComponent.css");
|
|
|
18
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
19
19
|
var bemClasses = (0, _cssClassesHelper.getBEMClasses)('settings-enable-two-factor-auth');
|
|
20
20
|
var EnableTwoFactorAuthComponent = function EnableTwoFactorAuthComponent(props) {
|
|
21
|
-
var _useTranslation = (0, _reactI18next.useTranslation)(
|
|
21
|
+
var _useTranslation = (0, _reactI18next.useTranslation)('auth'),
|
|
22
22
|
t = _useTranslation.t;
|
|
23
23
|
var handleClick = function handleClick(newValue) {
|
|
24
24
|
if (newValue) {
|
|
@@ -27,6 +27,13 @@ var EnableTwoFactorAuthComponent = function EnableTwoFactorAuthComponent(props)
|
|
|
27
27
|
props.enable2FA();
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
+
if (props.ssoManagedTwoFactor) {
|
|
31
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
32
|
+
className: bemClasses()
|
|
33
|
+
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
34
|
+
className: bemClasses('info')
|
|
35
|
+
}, /*#__PURE__*/_react["default"].createElement("p", null, t('Two-factor authentication for this account is managed by your single sign-on provider.'))));
|
|
36
|
+
}
|
|
30
37
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
31
38
|
className: bemClasses()
|
|
32
39
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
@@ -38,17 +45,18 @@ var EnableTwoFactorAuthComponent = function EnableTwoFactorAuthComponent(props)
|
|
|
38
45
|
onClick: handleClick
|
|
39
46
|
})), /*#__PURE__*/_react["default"].createElement("div", {
|
|
40
47
|
className: bemClasses('info')
|
|
41
|
-
}, /*#__PURE__*/_react["default"].createElement("p", null, t(
|
|
48
|
+
}, /*#__PURE__*/_react["default"].createElement("p", null, t('Two-Factor Authentication (2FA) adds another layer of protection to your account by requiring an additional passcode during the logging in process.')), props.TwoFAType !== _userConfigConstants.TwoFaTypes.Yubico && /*#__PURE__*/_react["default"].createElement("p", null, t('You will need to download Google Authenticator on your smartphone as part of the process to enable 2FA.')))), props.showRecoverySeed && /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_APButton["default"], {
|
|
42
49
|
name: "recovery2FA",
|
|
43
50
|
customClass: bemClasses(),
|
|
44
51
|
onClick: props.getGoogle2FARecoveryKey
|
|
45
|
-
}, t(
|
|
52
|
+
}, t('Recovery'))), /*#__PURE__*/_react["default"].createElement(_Enable2FAModalContainer["default"], null), /*#__PURE__*/_react["default"].createElement(_Disable2FAModalContainer["default"], null), /*#__PURE__*/_react["default"].createElement(_GetGoogle2FARecoveryKeyModalContainer["default"], null));
|
|
46
53
|
};
|
|
47
54
|
EnableTwoFactorAuthComponent.propTypes = {
|
|
48
55
|
getGoogle2FARecoveryKey: _propTypes["default"].func.isRequired,
|
|
49
56
|
disable2FA: _propTypes["default"].func.isRequired,
|
|
50
57
|
enable2FA: _propTypes["default"].func.isRequired,
|
|
51
58
|
showRecoverySeed: _propTypes["default"].bool.isRequired,
|
|
52
|
-
TwoFAType: _propTypes["default"].string
|
|
59
|
+
TwoFAType: _propTypes["default"].string,
|
|
60
|
+
ssoManagedTwoFactor: _propTypes["default"].bool
|
|
53
61
|
};
|
|
54
62
|
var _default = exports["default"] = EnableTwoFactorAuthComponent;
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
5
|
+
var _client = require("react-dom/client");
|
|
6
|
+
var _reactRedux = require("react-redux");
|
|
7
|
+
var _redux = require("redux");
|
|
8
|
+
var _reduxThunk = _interopRequireDefault(require("redux-thunk"));
|
|
9
|
+
var _reduxForm = require("redux-form");
|
|
10
|
+
var _apex = _interopRequireDefault(require("../../../../../apex"));
|
|
11
|
+
var _EnableTwoFactorAuthContainerFactory = _interopRequireDefault(require("../../../../EnableTwoFactorAuth/EnableTwoFactorAuthContainerFactory"));
|
|
12
|
+
var _EnableTwoFactorAuthComponent = _interopRequireDefault(require("./EnableTwoFactorAuthComponent"));
|
|
13
|
+
var _modalActions = require("../../../../../redux/actions/modalActions");
|
|
14
|
+
var _snackbarActions = require("../../../../../redux/actions/snackbarActions");
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
16
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
17
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
18
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
19
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
20
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
21
|
+
jest.mock('../../../../../apex', function () {
|
|
22
|
+
return {
|
|
23
|
+
__esModule: true,
|
|
24
|
+
"default": {
|
|
25
|
+
connection: {
|
|
26
|
+
EnableGoogle2FA: jest.fn()
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
jest.mock('react-i18next', function () {
|
|
32
|
+
return {
|
|
33
|
+
useTranslation: function useTranslation() {
|
|
34
|
+
return {
|
|
35
|
+
t: function t(key) {
|
|
36
|
+
return key;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// the modals are not under test; they need the modal and QR code slices of a full store
|
|
44
|
+
jest.mock('../../../../EnableTwoFactorAuth/Enable2FAModalContainer', function () {
|
|
45
|
+
return function () {
|
|
46
|
+
return null;
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
jest.mock('../../../../EnableTwoFactorAuth/Disable2FAModalContainer', function () {
|
|
50
|
+
return function () {
|
|
51
|
+
return null;
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
jest.mock('../../../../EnableTwoFactorAuth/GetGoogle2FARecoveryKeyModalContainer', function () {
|
|
55
|
+
return function () {
|
|
56
|
+
return null;
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
60
|
+
var SSO_MESSAGE = 'Two-factor authentication for this account is managed by your single sign-on provider.';
|
|
61
|
+
var EnableTwoFactorAuthContainer = (0, _EnableTwoFactorAuthContainerFactory["default"])(_EnableTwoFactorAuthComponent["default"]);
|
|
62
|
+
var render = function render(userInfo) {
|
|
63
|
+
var userConfig = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
64
|
+
var actions = [];
|
|
65
|
+
var record = function record() {
|
|
66
|
+
return function (next) {
|
|
67
|
+
return function (action) {
|
|
68
|
+
actions.push(action);
|
|
69
|
+
return next(action);
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
var store = (0, _redux.createStore)((0, _redux.combineReducers)({
|
|
74
|
+
form: _reduxForm.reducer,
|
|
75
|
+
user: function user() {
|
|
76
|
+
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
77
|
+
userInfo: userInfo,
|
|
78
|
+
userConfig: userConfig
|
|
79
|
+
};
|
|
80
|
+
return state;
|
|
81
|
+
},
|
|
82
|
+
snackbar: function snackbar() {
|
|
83
|
+
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
84
|
+
snacks: []
|
|
85
|
+
};
|
|
86
|
+
return state;
|
|
87
|
+
}
|
|
88
|
+
}), (0, _redux.applyMiddleware)(_reduxThunk["default"], record));
|
|
89
|
+
var container = document.createElement('div');
|
|
90
|
+
document.body.appendChild(container);
|
|
91
|
+
var root = (0, _client.createRoot)(container);
|
|
92
|
+
(0, _react.act)(function () {
|
|
93
|
+
return root.render(/*#__PURE__*/_react["default"].createElement(_reactRedux.Provider, {
|
|
94
|
+
store: store
|
|
95
|
+
}, /*#__PURE__*/_react["default"].createElement(EnableTwoFactorAuthContainer, null)));
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
actions: actions,
|
|
99
|
+
switchControl: function switchControl() {
|
|
100
|
+
return container.querySelector('.ap-switch__switch');
|
|
101
|
+
},
|
|
102
|
+
recoveryButton: function recoveryButton() {
|
|
103
|
+
return container.querySelector('button[name="recovery2FA"]');
|
|
104
|
+
},
|
|
105
|
+
text: function text() {
|
|
106
|
+
return container.textContent;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
describe('Profile & Security two-factor card', function () {
|
|
111
|
+
beforeEach(function () {
|
|
112
|
+
jest.clearAllMocks();
|
|
113
|
+
});
|
|
114
|
+
afterEach(function () {
|
|
115
|
+
document.body.innerHTML = '';
|
|
116
|
+
});
|
|
117
|
+
it('offers the 2FA switch to a password user', function () {
|
|
118
|
+
var card = render({
|
|
119
|
+
Use2FA: false,
|
|
120
|
+
IsOAuthUser: false
|
|
121
|
+
});
|
|
122
|
+
expect(card.switchControl()).not.toBeNull();
|
|
123
|
+
expect(card.text()).not.toContain(SSO_MESSAGE);
|
|
124
|
+
});
|
|
125
|
+
it('replaces the switch with the SSO message for an SSO user', function () {
|
|
126
|
+
var card = render({
|
|
127
|
+
Use2FA: false,
|
|
128
|
+
IsOAuthUser: true
|
|
129
|
+
});
|
|
130
|
+
expect(card.switchControl()).toBeNull();
|
|
131
|
+
expect(card.text()).toContain(SSO_MESSAGE);
|
|
132
|
+
});
|
|
133
|
+
it('keeps the switch for an SSO user who already has local 2FA, so it can be turned off', function () {
|
|
134
|
+
var card = render({
|
|
135
|
+
Use2FA: true,
|
|
136
|
+
IsOAuthUser: true
|
|
137
|
+
});
|
|
138
|
+
expect(card.switchControl()).not.toBeNull();
|
|
139
|
+
expect(card.text()).not.toContain(SSO_MESSAGE);
|
|
140
|
+
});
|
|
141
|
+
it('offers the recovery key to an authenticator user', function () {
|
|
142
|
+
var card = render({
|
|
143
|
+
Use2FA: true
|
|
144
|
+
}, [{
|
|
145
|
+
Key: '2FAType',
|
|
146
|
+
Value: 'Google'
|
|
147
|
+
}]);
|
|
148
|
+
expect(card.recoveryButton()).not.toBeNull();
|
|
149
|
+
});
|
|
150
|
+
it('hides the recovery key from a user whose 2FA type is passkey, as the gateway needs an authenticator code', function () {
|
|
151
|
+
var card = render({
|
|
152
|
+
Use2FA: true
|
|
153
|
+
}, [{
|
|
154
|
+
Key: '2FAType',
|
|
155
|
+
Value: 'WebAuthn'
|
|
156
|
+
}]);
|
|
157
|
+
expect(card.recoveryButton()).toBeNull();
|
|
158
|
+
});
|
|
159
|
+
it('opens the enrol modal when the gateway returns a QR code', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
160
|
+
var card;
|
|
161
|
+
return _regenerator().w(function (_context2) {
|
|
162
|
+
while (1) switch (_context2.n) {
|
|
163
|
+
case 0:
|
|
164
|
+
_apex["default"].connection.EnableGoogle2FA.mockResolvedValueOnce({
|
|
165
|
+
GoogleQRCode: 'otpauth://totp/x',
|
|
166
|
+
ManualCode: 'ABC'
|
|
167
|
+
});
|
|
168
|
+
card = render({
|
|
169
|
+
Use2FA: false,
|
|
170
|
+
IsOAuthUser: false
|
|
171
|
+
});
|
|
172
|
+
_context2.n = 1;
|
|
173
|
+
return (0, _react.act)(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
174
|
+
return _regenerator().w(function (_context) {
|
|
175
|
+
while (1) switch (_context.n) {
|
|
176
|
+
case 0:
|
|
177
|
+
return _context.a(2, card.switchControl().click());
|
|
178
|
+
}
|
|
179
|
+
}, _callee);
|
|
180
|
+
})));
|
|
181
|
+
case 1:
|
|
182
|
+
expect(card.actions).toContainEqual({
|
|
183
|
+
type: _modalActions.OPEN_MODAL,
|
|
184
|
+
payload: {
|
|
185
|
+
name: _modalActions.MODAL_TYPES.ENABLE_2FA
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
case 2:
|
|
189
|
+
return _context2.a(2);
|
|
190
|
+
}
|
|
191
|
+
}, _callee2);
|
|
192
|
+
})));
|
|
193
|
+
it('shows the refusal and does not open the enrol modal when the gateway refuses', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
|
|
194
|
+
var card;
|
|
195
|
+
return _regenerator().w(function (_context4) {
|
|
196
|
+
while (1) switch (_context4.n) {
|
|
197
|
+
case 0:
|
|
198
|
+
_apex["default"].connection.EnableGoogle2FA.mockResolvedValueOnce({
|
|
199
|
+
result: false,
|
|
200
|
+
errormsg: SSO_MESSAGE,
|
|
201
|
+
errorcode: 104
|
|
202
|
+
});
|
|
203
|
+
card = render({
|
|
204
|
+
Use2FA: false,
|
|
205
|
+
IsOAuthUser: false
|
|
206
|
+
});
|
|
207
|
+
_context4.n = 1;
|
|
208
|
+
return (0, _react.act)(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
|
|
209
|
+
return _regenerator().w(function (_context3) {
|
|
210
|
+
while (1) switch (_context3.n) {
|
|
211
|
+
case 0:
|
|
212
|
+
return _context3.a(2, card.switchControl().click());
|
|
213
|
+
}
|
|
214
|
+
}, _callee3);
|
|
215
|
+
})));
|
|
216
|
+
case 1:
|
|
217
|
+
expect(card.actions).toContainEqual(expect.objectContaining({
|
|
218
|
+
type: _snackbarActions.ADD_SNACK,
|
|
219
|
+
payload: expect.objectContaining({
|
|
220
|
+
text: "104: ".concat(SSO_MESSAGE)
|
|
221
|
+
})
|
|
222
|
+
}));
|
|
223
|
+
expect(card.actions).not.toContainEqual(expect.objectContaining({
|
|
224
|
+
type: _modalActions.OPEN_MODAL
|
|
225
|
+
}));
|
|
226
|
+
expect(card.switchControl().textContent).toBe('Off');
|
|
227
|
+
case 2:
|
|
228
|
+
return _context4.a(2);
|
|
229
|
+
}
|
|
230
|
+
}, _callee4);
|
|
231
|
+
})));
|
|
232
|
+
it('still shows a warning when the refusal has no message', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
|
|
233
|
+
var card;
|
|
234
|
+
return _regenerator().w(function (_context6) {
|
|
235
|
+
while (1) switch (_context6.n) {
|
|
236
|
+
case 0:
|
|
237
|
+
_apex["default"].connection.EnableGoogle2FA.mockResolvedValueOnce({
|
|
238
|
+
result: false,
|
|
239
|
+
errormsg: '',
|
|
240
|
+
errorcode: 104
|
|
241
|
+
});
|
|
242
|
+
card = render({
|
|
243
|
+
Use2FA: false,
|
|
244
|
+
IsOAuthUser: false
|
|
245
|
+
});
|
|
246
|
+
_context6.n = 1;
|
|
247
|
+
return (0, _react.act)(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
|
|
248
|
+
return _regenerator().w(function (_context5) {
|
|
249
|
+
while (1) switch (_context5.n) {
|
|
250
|
+
case 0:
|
|
251
|
+
return _context5.a(2, card.switchControl().click());
|
|
252
|
+
}
|
|
253
|
+
}, _callee5);
|
|
254
|
+
})));
|
|
255
|
+
case 1:
|
|
256
|
+
expect(card.actions).toContainEqual(expect.objectContaining({
|
|
257
|
+
type: _snackbarActions.ADD_SNACK,
|
|
258
|
+
payload: expect.objectContaining({
|
|
259
|
+
text: 'Two-factor authentication could not be enabled.'
|
|
260
|
+
})
|
|
261
|
+
}));
|
|
262
|
+
expect(card.switchControl().textContent).toBe('Off');
|
|
263
|
+
case 2:
|
|
264
|
+
return _context6.a(2);
|
|
265
|
+
}
|
|
266
|
+
}, _callee6);
|
|
267
|
+
})));
|
|
268
|
+
});
|