Skip to content
Open
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
8 changes: 5 additions & 3 deletions lib/src/api/xml-json/alter-isra/alter-business-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,23 @@ const alterBusinessAssets = (xmlDataCopy, businessAssetsCopy) => {

ba.businessAssetDescription = getHTMLString(xmlDataCopy, 'businessAssetDescription', businessAssetCounter.getCount());

ba.businessAssetProperties = (({
const {
businessAssetConfidentiality,
businessAssetIntegrity,
businessAssetAvailability,
businessAssetAuthenticity,
businessAssetAuthorization,
businessAssetNonRepudiation,
}) => ({
} = ba;

ba.businessAssetProperties = {
businessAssetConfidentiality,
businessAssetIntegrity,
businessAssetAvailability,
businessAssetAuthenticity,
businessAssetAuthorization,
businessAssetNonRepudiation,
}))(ba);
};
// ba.businessAssetProperties.businessAssetIdRef = ba.businessAssetId;
});
}
Expand Down
22 changes: 10 additions & 12 deletions lib/src/api/xml-json/alter-isra/alter-isra.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,17 @@ const { getHTMLString } = require('../utility');
* @param {string} xmlDAta - content of xml file
* @returns {object} edited ISRA JSON data
* */
const alterISRA = (israJSONData, xmlData) => ((israJSONDataCopy, xmlDataCopy) => {
const israJSON = israJSONDataCopy;

const alterISRA = (israJSONData, xmlData) => {
// alter contents of each key tagname
israJSON.ISRAmeta = alterISRAmeta(israJSONDataCopy.ISRAmeta).pop();
israJSON.ProjectContext = alterProjectContext(xmlDataCopy, israJSONDataCopy.ProjectContext).pop();
israJSON.SupportingAssetsDesc = getHTMLString(xmlDataCopy, 'supportingAssetDiagram');
alterBusinessAssets(xmlDataCopy, israJSONDataCopy.BusinessAsset);
alterSupportingAssets(israJSONDataCopy.SupportingAsset, israJSONDataCopy.BusinessAsset);
alterRisks(xmlDataCopy, israJSONDataCopy.Risk, israJSONDataCopy.BusinessAsset, israJSONDataCopy.SupportingAsset);
alterVulnerability(xmlDataCopy, israJSONDataCopy.Vulnerability);
israJSONData.ISRAmeta = alterISRAmeta(israJSONData.ISRAmeta).pop();
israJSONData.ProjectContext = alterProjectContext(xmlData, israJSONData.ProjectContext).pop();
israJSONData.SupportingAssetsDesc = getHTMLString(xmlData, 'supportingAssetDiagram');
alterBusinessAssets(xmlData, israJSONData.BusinessAsset);
alterSupportingAssets(israJSONData.SupportingAsset, israJSONData.BusinessAsset);
alterRisks(xmlData, israJSONData.Risk, israJSONData.BusinessAsset, israJSONData.SupportingAsset);
alterVulnerability(xmlData, israJSONData.Vulnerability);

return israJSON;
})(israJSONData, xmlData);
return israJSONData;
};

