diff options
author | xuegao <xg353y@intl.att.com> | 2019-10-07 14:36:34 +0200 |
---|---|---|
committer | xuegao <xg353y@intl.att.com> | 2019-10-07 14:36:34 +0200 |
commit | 0efeb6b141cb4abe84af8eb38e26d5ed1ab73bb0 (patch) | |
tree | 8c716d7b22828b13a796aa924b1e156a51b9e420 | |
parent | 52432d6512d2477ad16d46f5ab31a8f77e9f77bd (diff) |
Fix Sonar vulnerabilities
Fix the vulnerabilities reported by Sonar.
Issue-ID: CLAMP-530
Change-Id: I9f6a7fe9ce042045085c371ef3777188b11ffb36
Signed-off-by: xuegao <xg353y@intl.att.com>
-rw-r--r-- | ui-react/src/LoopUI.js | 39 | ||||
-rw-r--r-- | ui-react/src/api/LoopActionService.js | 8 | ||||
-rw-r--r-- | ui-react/src/components/dialogs/DeployLoop.js | 7 | ||||
-rw-r--r-- | ui-react/src/components/dialogs/DeployLoop.test.js | 7 | ||||
-rw-r--r-- | ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js | 2 | ||||
-rw-r--r-- | ui-react/src/components/dialogs/PerformActions.js | 6 | ||||
-rw-r--r-- | ui-react/src/components/dialogs/PerformActions.test.js | 12 | ||||
-rw-r--r-- | ui-react/src/components/dialogs/RefreshStatus.js | 7 | ||||
-rw-r--r-- | ui-react/src/components/dialogs/RefreshStatus.test.js | 13 |
9 files changed, 56 insertions, 45 deletions
diff --git a/ui-react/src/LoopUI.js b/ui-react/src/LoopUI.js index b6dd0cb07..ad970d811 100644 --- a/ui-react/src/LoopUI.js +++ b/ui-react/src/LoopUI.js @@ -44,6 +44,7 @@ import LoopService from './api/LoopService'; import PerformAction from './components/dialogs/PerformActions'; import RefreshStatus from './components/dialogs/RefreshStatus'; import DeployLoop from './components/dialogs/DeployLoop'; +import Alert from 'react-bootstrap/Alert'; import { Link } from 'react-router-dom'; @@ -100,7 +101,8 @@ export default class LoopUI extends React.Component { state = { userName: null, loopName: LoopUI.defaultLoopName, - loopCache: new LoopCache({}) + loopCache: new LoopCache({}), + showAlert: false }; constructor() { @@ -110,6 +112,8 @@ export default class LoopUI extends React.Component { this.updateLoopCache = this.updateLoopCache.bind(this); this.loadLoop = this.loadLoop.bind(this); this.closeLoop = this.closeLoop.bind(this); + this.showAlert = this.showAlert.bind(this); + this.disableAlert = this.disableAlert.bind(this); } componentWillMount() { @@ -155,6 +159,14 @@ export default class LoopUI extends React.Component { ); } + renderAlertBar() { + return ( + <Alert variant="danger" show={this.state.showAlert} onClose={this.disableAlert} dismissible> + {this.state.showMessage} + </Alert> + ); + } + renderNavBar() { return ( <Navbar > @@ -204,6 +216,14 @@ export default class LoopUI extends React.Component { console.info(this.state.loopName+" loop loaded successfully"); } + showAlert(message) { + this.setState ({ showAlert: true, showMessage:message }); + } + + disableAlert() { + this.setState ({ showAlert: false }); + } + loadLoop(loopName) { LoopService.getLoop(loopName).then(loop => { console.debug("Updating loopCache"); @@ -220,21 +240,22 @@ export default class LoopUI extends React.Component { return ( <StyledMainDiv id="main_div"> <Route path="/operationalPolicyModal" - render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} /> + render={(routeProps) => (<OperationalPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop} showAlert={this.showAlert}/>)} /> <Route path="/configurationPolicyModal/:componentName" render={(routeProps) => (<ConfigurationPolicyModal {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} /> <Route path="/openLoop" render={(routeProps) => (<OpenLoopModal {...routeProps} loadLoopFunction={this.loadLoop} />)} /> <Route path="/loopProperties" render={(routeProps) => (<LoopProperties {...routeProps} loopCache={this.getLoopCache()} loadLoopFunction={this.loadLoop}/>)} /> <Route path="/userInfo" render={(routeProps) => (<UserInfo {...routeProps} />)} /> <Route path="/closeLoop" render={this.closeLoop} /> - <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} /> - <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} /> - <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} /> - <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} /> - <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} /> - <Route path="/deploy" render={(routeProps) => (<DeployLoop {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} /> - <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache}/>)} /> + <Route path="/submit" render={(routeProps) => (<PerformAction {...routeProps} loopAction="submit" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} /> + <Route path="/stop" render={(routeProps) => (<PerformAction {...routeProps} loopAction="stop" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} /> + <Route path="/restart" render={(routeProps) => (<PerformAction {...routeProps} loopAction="restart" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} /> + <Route path="/delete" render={(routeProps) => (<PerformAction {...routeProps} loopAction="delete" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} /> + <Route path="/undeploy" render={(routeProps) => (<PerformAction {...routeProps} loopAction="undeploy" loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} /> + <Route path="/deploy" render={(routeProps) => (<DeployLoop {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} /> + <Route path="/refreshStatus" render={(routeProps) => (<RefreshStatus {...routeProps} loopCache={this.getLoopCache()} updateLoopFunction={this.updateLoopCache} showAlert={this.showAlert}/>)} /> <Route path="/logout" render={this.logout} /> <GlobalClampStyle /> + {this.renderAlertBar()} {this.renderNavBar()} {this.renderLoopViewer()} </StyledMainDiv> diff --git a/ui-react/src/api/LoopActionService.js b/ui-react/src/api/LoopActionService.js index 7e20e2f6c..7cea3ff9f 100644 --- a/ui-react/src/api/LoopActionService.js +++ b/ui-react/src/api/LoopActionService.js @@ -24,7 +24,7 @@ export default class LoopActionService{ static performAction(cl_name, uiAction) { - console.log("LoopActionService perform action: " + uiAction + " closedloopName=" + cl_name); + console.info("LoopActionService perform action: " + uiAction + " closedloopName=" + cl_name); const svcAction = uiAction.toLowerCase(); return fetch("/restservices/clds/v2/loop/" + svcAction + "/" + cl_name, { method: 'PUT', @@ -38,18 +38,18 @@ export default class LoopActionService{ } }) .then(function (data) { - alert("Action Successful: " + uiAction); + console.info("Action Successful: " + uiAction); return data; }) .catch(function(error) { - console.log("Action Failure: " + uiAction); + console.info("Action Failure: " + uiAction); return Promise.reject(error); }); } static refreshStatus(cl_name) { - console.log("Refresh the status for closedloopName=" + cl_name); + console.info("Refresh the status for closedloopName=" + cl_name); return fetch("/restservices/clds/v2/loop/getstatus/" + cl_name, { method: 'GET', diff --git a/ui-react/src/components/dialogs/DeployLoop.js b/ui-react/src/components/dialogs/DeployLoop.js index 805f0f29b..d71af9240 100644 --- a/ui-react/src/components/dialogs/DeployLoop.js +++ b/ui-react/src/components/dialogs/DeployLoop.js @@ -64,14 +64,13 @@ export default class DeployLoop extends React.Component { LoopService.updateGlobalProperties(loopName, this.state.temporaryPropertiesJson).then(resp => { this.setState({ show: false }); - console.log("Perform action: deploy"); LoopActionService.performAction(loopName, "deploy").then(pars => { - alert("Action deploy successfully performed"); + this.props.showAlert("Action deploy successfully performed"); // refresh status and update loop logs this.refreshStatus(loopName); }) .catch(error => { - alert("Action deploy failed"); + this.props.showAlert("Action deploy failed"); // refresh status and update loop logs this.refreshStatus(loopName); }); @@ -84,7 +83,7 @@ export default class DeployLoop extends React.Component { this.props.history.push('/'); }) .catch(error => { - alert("Refresh status failed"); + this.props.showAlert("Refresh status failed"); this.props.history.push('/'); }); } diff --git a/ui-react/src/components/dialogs/DeployLoop.test.js b/ui-react/src/components/dialogs/DeployLoop.test.js index 2959ed652..44bc78379 100644 --- a/ui-react/src/components/dialogs/DeployLoop.test.js +++ b/ui-react/src/components/dialogs/DeployLoop.test.js @@ -61,6 +61,7 @@ describe('Verify DeployLoop', () => { const flushPromises = () => new Promise(setImmediate); const historyMock = { push: jest.fn() }; const updateLoopFunction = jest.fn(); + const showAlert = jest.fn(); const handleSave = jest.spyOn(DeployLoop.prototype,'handleSave'); LoopService.updateGlobalProperties = jest.fn().mockImplementation(() => { return Promise.resolve({ @@ -83,10 +84,9 @@ describe('Verify DeployLoop', () => { json: () => {} }); }); - const jsdomAlert = window.alert; - window.alert = () => {}; + const component = shallow(<DeployLoop history={historyMock} - loopCache={loopCache} updateLoopFunction={updateLoopFunction} />) + loopCache={loopCache} updateLoopFunction={updateLoopFunction} showAlert={showAlert} />) component.find('[variant="primary"]').prop('onClick')(); await flushPromises(); @@ -95,7 +95,6 @@ describe('Verify DeployLoop', () => { expect(handleSave).toHaveBeenCalledTimes(1); expect(component.state('show')).toEqual(false); expect(historyMock.push.mock.calls[0]).toEqual([ '/']); - window.alert = jsdomAlert; handleSave.mockClear(); }); diff --git a/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js b/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js index 4dc1f90a0..5c5f0241a 100644 --- a/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js +++ b/ui-react/src/components/dialogs/OperationalPolicy/OperationalPolicyModal.js @@ -54,7 +54,7 @@ export default class OperationalPolicyModal extends React.Component { if (errors.length !== 0) { console.error("Errors detected during config policy data validation ", errors); - alert(errors); + this.props.showAlert(errors); } else { console.info("NO validation errors found in config policy data"); diff --git a/ui-react/src/components/dialogs/PerformActions.js b/ui-react/src/components/dialogs/PerformActions.js index 9c34e141b..66b192863 100644 --- a/ui-react/src/components/dialogs/PerformActions.js +++ b/ui-react/src/components/dialogs/PerformActions.js @@ -50,14 +50,14 @@ export default class PerformActions extends React.Component { componentDidMount() { const action = this.state.loopAction; const loopName = this.state.loopName; - console.log("Perform action:" + action); + LoopActionService.performAction(loopName, action).then(pars => { - alert("Action " + action + " successfully performed"); + this.props.showAlert("Action " + action + " successfully performed"); // refresh status and update loop logs this.refreshStatus(loopName); }) .catch(error => { - alert("Action " + action + " failed"); + this.props.showAlert("Action " + action + " failed"); // refresh status and update loop logs this.refreshStatus(loopName); }); diff --git a/ui-react/src/components/dialogs/PerformActions.test.js b/ui-react/src/components/dialogs/PerformActions.test.js index 56fdcf39b..0b0786290 100644 --- a/ui-react/src/components/dialogs/PerformActions.test.js +++ b/ui-react/src/components/dialogs/PerformActions.test.js @@ -36,6 +36,7 @@ describe('Verify PerformActions', () => { const flushPromises = () => new Promise(setImmediate); const historyMock = { push: jest.fn() }; const updateLoopFunction = jest.fn(); + const showAlert = jest.fn(); LoopActionService.refreshStatus = jest.fn().mockImplementation(() => { return Promise.resolve({ @@ -44,21 +45,19 @@ describe('Verify PerformActions', () => { json: () => {} }); }); - const jsdomAlert = window.alert; - window.alert = () => {}; const component = shallow(<PerformActions loopCache={loopCache} - loopAction="submit" history={historyMock} updateLoopFunction={updateLoopFunction} />) + loopAction="submit" history={historyMock} updateLoopFunction={updateLoopFunction} showAlert={showAlert} />) await flushPromises(); component.update(); expect(historyMock.push.mock.calls[0]).toEqual([ '/']); - window.alert = jsdomAlert; }); it('Test the render method action successful', async () => { const flushPromises = () => new Promise(setImmediate); const historyMock = { push: jest.fn() }; const updateLoopFunction = jest.fn(); + const showAlert = jest.fn(); LoopActionService.performAction = jest.fn().mockImplementation(() => { return Promise.resolve({ @@ -74,15 +73,12 @@ describe('Verify PerformActions', () => { json: () => {} }); }); - const jsdomAlert = window.alert; - window.alert = () => {}; const component = shallow(<PerformActions loopCache={loopCache} - loopAction="submit" history={historyMock} updateLoopFunction={updateLoopFunction} />) + loopAction="submit" history={historyMock} updateLoopFunction={updateLoopFunction} showAlert={showAlert} />) await flushPromises(); component.update(); expect(historyMock.push.mock.calls[0]).toEqual([ '/']); - window.alert = jsdomAlert; }); }); diff --git a/ui-react/src/components/dialogs/RefreshStatus.js b/ui-react/src/components/dialogs/RefreshStatus.js index cf08655ee..64b35d99b 100644 --- a/ui-react/src/components/dialogs/RefreshStatus.js +++ b/ui-react/src/components/dialogs/RefreshStatus.js @@ -22,7 +22,7 @@ */ import React from 'react'; import LoopActionService from '../../api/LoopActionService'; -import Spinner from 'react-bootstrap/Spinner' +import Spinner from 'react-bootstrap/Spinner'; import styled from 'styled-components'; const StyledSpinnerDiv = styled.div` @@ -42,15 +42,14 @@ export default class RefreshStatus extends React.Component { } componentDidMount() { - console.log("Refresh status for: " + this.state.loopName); // refresh status and update loop logs LoopActionService.refreshStatus(this.state.loopName).then(data => { - alert("Status successfully refreshed") + this.props.showAlert("Status successfully refreshed"); this.props.updateLoopFunction(data); this.props.history.push('/'); }) .catch(error => { - alert("Status refreshing failed"); + this.props.showAlert("Status refreshing failed"); this.props.history.push('/'); }); } diff --git a/ui-react/src/components/dialogs/RefreshStatus.test.js b/ui-react/src/components/dialogs/RefreshStatus.test.js index cb782ad23..3038eb321 100644 --- a/ui-react/src/components/dialogs/RefreshStatus.test.js +++ b/ui-react/src/components/dialogs/RefreshStatus.test.js @@ -35,21 +35,20 @@ describe('Verify RefreshStatus', () => { it('Test refresh status failed', async () => { const flushPromises = () => new Promise(setImmediate); const historyMock = { push: jest.fn() }; + const showAlert = jest.fn(); - const jsdomAlert = window.alert; - window.alert = () => {}; - const component = shallow(<RefreshStatus loopCache={loopCache} history={historyMock} />) + const component = shallow(<RefreshStatus loopCache={loopCache} history={historyMock} showAlert={showAlert} />) await flushPromises(); component.update(); expect(historyMock.push.mock.calls[0]).toEqual([ '/']); - window.alert = jsdomAlert; }); it('Test refresh status successful', async () => { const flushPromises = () => new Promise(setImmediate); const historyMock = { push: jest.fn() }; const updateLoopFunction = jest.fn(); + const showAlert = jest.fn(); LoopActionService.refreshStatus = jest.fn().mockImplementation(() => { return Promise.resolve({ @@ -58,15 +57,13 @@ describe('Verify RefreshStatus', () => { json: () => {} }); }); - const jsdomAlert = window.alert; - window.alert = () => {}; + const component = shallow(<RefreshStatus loopCache={loopCache} - loopAction="submit" history={historyMock} updateLoopFunction={updateLoopFunction} />) + loopAction="submit" history={historyMock} updateLoopFunction={updateLoopFunction} showAlert={showAlert} />) await flushPromises(); component.update(); expect(historyMock.push.mock.calls[0]).toEqual([ '/']); - window.alert = jsdomAlert; }); }); |