From 13b96d587e829744b2656f5d26802946eaaac8e9 Mon Sep 17 00:00:00 2001 From: Katia Aresti Date: Mon, 15 May 2023 14:22:17 +0200 Subject: [PATCH] ISPN-14835 Use BASIC when url contains user and password --- run-server-for-e2e.sh | 2 +- src/__tests__/views/About.test.tsx | 2 +- .../views/counters/AddDeltaCounter.test.tsx | 4 +- .../views/counters/CreateCounter.test.tsx | 57 ++++++------------- src/app/AppLayout/AppLayout.tsx | 6 +- src/app/CacheManagers/CacheTableDisplay.tsx | 6 +- src/app/CacheManagers/CounterTableDisplay.tsx | 2 +- src/app/Caches/Create/CreateCacheWizard.tsx | 4 +- src/app/Caches/DataAccessChart.tsx | 3 +- src/app/Caches/DataDistributionChart.tsx | 3 +- src/app/Caches/DetailCache.tsx | 9 ++- src/app/Caches/Query/ClearQueryMetrics.tsx | 4 +- src/app/Caches/Query/QueryMetrics.tsx | 6 +- src/app/Common/DataContainerBreadcrumb.tsx | 6 +- src/app/Counters/AddDeltaCounter.tsx | 16 +++++- src/app/Counters/CreateCounter.tsx | 2 +- src/app/Counters/DeleteCounter.tsx | 10 +++- src/app/Counters/ResetCounter.tsx | 10 +++- src/app/GlobalStats/GlobalStats.tsx | 4 +- src/app/IndexManagement/IndexManagement.tsx | 3 +- src/app/NotFound/NotFound.tsx | 2 +- src/app/Welcome/Welcome.tsx | 4 +- src/app/XSite/XSiteCache.tsx | 5 +- src/app/index.tsx | 13 ++++- src/app/providers/UserContextProvider.tsx | 2 +- src/app/routes.tsx | 3 - src/services/ConsoleServices.ts | 4 +- src/services/fetchCaller.ts | 8 ++- 28 files changed, 115 insertions(+), 85 deletions(-) diff --git a/run-server-for-e2e.sh b/run-server-for-e2e.sh index 1915fb65..00720145 100755 --- a/run-server-for-e2e.sh +++ b/run-server-for-e2e.sh @@ -13,7 +13,7 @@ EXISTING_SERVER_PATH="${EXISTING_SERVER_PATH}" #Base directory where the server should be downloaded BASE_DIR="server" #The version of the server is either set as an environment variable or is the latest dev version -SERVER_VERSION="${SERVER_VERSION:-"14.0.6.Final"}" +SERVER_VERSION="${SERVER_VERSION:-"15.0.0.Dev01"}" #Root path from there the infinispan server should be downloaded ZIP_ROOT="http://downloads.jboss.org/infinispan" #If this environment variable is provided then it is used for downloading the server; diff --git a/src/__tests__/views/About.test.tsx b/src/__tests__/views/About.test.tsx index 5876c812..aacf3944 100644 --- a/src/__tests__/views/About.test.tsx +++ b/src/__tests__/views/About.test.tsx @@ -25,7 +25,7 @@ describe('About page', () => { expect(getByText('Infinispan Corona 1.9')).toBeTruthy(); - expect(getByRole('img', { name: /Logo$/})).toBeInTheDocument(); + expect(getByRole('img', { name: /Logo$/ })).toBeInTheDocument(); fireEvent.click(getByRole('button', { name: 'Close Dialog' })); diff --git a/src/__tests__/views/counters/AddDeltaCounter.test.tsx b/src/__tests__/views/counters/AddDeltaCounter.test.tsx index 032277ed..8c454e10 100644 --- a/src/__tests__/views/counters/AddDeltaCounter.test.tsx +++ b/src/__tests__/views/counters/AddDeltaCounter.test.tsx @@ -56,10 +56,10 @@ describe('Add a delta', () => { ); expect(screen.queryByRole('modal')).toBeDefined(); expect(screen.queryAllByRole('button')).toHaveLength(3); - + const submitButton = screen.getByRole('button', { name: 'Confirm' }); fireEvent.click(submitButton); - + expect(screen.getByText('cache-managers.counters.modal-delta-helper-invalid')).toBeTruthy(); expect(closeModalCalls).toBe(0); expect(onAddDeltaCalls).toBe(0); diff --git a/src/__tests__/views/counters/CreateCounter.test.tsx b/src/__tests__/views/counters/CreateCounter.test.tsx index 409c2fa9..4275528f 100644 --- a/src/__tests__/views/counters/CreateCounter.test.tsx +++ b/src/__tests__/views/counters/CreateCounter.test.tsx @@ -26,11 +26,7 @@ mockedCounterHook.useCreateCounter.mockImplementation(() => { describe('Create a counter', () => { test('not render the dialog if the modal is closed', () => { renderWithRouter( - submitModalCalls++} - isModalOpen={false} - closeModal={() => closeModalCalls++} - /> + submitModalCalls++} isModalOpen={false} closeModal={() => closeModalCalls++} /> ); expect(screen.queryByRole('modal')).toBeNull(); expect(closeModalCalls).toBe(0); @@ -39,15 +35,11 @@ describe('Create a counter', () => { test('render the dialog and submit with empty values', () => { renderWithRouter( - submitModalCalls++} - isModalOpen={true} - closeModal={() => closeModalCalls++} - /> + submitModalCalls++} isModalOpen={true} closeModal={() => closeModalCalls++} /> ); expect(screen.queryByRole('modal')).toBeDefined(); expect(screen.queryAllByRole('button')).toHaveLength(5); - + //Submiting empty form const submitButton = screen.getByRole('button', { name: 'Create' }); fireEvent.click(submitButton); @@ -59,20 +51,16 @@ describe('Create a counter', () => { test('render the dialog and submit with filled name', () => { renderWithRouter( - submitModalCalls++} - isModalOpen={true} - closeModal={() => closeModalCalls++} - /> + submitModalCalls++} isModalOpen={true} closeModal={() => closeModalCalls++} /> ); expect(screen.queryByRole('modal')).toBeDefined(); expect(screen.queryAllByRole('button')).toHaveLength(5); - + const submitButton = screen.getByRole('button', { name: 'Create' }); expect(onCreateCounterCalls).toBe(0); //Submiting form with name filled const nameInput = screen.getByLabelText('counter-name-input'); - fireEvent.change(nameInput, {target: {value: 'TestCounter'}}); + fireEvent.change(nameInput, { target: { value: 'TestCounter' } }); fireEvent.click(submitButton); expect(closeModalCalls).toBe(1); @@ -83,26 +71,22 @@ describe('Create a counter', () => { test('render the dialog and submit with invalid values', () => { renderWithRouter( - submitModalCalls++} - isModalOpen={true} - closeModal={() => closeModalCalls++} - /> + submitModalCalls++} isModalOpen={true} closeModal={() => closeModalCalls++} /> ); expect(screen.queryByRole('modal')).toBeDefined(); expect(screen.queryAllByRole('button')).toHaveLength(5); - + const submitButton = screen.getByRole('button', { name: 'Create' }); //Submiting form with name filled const nameInput = screen.getByLabelText('counter-name-input'); - fireEvent.change(nameInput, {target: {value: 'TestCounter1'}}); + fireEvent.change(nameInput, { target: { value: 'TestCounter1' } }); const initialValueInput = screen.getByLabelText('initial-value-input'); - fireEvent.change(initialValueInput, {target: {value: '5'}}); + fireEvent.change(initialValueInput, { target: { value: '5' } }); const lowerBoundInput = screen.getByLabelText('lower-bound-input'); - fireEvent.change(lowerBoundInput, {target: {value: '5'}}); + fireEvent.change(lowerBoundInput, { target: { value: '5' } }); const upperBoundInput = screen.getByLabelText('upper-bound-input'); - fireEvent.change(upperBoundInput, {target: {value: '5'}}); + fireEvent.change(upperBoundInput, { target: { value: '5' } }); fireEvent.click(submitButton); expect(screen.getByText('cache-managers.counters.modal-initial-value-invalid')).toBeTruthy(); expect(screen.getByText('cache-managers.counters.modal-lower-bound-invalid')).toBeTruthy(); @@ -114,26 +98,22 @@ describe('Create a counter', () => { test('render the dialog and submit with valid values', () => { renderWithRouter( - submitModalCalls++} - isModalOpen={true} - closeModal={() => closeModalCalls++} - /> + submitModalCalls++} isModalOpen={true} closeModal={() => closeModalCalls++} /> ); expect(screen.queryByRole('modal')).toBeDefined(); expect(screen.queryAllByRole('button')).toHaveLength(5); - + const submitButton = screen.getByRole('button', { name: 'Create' }); //Submiting form with name filled const nameInput = screen.getByLabelText('counter-name-input'); - fireEvent.change(nameInput, {target: {value: 'TestCounter1'}}); + fireEvent.change(nameInput, { target: { value: 'TestCounter1' } }); const initialValueInput = screen.getByLabelText('initial-value-input'); - fireEvent.change(initialValueInput, {target: {value: '5'}}); + fireEvent.change(initialValueInput, { target: { value: '5' } }); const lowerBoundInput = screen.getByLabelText('lower-bound-input'); - fireEvent.change(lowerBoundInput, {target: {value: '0'}}); + fireEvent.change(lowerBoundInput, { target: { value: '0' } }); const upperBoundInput = screen.getByLabelText('upper-bound-input'); - fireEvent.change(upperBoundInput, {target: {value: '10'}}); + fireEvent.change(upperBoundInput, { target: { value: '10' } }); fireEvent.click(submitButton); expect(closeModalCalls).toBe(1); @@ -141,5 +121,4 @@ describe('Create a counter', () => { expect(submitModalCalls).toBe(1); expect(screen.queryByRole('modal')).toBeNull(); }); - }); diff --git a/src/app/AppLayout/AppLayout.tsx b/src/app/AppLayout/AppLayout.tsx index 17ab5429..df4ad146 100644 --- a/src/app/AppLayout/AppLayout.tsx +++ b/src/app/AppLayout/AppLayout.tsx @@ -53,7 +53,7 @@ const AppLayout: React.FunctionComponent = ({ init, children }) => { const [isWelcomePage, setIsWelcomePage] = useState(ConsoleServices.isWelcomePage()); const logoProps = { target: '_self', - onClick: () => history.push('/') + onClick: () => history.push('/' + history.location.search) }; const { t } = useTranslation(); @@ -87,7 +87,7 @@ const AppLayout: React.FunctionComponent = ({ init, children }) => { const Logo = ( - + @@ -179,7 +179,7 @@ const AppLayout: React.FunctionComponent = ({ init, children }) => { { if (match) { diff --git a/src/app/CacheManagers/CacheTableDisplay.tsx b/src/app/CacheManagers/CacheTableDisplay.tsx index 4d8fef5d..269f087d 100644 --- a/src/app/CacheManagers/CacheTableDisplay.tsx +++ b/src/app/CacheManagers/CacheTableDisplay.tsx @@ -434,7 +434,7 @@ const CacheTableDisplay = (props: { cmName: string; setCachesCount: (count: numb {cacheDetailAccess} @@ -517,7 +517,8 @@ const CacheTableDisplay = (props: { cmName: string; setCachesCount: (count: numb diff --git a/src/app/Caches/Create/CreateCacheWizard.tsx b/src/app/Caches/Create/CreateCacheWizard.tsx index 113b5c38..552e456d 100644 --- a/src/app/Caches/Create/CreateCacheWizard.tsx +++ b/src/app/Caches/Create/CreateCacheWizard.tsx @@ -66,7 +66,7 @@ const CreateCacheWizard = (props: { cacheManager: CacheManager; create: boolean const history = useHistory(); const closeWizard = () => { - history.push('/'); + history.push('/' + history.location.search); }; useEffect(() => { @@ -366,7 +366,7 @@ const CreateCacheWizard = (props: { cacheManager: CacheManager; create: boolean createCacheCall .then((actionResponse) => { if (actionResponse.success) { - history.push('/'); + history.push('/' + history.location.search); } return actionResponse; }) diff --git a/src/app/Caches/DataAccessChart.tsx b/src/app/Caches/DataAccessChart.tsx index f7beee96..e5d821fa 100644 --- a/src/app/Caches/DataAccessChart.tsx +++ b/src/app/Caches/DataAccessChart.tsx @@ -49,7 +49,8 @@ const DataAccessChart = (props: { stats: CacheStats }) => {
- { ariaDesc={t('caches.cache-metrics.data-distribution')} ariaTitle={t('caches.cache-metrics.data-distribution')} containerComponent={ - datum.y !== 0 ? `${datum.y}` diff --git a/src/app/Caches/DetailCache.tsx b/src/app/Caches/DetailCache.tsx index 470cd3b4..0ed37342 100644 --- a/src/app/Caches/DetailCache.tsx +++ b/src/app/Caches/DetailCache.tsx @@ -159,7 +159,8 @@ const DetailCache = (props: { cacheName: string }) => { @@ -214,7 +215,8 @@ const DetailCache = (props: { cacheName: string }) => { @@ -254,7 +256,8 @@ const DetailCache = (props: { cacheName: string }) => { , - ]} diff --git a/src/app/Caches/Query/QueryMetrics.tsx b/src/app/Caches/Query/QueryMetrics.tsx index 108520a7..1beef57c 100644 --- a/src/app/Caches/Query/QueryMetrics.tsx +++ b/src/app/Caches/Query/QueryMetrics.tsx @@ -113,7 +113,11 @@ const QueryMetrics = (props: { cacheName: string }) => { return ( - {props.cacheName} @@ -25,7 +26,8 @@ const DataContainerBreadcrumb = (props: { currentPage: string; cacheName?: strin Data container diff --git a/src/app/Counters/AddDeltaCounter.tsx b/src/app/Counters/AddDeltaCounter.tsx index 22cf01ec..f64e8199 100644 --- a/src/app/Counters/AddDeltaCounter.tsx +++ b/src/app/Counters/AddDeltaCounter.tsx @@ -33,10 +33,22 @@ const AddDeltaCounter = (props: { aria-label={t('cache-managers.counters.modal-delta-title')} disableFocusTrap={true} actions={[ - , - ]} diff --git a/src/app/Counters/CreateCounter.tsx b/src/app/Counters/CreateCounter.tsx index 61820fe2..153e6937 100644 --- a/src/app/Counters/CreateCounter.tsx +++ b/src/app/Counters/CreateCounter.tsx @@ -241,7 +241,7 @@ const CreateCounter = (props: { isModalOpen: boolean; submitModal: () => void; c } > diff --git a/src/app/Counters/DeleteCounter.tsx b/src/app/Counters/DeleteCounter.tsx index 61d946b6..10513b28 100644 --- a/src/app/Counters/DeleteCounter.tsx +++ b/src/app/Counters/DeleteCounter.tsx @@ -30,7 +30,7 @@ const DeleteCounter = (props: { disableFocusTrap={true} actions={[ , - ]} diff --git a/src/app/Counters/ResetCounter.tsx b/src/app/Counters/ResetCounter.tsx index a3937c5e..229af102 100644 --- a/src/app/Counters/ResetCounter.tsx +++ b/src/app/Counters/ResetCounter.tsx @@ -40,14 +40,20 @@ const ResetCounter = (props: { > {t('cache-managers.counters.reset-action')} , - ]} > - The current value of {props.name} will be restored to its initial value of{' '} + The current value of {props.name} will be restored to its initial value of{' '} {props.initialValue} diff --git a/src/app/GlobalStats/GlobalStats.tsx b/src/app/GlobalStats/GlobalStats.tsx index c4a15583..e4749023 100644 --- a/src/app/GlobalStats/GlobalStats.tsx +++ b/src/app/GlobalStats/GlobalStats.tsx @@ -61,7 +61,7 @@ const GlobalStats = () => { /> - + @@ -232,7 +232,7 @@ const GlobalStats = () => { /> - + diff --git a/src/app/IndexManagement/IndexManagement.tsx b/src/app/IndexManagement/IndexManagement.tsx index a7fd6b45..6e877efd 100644 --- a/src/app/IndexManagement/IndexManagement.tsx +++ b/src/app/IndexManagement/IndexManagement.tsx @@ -160,7 +160,8 @@ const IndexManagement = (props) => { diff --git a/src/app/NotFound/NotFound.tsx b/src/app/NotFound/NotFound.tsx index b2d62475..daf1b44b 100644 --- a/src/app/NotFound/NotFound.tsx +++ b/src/app/NotFound/NotFound.tsx @@ -11,7 +11,7 @@ const NotFound = () => { const history = useHistory(); function handleClick() { - history.push('/'); + history.push(history?.location?.search ? '/' + history?.location?.search : '/'); } return ; diff --git a/src/app/Welcome/Welcome.tsx b/src/app/Welcome/Welcome.tsx index a75d64c4..54f29623 100644 --- a/src/app/Welcome/Welcome.tsx +++ b/src/app/Welcome/Welcome.tsx @@ -89,7 +89,7 @@ const Welcome = (props) => { }; const notSecured = () => { - history.push('/'); + history.push('/' + history.location.search); }; const goToTheConsole = t('welcome-page.go-to-console'); @@ -112,7 +112,7 @@ const Welcome = (props) => { .then((r) => { if (r.success) { logUser(); - history.push('/'); + history.push('/' + history.location.search); } else { // Do nothing } diff --git a/src/app/XSite/XSiteCache.tsx b/src/app/XSite/XSiteCache.tsx index d1be4947..e656b5e3 100644 --- a/src/app/XSite/XSiteCache.tsx +++ b/src/app/XSite/XSiteCache.tsx @@ -308,7 +308,7 @@ const XSiteCache = (props) => { heightAuto: true, cells: [ { title: backup.name }, - { title: buildStatus(backup.name, backup.status.status) }, + { title: buildStatus(backup.name, backup.status) }, { title: buildStateTransferStatus(backup.name) }, { title: buildStateTransferButton(backup) } ] @@ -334,7 +334,8 @@ const XSiteCache = (props) => { diff --git a/src/app/index.tsx b/src/app/index.tsx index 90324a4e..0622aef3 100644 --- a/src/app/index.tsx +++ b/src/app/index.tsx @@ -12,7 +12,17 @@ const App = () => { const [init, setInit] = useState< 'SERVER_ERROR' | 'READY' | 'NOT_READY' | 'PENDING' | 'DONE' | 'LOGIN' | 'HTTP_LOGIN' >('PENDING'); - ConsoleServices.init(); + // @ts-ignore + let searchParams = new URL(window.location).searchParams; + // local dev mode basic + let user = searchParams.get('user'); + let password = searchParams.get('password'); + + if (user != null && password != null) { + ConsoleServices.init(user, password); + } else { + ConsoleServices.init(); + } useEffect(() => { ConsoleServices.authentication() @@ -46,7 +56,6 @@ const App = () => { }); } else if (eitherAuth.value.ready) { if (eitherAuth.value.mode === 'HTTP') { - console.log('update init to http login'); setInit('HTTP_LOGIN'); } else { ConsoleServices.authentication().noSecurityMode(); diff --git a/src/app/providers/UserContextProvider.tsx b/src/app/providers/UserContextProvider.tsx index 72a5ab29..71da0a44 100644 --- a/src/app/providers/UserContextProvider.tsx +++ b/src/app/providers/UserContextProvider.tsx @@ -72,7 +72,7 @@ const UserContextProvider = ({ children }) => { const notSecuredModeOn = () => { setNotSecured(true); ConsoleServices.authentication().noSecurityMode(); - history.push('/'); + history.push('/' + history.location.search); }; const contextValue = { diff --git a/src/app/routes.tsx b/src/app/routes.tsx index 95f19b9f..1a1d96e3 100644 --- a/src/app/routes.tsx +++ b/src/app/routes.tsx @@ -14,9 +14,6 @@ import { useDocumentTitle } from '@app/utils/useDocumentTitle'; import { IndexManagement } from '@app/IndexManagement/IndexManagement'; import { XSiteCache } from '@app/XSite/XSiteCache'; import { DetailCachePage } from '@app/Caches/DetailCachePage'; -import { useConnectedUser } from '@app/services/userManagementHook'; -import { ConsoleServices } from '@services/ConsoleServices'; -import { ConsoleACL } from '@services/securityService'; let routeFocusTimer: number; diff --git a/src/services/ConsoleServices.ts b/src/services/ConsoleServices.ts index da011ff6..8088c676 100644 --- a/src/services/ConsoleServices.ts +++ b/src/services/ConsoleServices.ts @@ -64,11 +64,11 @@ export class ConsoleServices { return location.pathname == '/console/welcome' || location.pathname == '/console/welcome/'; } - public static init() { + public static init(user?: string, password?: string) { if (!this.instance.initialized) { console.info('Init Console Services'); this.instance.authenticationService = new AuthenticationService(ConsoleServices.endpoint()); - this.instance.fetchCaller = new FetchCaller(this.instance.authenticationService); + this.instance.fetchCaller = new FetchCaller(this.instance.authenticationService, user, password); this.instance.protobufService = new ProtobufService( ConsoleServices.endpoint() + '/schemas', this.instance.fetchCaller diff --git a/src/services/fetchCaller.ts b/src/services/fetchCaller.ts index 37f56adb..fa40e037 100644 --- a/src/services/fetchCaller.ts +++ b/src/services/fetchCaller.ts @@ -9,6 +9,8 @@ import { Either, left, right } from '@services/either'; */ export class FetchCaller { private authenticationService: AuthenticationService; + private user: string | undefined; + private password: string | undefined; /** * Get REST API Calls @@ -103,14 +105,18 @@ export class FetchCaller { return fetch(url, fetchOptions); } - constructor(authenticationService: AuthenticationService) { + constructor(authenticationService: AuthenticationService, user?: string, password?: string) { this.authenticationService = authenticationService; + this.user = user; + this.password = password; } private createAuthenticatedHeader = (): Headers => { let headers = new Headers(); if (KeycloakService.Instance.isInitialized()) { headers.append('Authorization', 'Bearer ' + localStorage.getItem('react-token')); + } else if (this.user && this.password) { + headers.set('Authorization', 'Basic ' + btoa(this.user + ':' + this.password)); } return headers; };