aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/sessions
diff options
context:
space:
mode:
authorJacek <jacek.poreda@sonarsource.com>2021-07-07 13:37:17 +0200
committersonartech <sonartech@sonarsource.com>2021-07-09 20:03:00 +0000
commitdedcd07375177612708036458183e5cb221fff6b (patch)
tree3366271f0d53895bb5928a0de0ceb33a9237dd94 /server/sonar-web/src/main/js/apps/sessions
parenta0c54d7328479914c288a10979307c49e6ab93fa (diff)
downloadsonarqube-dedcd07375177612708036458183e5cb221fff6b.tar.gz
sonarqube-dedcd07375177612708036458183e5cb221fff6b.zip
SONAR-15137 Prevent users from associating their account with a new identity provider
Diffstat (limited to 'server/sonar-web/src/main/js/apps/sessions')
-rw-r--r--server/sonar-web/src/main/js/apps/sessions/components/EmailAlreadyExists.tsx142
-rw-r--r--server/sonar-web/src/main/js/apps/sessions/components/__tests__/EmailAlreadyExists-test.tsx59
-rw-r--r--server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/EmailAlreadyExists-test.tsx.snap118
-rw-r--r--server/sonar-web/src/main/js/apps/sessions/routes.ts4
4 files changed, 0 insertions, 323 deletions
diff --git a/server/sonar-web/src/main/js/apps/sessions/components/EmailAlreadyExists.tsx b/server/sonar-web/src/main/js/apps/sessions/components/EmailAlreadyExists.tsx
deleted file mode 100644
index 08d5157a1ba..00000000000
--- a/server/sonar-web/src/main/js/apps/sessions/components/EmailAlreadyExists.tsx
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-import * as React from 'react';
-import { FormattedMessage } from 'react-intl';
-import { Alert } from 'sonar-ui-common/components/ui/Alert';
-import { getTextColor } from 'sonar-ui-common/helpers/colors';
-import { getCookie } from 'sonar-ui-common/helpers/cookies';
-import { translate } from 'sonar-ui-common/helpers/l10n';
-import { getBaseUrl } from 'sonar-ui-common/helpers/urls';
-import { getIdentityProviders } from '../../../api/users';
-import { colors } from '../../../app/theme';
-
-interface State {
- identityProviders: T.IdentityProvider[];
-}
-
-export default class EmailAlreadyExists extends React.PureComponent<{}, State> {
- mounted = false;
- state: State = { identityProviders: [] };
-
- componentDidMount() {
- this.mounted = true;
- this.fetchIdentityProviders();
- }
-
- componentWillUnmount() {
- this.mounted = false;
- }
-
- fetchIdentityProviders = () => {
- getIdentityProviders().then(
- ({ identityProviders }) => {
- if (this.mounted) {
- this.setState({ identityProviders });
- }
- },
- () => {}
- );
- };
-
- getAuthError = (): {
- email?: string;
- login?: string;
- provider?: string;
- existingLogin?: string;
- existingProvider?: string;
- } => {
- const cookie = getCookie('AUTHENTICATION-ERROR');
- if (cookie) {
- return JSON.parse(decodeURIComponent(cookie));
- }
- return {};
- };
-
- renderIdentityProvier = (provider?: string, login?: string) => {
- const identityProvider = this.state.identityProviders.find(p => p.key === provider);
-
- return identityProvider ? (
- <div
- className="identity-provider"
- style={{
- backgroundColor: identityProvider.backgroundColor,
- color: getTextColor(identityProvider.backgroundColor, colors.secondFontColor)
- }}>
- <img
- alt={identityProvider.name}
- className="little-spacer-right"
- height="14"
- src={getBaseUrl() + identityProvider.iconPath}
- width="14"
- />
- {login}
- </div>
- ) : (
- <div>
- {provider !== 'sonarqube' && provider} {login}
- </div>
- );
- };
-
- render() {
- const authError = this.getAuthError();
- return (
- <div className="page-wrapper-simple" id="bd">
- <div className="page-simple" id="nonav">
- <div className="big-spacer-bottom js-existing-account">
- <p className="little-spacer-bottom">
- <FormattedMessage
- defaultMessage={translate('sessions.email_already_exists.1')}
- id="sessions.email_already_exists.1"
- values={{ email: <strong>{authError.email}</strong> }}
- />
- </p>
- {this.renderIdentityProvier(authError.existingProvider, authError.existingLogin)}
- </div>
-
- <div className="big-spacer-bottom js-new-account">
- <p className="little-spacer-bottom">{translate('sessions.email_already_exists.2')}</p>
- {this.renderIdentityProvier(authError.provider, authError.login)}
- </div>
-
- <Alert variant="warning">
- {translate('sessions.email_already_exists.3')}
- <ul className="list-styled">
- <li className="spacer-top">{translate('sessions.email_already_exists.4')}</li>
- <li className="spacer-top">{translate('sessions.email_already_exists.5')}</li>
- <li className="spacer-top">{translate('sessions.email_already_exists.6')}</li>
- </ul>
- </Alert>
-
- <div className="big-spacer-top text-right">
- <a
- className="button js-continue"
- href={`${getBaseUrl()}/sessions/init/${authError.provider}?allowEmailShift=true`}>
- {translate('continue')}
- </a>
- <a className="big-spacer-left js-cancel" href={getBaseUrl() + '/'}>
- {translate('cancel')}
- </a>
- </div>
- </div>
- </div>
- );
- }
-}
diff --git a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/EmailAlreadyExists-test.tsx b/server/sonar-web/src/main/js/apps/sessions/components/__tests__/EmailAlreadyExists-test.tsx
deleted file mode 100644
index 411c33384bc..00000000000
--- a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/EmailAlreadyExists-test.tsx
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-import { shallow } from 'enzyme';
-import * as React from 'react';
-import { waitAndUpdate } from 'sonar-ui-common/helpers/testUtils';
-import EmailAlreadyExists from '../EmailAlreadyExists';
-
-jest.mock('../../../../api/users', () => ({
- getIdentityProviders: () =>
- Promise.resolve({
- identityProviders: [
- {
- key: 'bitbucket',
- name: 'Bitbucket',
- iconPath: '/static/authbitbucket/bitbucket.svg',
- backgroundColor: '#0052cc'
- },
- {
- key: 'github',
- name: 'GitHub',
- iconPath: '/static/authgithub/github.svg',
- backgroundColor: '#444444'
- }
- ]
- })
-}));
-
-jest.mock('sonar-ui-common/helpers/cookies', () => ({
- getCookie: jest
- .fn()
- .mockReturnValue(
- '%7B%22email%22%3A%22mail%40example.com%22%2C%22login%22%3A%22foo%22%2C%22provider%22%3A%22github%22%2C%22existingLogin%22%3A%22bar%22%2C%22existingProvider%22%3A%22bitbucket%22%7D'
- )
-}));
-
-it('render', async () => {
- const wrapper = shallow(<EmailAlreadyExists />);
- (wrapper.instance() as EmailAlreadyExists).mounted = true;
- (wrapper.instance() as EmailAlreadyExists).fetchIdentityProviders();
- await waitAndUpdate(wrapper);
- expect(wrapper).toMatchSnapshot();
-});
diff --git a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/EmailAlreadyExists-test.tsx.snap b/server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/EmailAlreadyExists-test.tsx.snap
deleted file mode 100644
index 26c56ed365c..00000000000
--- a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/EmailAlreadyExists-test.tsx.snap
+++ /dev/null
@@ -1,118 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`render 1`] = `
-<div
- className="page-wrapper-simple"
- id="bd"
->
- <div
- className="page-simple"
- id="nonav"
- >
- <div
- className="big-spacer-bottom js-existing-account"
- >
- <p
- className="little-spacer-bottom"
- >
- <FormattedMessage
- defaultMessage="sessions.email_already_exists.1"
- id="sessions.email_already_exists.1"
- values={
- Object {
- "email": <strong>
- mail@example.com
- </strong>,
- }
- }
- />
- </p>
- <div
- className="identity-provider"
- style={
- Object {
- "backgroundColor": "#0052cc",
- "color": "#fff",
- }
- }
- >
- <img
- alt="Bitbucket"
- className="little-spacer-right"
- height="14"
- src="/static/authbitbucket/bitbucket.svg"
- width="14"
- />
- bar
- </div>
- </div>
- <div
- className="big-spacer-bottom js-new-account"
- >
- <p
- className="little-spacer-bottom"
- >
- sessions.email_already_exists.2
- </p>
- <div
- className="identity-provider"
- style={
- Object {
- "backgroundColor": "#444444",
- "color": "#fff",
- }
- }
- >
- <img
- alt="GitHub"
- className="little-spacer-right"
- height="14"
- src="/static/authgithub/github.svg"
- width="14"
- />
- foo
- </div>
- </div>
- <Alert
- variant="warning"
- >
- sessions.email_already_exists.3
- <ul
- className="list-styled"
- >
- <li
- className="spacer-top"
- >
- sessions.email_already_exists.4
- </li>
- <li
- className="spacer-top"
- >
- sessions.email_already_exists.5
- </li>
- <li
- className="spacer-top"
- >
- sessions.email_already_exists.6
- </li>
- </ul>
- </Alert>
- <div
- className="big-spacer-top text-right"
- >
- <a
- className="button js-continue"
- href="/sessions/init/github?allowEmailShift=true"
- >
- continue
- </a>
- <a
- className="big-spacer-left js-cancel"
- href="/"
- >
- cancel
- </a>
- </div>
- </div>
-</div>
-`;
diff --git a/server/sonar-web/src/main/js/apps/sessions/routes.ts b/server/sonar-web/src/main/js/apps/sessions/routes.ts
index f3197bbb219..ec67f583593 100644
--- a/server/sonar-web/src/main/js/apps/sessions/routes.ts
+++ b/server/sonar-web/src/main/js/apps/sessions/routes.ts
@@ -31,10 +31,6 @@ const routes = [
{
path: 'unauthorized',
component: lazyLoadComponent(() => import('./components/Unauthorized'))
- },
- {
- path: 'email_already_exists',
- component: lazyLoadComponent(() => import('./components/EmailAlreadyExists'))
}
];