module.exports = alterISRA;
21 changes: 11 additions & 10 deletions lib/src/api/xml-json/alter-isra/alter-risks.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ const alterRisks = (xmlDataCopy, risksCopy, businessAssetsCopy = [], supportingA
const riskCounter = counter();
const riskMitigationCounter = counter();

// Build lookup maps once outside of the loop for O(1) retrieval and better performance
const businessAssets = {};
businessAssetsCopy.forEach((asset) => {
businessAssets[asset.businessAssetId[0]] = asset.businessAssetName[0];
});

const supportingAssets = {};
supportingAssetsCopy.forEach((asset) => {
supportingAssets[asset.supportingAssetId[0]] = asset.supportingAssetName[0];
});

risksCopy.forEach((risk) => {
riskCounter.increment();
const r = risk;
Expand Down Expand Up @@ -69,16 +80,6 @@ const alterRisks = (xmlDataCopy, risksCopy, businessAssetsCopy = [], supportingA
r.motivationDetail = getHTMLString(xmlDataCopy, 'motivationDetail', riskCounter.getCount())

// remove businessAssetRef & its corresponding supportingAssetRef if businessAssetId does not exist
const businessAssets= {};
businessAssetsCopy.forEach((asset) => {
businessAssets[asset.businessAssetId[0]] = asset.businessAssetName[0];
});

const supportingAssets = {};
supportingAssetsCopy.forEach((asset)=>{
supportingAssets[asset.supportingAssetId[0]] = asset.supportingAssetName[0];
});

if (businessAssets[businessAssetRef[0]] === undefined) {
r.businessAssetRef = null;
r.supportingAssetRef = null;
Expand Down
13 changes: 6 additions & 7 deletions lib/src/api/xml-json/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ const parser = (xml) => {
* @returns {string} edited xml name
* */
const editName = (name) => {
let tagname = name;
tagname = tagname.match('ISRA_tracking') ? tagname.replace('_', '') : tagname;
tagname = tagname.match('accessRessources') ? tagname.replace('accessRessources', 'accessResources') : tagname;
tagname = tagname.match('intrusionDection') ? tagname.replace('intrusionDection', 'intrusionDetection') : tagname;
tagname = tagname.match('riskManagmentDetail') ? tagname.replace('riskManagmentDetail', 'riskManagementDetail') : tagname;
tagname = tagname.match('occurence') ? tagname.replace('occurence', 'occurrence') : tagname;
return tagname;
return name
.replace('ISRA_tracking', 'ISRAtracking')
.replace('accessRessources', 'accessResources')
.replace('intrusionDection', 'intrusionDetection')
.replace('riskManagmentDetail', 'riskManagementDetail')
.replace('occurence', 'occurrence');
};

/** to remove namespace
Expand Down
8 changes: 4 additions & 4 deletions lib/src/api/xml-json/populate-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ const populateClass = (data, israProject) => {
const baProperties = new BusinessAssetProperties();
const { businessAssetId, businessAssetProperties, businessAssetName, ...rest } = invalidBA;
highestBAId += 1;
const defaultBusinessAssetName = `Please name Business Asset ${highestBAId? highestBAId: businessAssetId}`
const defaultBusinessAssetName = `Please name Business Asset ${highestBAId}`


Object.assign(baProperties, businessAssetProperties);
Object.assign(ba, { businessAssetId: highestBAId? highestBAId: businessAssetId,businessAssetName: businessAssetName?
Object.assign(ba, { businessAssetId: highestBAId, businessAssetName: businessAssetName?
businessAssetName: defaultBusinessAssetName, ...rest });
ba.businessAssetProperties = baProperties;

Expand All @@ -147,8 +147,8 @@ const populateClass = (data, israProject) => {
const sa = new SupportingAsset();
const { supportingAssetId, businessAssetRef, supportingAssetName, ...rest } = invalidSA;
highestSAId += 1;
const defaultSupportingAssetName = `Please name Supporting Asset ${ highestSAId? highestSAId: supportingAssetId}`
Object.assign(sa, { supportingAssetId: highestSAId? highestSAId: supportingAssetId, supportingAssetName: supportingAssetName?
const defaultSupportingAssetName = `Please name Supporting Asset ${highestSAId}`
Object.assign(sa, { supportingAssetId: highestSAId, supportingAssetName: supportingAssetName?
supportingAssetName: defaultSupportingAssetName, ...rest });
businessAssetRef.forEach((ref) => {
sa.addBusinessAssetRef(ref);
Expand Down
31 changes: 11 additions & 20 deletions lib/src/utility-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,17 @@
* -----------------------------------------------------------------------------
*/
// used by api & classes
const utilityGlobal = (() => {
const counter = () => {
// eslint-disable-next-line no-unused-vars
let count = 0;
const increment = (val) => {
count += val;
};

return {
increment: () => {
increment(1);
},

getCount: () => count,
};
};

const counter = () => {
let count = 0;
return {
counter: () => counter(),
increment: () => {
count += 1;
},

getCount: () => count,
};
})();
};

module.exports = utilityGlobal;
module.exports = {
counter,
};