From dedcd07375177612708036458183e5cb221fff6b Mon Sep 17 00:00:00 2001 From: Jacek Date: Wed, 7 Jul 2021 13:37:17 +0200 Subject: SONAR-15137 Prevent users from associating their account with a new identity provider --- .../sessions/components/EmailAlreadyExists.tsx | 142 --------------------- .../__tests__/EmailAlreadyExists-test.tsx | 59 --------- .../__snapshots__/EmailAlreadyExists-test.tsx.snap | 118 ----------------- .../sonar-web/src/main/js/apps/sessions/routes.ts | 4 - 4 files changed, 323 deletions(-) delete mode 100644 server/sonar-web/src/main/js/apps/sessions/components/EmailAlreadyExists.tsx delete mode 100644 server/sonar-web/src/main/js/apps/sessions/components/__tests__/EmailAlreadyExists-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/EmailAlreadyExists-test.tsx.snap (limited to 'server/sonar-web/src/main/js/apps/sessions') 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 ? ( -
- {identityProvider.name} - {login} -
- ) : ( -
- {provider !== 'sonarqube' && provider} {login} -
- ); - }; - - render() { - const authError = this.getAuthError(); - return ( -
-
-
-

- {authError.email} }} - /> -

- {this.renderIdentityProvier(authError.existingProvider, authError.existingLogin)} -
- -
-

{translate('sessions.email_already_exists.2')}

- {this.renderIdentityProvier(authError.provider, authError.login)} -
- - - {translate('sessions.email_already_exists.3')} -
    -
  • {translate('sessions.email_already_exists.4')}
  • -
  • {translate('sessions.email_already_exists.5')}
  • -
  • {translate('sessions.email_already_exists.6')}
  • -
-
- -
- - {translate('continue')} - - - {translate('cancel')} - -
-
-
- ); - } -} 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(); - (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`] = ` -
-
-
-

- - mail@example.com - , - } - } - /> -

-
- Bitbucket - bar -
-
-
-

- sessions.email_already_exists.2 -

-
- GitHub - foo -
-
- - sessions.email_already_exists.3 -
    -
  • - sessions.email_already_exists.4 -
  • -
  • - sessions.email_already_exists.5 -
  • -
  • - sessions.email_already_exists.6 -
  • -
-
-
- - continue - - - cancel - -
-
-
-`; 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')) } ]; -- cgit v1.2.3