Skip to content

Commit 67c320b

Browse files
Switch the home link to logout on security error pages (opensearch-project#1564) (opensearch-project#1629)
* changing return to dashboards with functioning logout button on error page Signed-off-by: [email protected] <[email protected]> Co-authored-by: Darshit Chanpura <[email protected]> Co-authored-by: Peter Nied <[email protected]> (cherry picked from commit 27c37d40221bdc07f0167eca6348806d6b876dd6) Co-authored-by: leanneeliatra <[email protected]>
1 parent 6b86cd3 commit 67c320b

File tree

3 files changed

+109
-2
lines changed

3 files changed

+109
-2
lines changed

public/apps/customerror/custom-error.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Router, Route } from 'react-router-dom';
2121
import { ERROR_MISSING_ROLE_PATH } from '../../../common';
2222
import { ClientConfigType } from '../../types';
2323
import './_index.scss';
24+
import { logout } from '../account/utils';
2425

2526
interface CustomErrorDeps {
2627
title: string;
@@ -45,8 +46,13 @@ export function CustomErrorPage(props: CustomErrorDeps) {
4546
{props.subtitle}
4647
</EuiText>
4748
<EuiSpacer size="s" />
48-
<EuiButton fill href={props.http.basePath.serverBasePath} fullWidth>
49-
Back to OpenSearch Dashboards Home
49+
<EuiButton
50+
fill
51+
onClick={() => logout(props.http, '')}
52+
data-test-subj="error-logout-button"
53+
fullWidth
54+
>
55+
Logout
5056
</EuiButton>
5157
</EuiListGroup>
5258
);
@@ -74,3 +80,4 @@ export async function renderPage(
7480
);
7581
return () => ReactDOM.unmountComponentAtNode(params.element);
7682
}
83+
export { EuiButton };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Custom error page test renders and clicks the button on the error page 1`] = `
4+
<EuiListGroup
5+
className="custom-error-wrapper"
6+
>
7+
<EuiSpacer
8+
size="s"
9+
/>
10+
<EuiText
11+
size="m"
12+
textAlign="center"
13+
>
14+
<h3>
15+
Title
16+
</h3>
17+
</EuiText>
18+
<EuiSpacer
19+
size="s"
20+
/>
21+
<EuiText
22+
size="s"
23+
textAlign="center"
24+
>
25+
Sub Title
26+
</EuiText>
27+
<EuiSpacer
28+
size="s"
29+
/>
30+
<EuiButton
31+
data-test-subj="error-logout-button"
32+
fill={true}
33+
fullWidth={true}
34+
onClick={[Function]}
35+
>
36+
Logout
37+
</EuiButton>
38+
</EuiListGroup>
39+
`;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
import { shallow } from 'enzyme';
16+
import React from 'react';
17+
import { CustomErrorPage } from '../custom-error';
18+
import { cleanup } from '@testing-library/react';
19+
import '@testing-library/jest-dom';
20+
import { EuiButton } from '../custom-error';
21+
import { logout } from '../../account/utils';
22+
23+
afterEach(() => {
24+
cleanup();
25+
});
26+
27+
describe('Custom error page test', () => {
28+
let component;
29+
30+
beforeEach(() => {
31+
component = shallow(
32+
<EuiButton fill onClick={logout} data-test-subj="error-logout-button" fullWidth>
33+
Logout
34+
</EuiButton>
35+
);
36+
});
37+
38+
it('renders and clicks the button on the error page', () => {
39+
const wrapper = shallow(
40+
<CustomErrorPage
41+
title="Title"
42+
subtitle="Sub Title"
43+
http={undefined}
44+
chrome={undefined}
45+
config={{
46+
title: '',
47+
subtitle: '',
48+
showbrandimage: false,
49+
brandimage: '',
50+
buttonstyle: '',
51+
}}
52+
/>
53+
);
54+
55+
expect(wrapper).toMatchSnapshot();
56+
57+
component.find('[data-test-subj="error-logout-button"]').simulate('onClick', {
58+
preventDefault: () => {},
59+
});
60+
});
61+
});

0 commit comments

Comments
 (0)