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

Switch the home link to logout on security error pages #1564

Merged
merged 19 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 9 additions & 2 deletions public/apps/customerror/custom-error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import { ERROR_MISSING_ROLE_PATH } from '../../../common';
import { ClientConfigType } from '../../types';
import './_index.scss';
import { logout } from '../account/utils';

interface CustomErrorDeps {
title: string;
Expand All @@ -45,8 +46,13 @@
{props.subtitle}
</EuiText>
<EuiSpacer size="s" />
<EuiButton fill href={props.http.basePath.serverBasePath} fullWidth>
Back to OpenSearch Dashboards Home
<EuiButton
fill
onClick={() => logout(props.http, '')}

Check warning on line 51 in public/apps/customerror/custom-error.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/customerror/custom-error.tsx#L51

Added line #L51 was not covered by tests
data-test-subj="error-logout-button"
fullWidth
>
Logout
</EuiButton>
</EuiListGroup>
);
Expand Down Expand Up @@ -74,3 +80,4 @@
);
return () => ReactDOM.unmountComponentAtNode(params.element);
}
export { EuiButton };
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Custom error page test renders and clicks the button on the error page 1`] = `
<EuiListGroup
className="custom-error-wrapper"
>
<EuiSpacer
size="s"
/>
<EuiText
size="m"
textAlign="center"
>
<h3>
Title
</h3>
</EuiText>
<EuiSpacer
size="s"
/>
<EuiText
size="s"
textAlign="center"
>
Sub Title
</EuiText>
<EuiSpacer
size="s"
/>
<EuiButton
data-test-subj="error-logout-button"
fill={true}
fullWidth={true}
onClick={[Function]}
>
Logout
</EuiButton>
</EuiListGroup>
`;
61 changes: 61 additions & 0 deletions public/apps/customerror/test/custom-error.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright OpenSearch Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import { shallow } from 'enzyme';
import React from 'react';
import { CustomErrorPage } from '../custom-error';
import { cleanup } from '@testing-library/react';
import '@testing-library/jest-dom';
import { EuiButton } from '../custom-error';
import { logout } from '../../account/utils';

afterEach(() => {
cleanup();
});

describe('Custom error page test', () => {
let component;

beforeEach(() => {
component = shallow(
<EuiButton fill onClick={logout} data-test-subj="error-logout-button" fullWidth>
Logout
</EuiButton>
);
});

it('renders and clicks the button on the error page', () => {
const wrapper = shallow(
<CustomErrorPage
title="Title"
subtitle="Sub Title"
http={undefined}
chrome={undefined}
config={{
title: '',
subtitle: '',
showbrandimage: false,
brandimage: '',
buttonstyle: '',
}}
/>
);

expect(wrapper).toMatchSnapshot();

component.find('[data-test-subj="error-logout-button"]').simulate('onClick', {
preventDefault: () => {},
});
});
});
Loading