Merge "Fix sonar security issues in policy-gui"
diff --git a/gui-clamp/ui-react/src/components/dialogs/PerformActions.test.js b/gui-clamp/ui-react/src/components/dialogs/PerformActions.test.js
index 74c9145..e5a2f9f 100644
--- a/gui-clamp/ui-react/src/components/dialogs/PerformActions.test.js
+++ b/gui-clamp/ui-react/src/components/dialogs/PerformActions.test.js
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights
* reserved.
+ * Modifications Copyright (C) 2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -92,4 +93,29 @@
expect(historyMock.push.mock.calls[0]).toEqual(['/']);
});
+ it('Test the delete method action', async () => {
+ const flushPromises = () => new Promise(setImmediate);
+ const historyMock = { push: jest.fn() };
+ const updateLoopFunction = jest.fn();
+ const showSucAlert = jest.fn();
+ const showFailAlert = jest.fn();
+ const setBusyLoading = jest.fn();
+ const clearBusyLoading = jest.fn();
+
+ LoopActionService.refreshStatus = jest.fn().mockImplementation(() => {
+ return Promise.resolve({
+ ok: true,
+ status: 200,
+ json: () => {
+ }
+ });
+ });
+ const component = shallow(<PerformActions loopCache={ loopCache }
+ loopAction="delete" history={ historyMock } updateLoopFunction={ updateLoopFunction } showSucAlert={ showSucAlert } showFailAlert={ showFailAlert }
+ setBusyLoading={ setBusyLoading } clearBusyLoading={ clearBusyLoading }/>)
+ await flushPromises();
+ component.update();
+
+ expect(historyMock.push.mock.calls[0]).toEqual(['/']);
+ });
});
diff --git a/gui-clamp/ui-react/src/components/dialogs/Policy/PolicyModal.test.js b/gui-clamp/ui-react/src/components/dialogs/Policy/PolicyModal.test.js
index 2cb1af5..0f7d528 100644
--- a/gui-clamp/ui-react/src/components/dialogs/Policy/PolicyModal.test.js
+++ b/gui-clamp/ui-react/src/components/dialogs/Policy/PolicyModal.test.js
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights
* reserved.
+ * Modifications Copyright (C) 2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -54,10 +55,27 @@
}]
};
+ const loopCacheStrMC = {
+ "name": "MICROSERVICE_type_tca",
+ "microServicePolicies": [{
+ "name": "MICROSERVICE_type",
+ "configurationsJson": {
+ "operational_policy": {
+ "acm": {},
+ "policies": []
+ }
+ },
+ "policyModel": { "policyPdpGroup": { "supportedPdpGroups": [{ "monitoring": ["xacml"] }] } },
+ "jsonRepresentation": { "schema": {} }
+ }]
+ };
+
const loopCache = new LoopCache(loopCacheStr);
const historyMock = { push: jest.fn() };
const flushPromises = () => new Promise(setImmediate);
const match = { params: { policyName: "OPERATIONAL_h2NMX_v1_0_ResourceInstanceName1_tca", policyInstanceType: OnapConstant.operationalPolicyType } }
+ const loopCacheMicroService = new LoopCache(loopCacheStrMC);
+ const matchMicroService = { params: { policyName: "MICROSERVICE_type", policyInstanceType: OnapConstant.microServiceType } }
it('Test handleClose', () => {
const handleClose = jest.spyOn(PolicyModal.prototype, 'handleClose');
@@ -85,6 +103,20 @@
expect(historyMock.push.mock.calls[0]).toEqual(['/']);
});
+ it('Test handleSave MicroService', async () => {
+ const loadLoopFunctionMC = jest.fn();
+ const handleSaveMC = jest.spyOn(PolicyModal.prototype, 'handleSave');
+ const componentMC = mount(<PolicyModal history={ historyMock }
+ loopCache={ loopCacheMicroService } match={ matchMicroService } loadLoopFunction={ loadLoopFunctionMC }/>)
+ componentMC.find('[variant="primary"]').get(0).props.onClick();
+ await flushPromises();
+ componentMC.update();
+
+ expect(handleSaveMC).toHaveBeenCalledTimes(2); //The 1st call it's done in the previous test
+ expect(componentMC.state('show')).toEqual(false);
+ expect(historyMock.push.mock.calls[0]).toEqual(['/']);
+ });
+
it('Test handleRefresh', async () => {
LoopService.refreshOperationalPolicyJson = jest.fn().mockImplementation(() => {
return Promise.resolve(loopCacheStr);
@@ -103,6 +135,24 @@
expect(component.state('showMessage')).toEqual("Successfully refreshed");
});
+ it('Test handleRefresh MicroService Fail', async () => {
+ LoopService.refreshOperationalPolicyJson = jest.fn().mockImplementation(() => {
+ return Promise.resolve(loopCacheStrMC);
+ });
+ const updateLoopFunction = jest.fn();
+ const handleRefresh = jest.spyOn(PolicyModal.prototype, 'handleRefresh');
+ const component = mount(<PolicyModal loopCache={ loopCacheMicroService } match={ matchMicroService } updateLoopFunction={ updateLoopFunction }/>)
+
+ component.find('[variant="primary"]').get(1).props.onClick();
+ await flushPromises();
+ component.update();
+
+ expect(handleRefresh).toHaveBeenCalledTimes(2);
+ expect(component.state('show')).toEqual(true);
+ expect(component.state('showSucAlert')).toEqual(false);
+ expect(component.state('showMessage')).toEqual("Refreshing of UI failed");
+ });
+
it('Test handlePdpGroupChange', () => {
const component = mount(<PolicyModal loopCache={ loopCache } match={ match }/>)
component.setState({
diff --git a/gui-editors/gui-editor-apex/src/lombok.config b/gui-editors/gui-editor-apex/src/lombok.config
new file mode 100644
index 0000000..6252e99
--- /dev/null
+++ b/gui-editors/gui-editor-apex/src/lombok.config
@@ -0,0 +1,2 @@
+# tells Lombok to add @lombok.Generated annotation to all generated methods
+lombok.addLombokGeneratedAnnotation = true
\ No newline at end of file