Skip to content

Commit

Permalink
[SDK-2970] Remove captcha for enterprise SSO connections (#2071)
Browse files Browse the repository at this point in the history
* Hide captcha for SSO connections in login pane

* Add tests for sign-up pane + captcha

* Add tests for login pane + captcha

* Modify browserstack settings (rolls in #2065)

Co-authored-by: Adam Mcgrath <[email protected]>
  • Loading branch information
Steve Hobbs and adamjmcgrath authored Dec 21, 2021
1 parent f13a5ab commit 6e5b27d
Show file tree
Hide file tree
Showing 16 changed files with 824 additions and 467 deletions.
852 changes: 435 additions & 417 deletions build/lock.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/lock.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/lock.min.js.map

Large diffs are not rendered by default.

14 changes: 4 additions & 10 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function(config) {
module.exports = function (config) {
process.env.CHROME_BIN = require('puppeteer').executablePath();

config.set({
Expand Down Expand Up @@ -52,9 +52,9 @@ module.exports = function(config) {

browserNoActivityTimeout: 60000,

browserDisconnectTimeout: 20000,
browserDisconnectTimeout: 30000,

browserDisconnectTolerance: 3,
browserDisconnectTolerance: 10,

// level of logging
logLevel: config.LOG_INFO,
Expand Down Expand Up @@ -118,12 +118,6 @@ module.exports = function(config) {
}
},

browsers: [
'bs_chrome_windows',
'bs_firefox_windows',
'bs_safari',
'bs_ie11_windows',
'bs_edge_windows'
]
browsers: ['bs_chrome_windows']
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`LoginPane hides the captcha for SSO connections 1`] = `
<div>
<UsernamePane
i18n={Object {}}
lock={
Immutable.Map {
"id": "__lock-id__",
}
}
placeholder=""
strictValidation={false}
usernameStyle="username"
validateFormat={false}
/>
<PasswordPane
hidden={false}
i18n={Object {}}
lock={
Immutable.Map {
"id": "__lock-id__",
}
}
placeholder=""
/>
</div>
`;

exports[`LoginPane renders a captcha 1`] = `
<div>
<UsernamePane
i18n={Object {}}
lock={
Immutable.Map {
"id": "__lock-id__",
}
}
placeholder=""
strictValidation={false}
usernameStyle="username"
validateFormat={false}
/>
<PasswordPane
hidden={false}
i18n={Object {}}
lock={
Immutable.Map {
"id": "__lock-id__",
}
}
placeholder=""
/>
<CaptchaPane
error={false}
i18n={Object {}}
lock={
Immutable.Map {
"id": "__lock-id__",
}
}
onReload={[Function]}
/>
</div>
`;

exports[`LoginPane renders correctly 1`] = `
<div>
<UsernamePane
i18n={Object {}}
lock={
Immutable.Map {
"id": "__lock-id__",
}
}
placeholder=""
strictValidation={false}
usernameStyle="username"
validateFormat={false}
/>
<PasswordPane
hidden={false}
i18n={Object {}}
lock={
Immutable.Map {
"id": "__lock-id__",
}
}
placeholder=""
/>
</div>
`;

exports[`LoginPane shows the captcha for SSO (ADFS) connections 1`] = `
<div>
<UsernamePane
i18n={Object {}}
lock={
Immutable.Map {
"id": "__lock-id__",
}
}
placeholder=""
strictValidation={false}
usernameStyle="username"
validateFormat={false}
/>
<PasswordPane
hidden={false}
i18n={Object {}}
lock={
Immutable.Map {
"id": "__lock-id__",
}
}
placeholder=""
/>
<CaptchaPane
error={false}
i18n={Object {}}
lock={
Immutable.Map {
"id": "__lock-id__",
}
}
onReload={[Function]}
/>
</div>
`;
67 changes: 67 additions & 0 deletions src/__tests__/connection/database/login_pane.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react';
import I from 'immutable';
import { expectShallowComponent } from 'testUtils';
import LoginPane from '../../../connection/database/login_pane';

const lock = I.fromJS({ id: '__lock-id__' });

jest.mock('core/index');

jest.mock('engine/classic');
jest.mock('connection/enterprise');

describe('LoginPane', () => {
const defaultProps = {
emailInputPlaceholder: '',
forgotPasswordAction: '',
i18n: {},
passwordInputPlaceholder: '',
showForgotPasswordLink: true,
showPassword: true,
usernameInputPlaceholder: '',
lock
};

beforeEach(() => {
jest.resetAllMocks();
});

it('renders correctly', async () => {
expectShallowComponent(<LoginPane {...defaultProps} />).toMatchSnapshot();
});

it('renders a captcha', () => {
require('core/index').captcha.mockReturnValue({
get() {
return true;
}
});

expectShallowComponent(<LoginPane {...defaultProps} />).toMatchSnapshot();
});

it('hides the captcha for SSO connections', () => {
require('core/index').captcha.mockReturnValue({
get() {
return true;
}
});

require('engine/classic').isSSOEnabled.mockReturnValue(true);

expectShallowComponent(<LoginPane {...defaultProps} />).toMatchSnapshot();
});

it('shows the captcha for SSO (ADFS) connections', () => {
require('core/index').captcha.mockReturnValue({
get() {
return true;
}
});

require('engine/classic').isSSOEnabled.mockReturnValue(true);
require('connection/enterprise').isHRDDomain.mockReturnValue(true);

expectShallowComponent(<LoginPane {...defaultProps} />).toMatchSnapshot();
});
});
12 changes: 8 additions & 4 deletions src/__tests__/connection/enterprise/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import * as l from '../../../core/index';
import { setField } from '../../../field/index';

jest.mock('connection/database/index', () => ({
databaseLogInWithEmail: jest.fn(() => true)
databaseLogInWithEmail: jest.fn(() => true),
databaseUsernameValue: jest.fn()
}));

jest.mock('store/index', () => ({
Expand All @@ -17,7 +18,8 @@ jest.mock('store/index', () => ({
jest.mock('connection/enterprise', () => ({
matchConnection: jest.fn(),
enterpriseActiveFlowConnection: jest.fn(),
isHRDActive: jest.fn()
isHRDActive: jest.fn(),
isEnterpriseDomain: jest.fn()
}));

jest.mock('core/actions', () => ({
Expand Down Expand Up @@ -65,10 +67,12 @@ describe('Login with connection scopes', () => {
});
});

it('should throw an error if the captcha was not completed', () => {
it('should not throw an error if the captcha was not completed', () => {
lock = l.setup('__lock__', 'client', 'domain', {});
lock = setField(lock, 'email', '[email protected]');

// This will be specified in the response from the /challenge endpoint if the
// dashboard settings have Captcha as 'required', regardless of connection being used.
lock = l.setCaptcha(lock, {
required: true,
provider: 'recaptcha_v2'
Expand All @@ -83,7 +87,7 @@ describe('Login with connection scopes', () => {
const coreActions = require('core/actions');

logIn('__lock__');
expect(coreActions.logIn).not.toHaveBeenCalled();
expect(coreActions.logIn).toHaveBeenCalled();
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SignUpPane hides the Captcha pane for SSO connections 1`] = `
<div>
<Unknown
i18n={
Object {
"html": [Function],
"str": [Function],
}
}
lock="model"
placeholder="emailInputPlaceholder"
strictValidation={true}
/>
</div>
`;

exports[`SignUpPane onlyEmail is false hide UsernamePane when databaseConnectionRequiresUsername is true and signUpHideUsernameField is true 1`] = `
<div>
<div
Expand Down Expand Up @@ -182,3 +198,57 @@ exports[`SignUpPane shows header when instructions are available 1`] = `
/>
</div>
`;

exports[`SignUpPane shows the Captcha pane 1`] = `
<div>
<Unknown
i18n={
Object {
"html": [Function],
"str": [Function],
}
}
lock="model"
placeholder="emailInputPlaceholder"
strictValidation={true}
/>
<CaptchaPane
error={false}
i18n={
Object {
"html": [Function],
"str": [Function],
}
}
lock="model"
onReload={[Function]}
/>
</div>
`;

exports[`SignUpPane shows the Captcha pane for SSO (ADFS) connections 1`] = `
<div>
<Unknown
i18n={
Object {
"html": [Function],
"str": [Function],
}
}
lock="model"
placeholder="emailInputPlaceholder"
strictValidation={true}
/>
<CaptchaPane
error={false}
i18n={
Object {
"html": [Function],
"str": [Function],
}
}
lock="model"
onReload={[Function]}
/>
</div>
`;
3 changes: 1 addition & 2 deletions src/__tests__/engine/classic/login.test.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { mount } from 'enzyme';

import { expectComponent, extractPropsFromWrapper, mockComponent } from 'testUtils';
import { expectComponent, mockComponent } from 'testUtils';

jest.mock('core/pane_separator', () => mockComponent('pane_separator'));
jest.mock('field/social/social_buttons_pane', () => mockComponent('social_buttons_pane'));
Expand Down
Loading

0 comments on commit 6e5b27d

Please sign in to comment.