@mitre/inspec-objects 0.0.7 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,14 +21,15 @@ export default class Control {
21
21
  })[];
22
22
  tags: {
23
23
  check?: string;
24
+ check_id?: string;
24
25
  fix?: string;
26
+ fix_id?: string | null;
25
27
  severity?: string;
26
28
  gtitle?: string;
27
29
  gid?: string;
28
30
  satisfies?: string[];
29
31
  rid?: string;
30
32
  stig_id?: string;
31
- fix_id?: string | null;
32
33
  cci?: string[];
33
34
  cis_controls?: Record<string, string[]>[];
34
35
  nist?: string[];
@@ -60,7 +60,7 @@ function processXCCDF(xml, removeNewlines = false, useRuleId, ovalDefinitions) {
60
60
  const title = (0, xccdf_1.removeXMLSpecialCharacters)(rule['@_severity'] ? rule.title : `[[[MISSING SEVERITY FROM STIG]]] ${rule.title}`);
61
61
  control.title = title.replace(/\n/g, '{{{{newlineHERE}}}}');
62
62
  const desc = (0, xccdf_1.removeXMLSpecialCharacters)(typeof extractedDescription === 'string' ? extractedDescription : ((_a = extractedDescription.VulnDiscussion) === null || _a === void 0 ? void 0 : _a.split('Satisfies: ')[0]) || 'Missing Description');
63
- control.desc = desc === null || desc === void 0 ? void 0 : desc.replace(/\n/g, '{{{{newlineHERE}}}}');
63
+ control.desc = desc === null || desc === void 0 ? void 0 : desc.trim().replace(/\n/g, '{{{{newlineHERE}}}}');
64
64
  }
65
65
  else {
66
66
  control.title = (0, xccdf_1.removeXMLSpecialCharacters)(rule['@_severity'] ? rule.title : `[[[MISSING SEVERITY FROM STIG]]] ${rule.title}`);
@@ -125,15 +125,9 @@ function processXCCDF(xml, removeNewlines = false, useRuleId, ovalDefinitions) {
125
125
  if (rule['fix'] && rule['fix'].length > 0) {
126
126
  control.tags.fix_id = rule['fix'][0]['@_id'];
127
127
  }
128
- else {
129
- control.tags.fix_id = null;
130
- }
131
128
  if (rule['rationale']) {
132
129
  control.tags.rationale = rule['rationale'][0]['#text'];
133
130
  }
134
- else {
135
- control.tags.rationale = null;
136
- }
137
131
  if (typeof extractedDescription === 'object') {
138
132
  control.tags.satisfies = ((_c = extractedDescription.VulnDiscussion) === null || _c === void 0 ? void 0 : _c.includes('Satisfies: ')) && extractedDescription.VulnDiscussion.split('Satisfies: ').length >= 1 ? extractedDescription.VulnDiscussion.split('Satisfies: ')[1].split(',').map(satisfaction => satisfaction.trim()) : undefined;
139
133
  control.tags.false_negatives = extractedDescription.FalseNegatives || undefined;
@@ -1,4 +1,8 @@
1
1
  import Profile from '../objects/profile';
2
2
  import { ProfileDiff } from '../types/diff';
3
3
  export declare function removeNewlines(control?: Record<string, unknown>): Record<string, unknown>;
4
- export declare function diffProfile(fromProfile: Profile, toProfile: Profile): ProfileDiff;
4
+ export declare function simplifyDiff(diffData: Record<string, unknown>): Record<string, unknown>;
5
+ export declare function diffProfile(fromProfile: Profile, toProfile: Profile): {
6
+ simplified: ProfileDiff;
7
+ originalDiff: Record<string, unknown>;
8
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.diffProfile = exports.removeNewlines = void 0;
3
+ exports.diffProfile = exports.simplifyDiff = exports.removeNewlines = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const json_diff_1 = require("json-diff");
6
6
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
@@ -19,12 +19,37 @@ function removeNewlines(control) {
19
19
  });
20
20
  }
21
21
  exports.removeNewlines = removeNewlines;
22
+ function simplifyDiff(diffData) {
23
+ return lodash_1.default.transform(diffData, (result, diffValue, key) => {
24
+ if (lodash_1.default.has(diffValue, '__new')) {
25
+ result[key] = lodash_1.default.get(diffValue, '__new');
26
+ }
27
+ else if (Array.isArray(diffValue)) {
28
+ result[key] = diffValue.map((value) => value[0] === '+' && value[1]).filter(value => value);
29
+ }
30
+ else if (typeof diffValue === 'object') {
31
+ result[key] = simplifyDiff(diffValue);
32
+ }
33
+ else if (key.endsWith('__deleted')) {
34
+ return undefined;
35
+ }
36
+ else {
37
+ result[key] = diffValue;
38
+ }
39
+ });
40
+ }
41
+ exports.simplifyDiff = simplifyDiff;
22
42
  function diffProfile(fromProfile, toProfile) {
23
43
  const profileDiff = {
24
44
  addedControlIDs: [],
25
45
  removedControlIDs: [],
26
46
  changedControls: {}
27
47
  };
48
+ const originalDiff = {
49
+ addedControlIDs: [],
50
+ removedControlIDs: [],
51
+ changedControls: {}
52
+ };
28
53
  const fromControlIDs = fromProfile.controls.map((control) => control.id).sort();
29
54
  const toControlIDs = toProfile.controls.map((control) => control.id).sort();
30
55
  // Find new controls
@@ -32,9 +57,11 @@ function diffProfile(fromProfile, toProfile) {
32
57
  controlIDDiff === null || controlIDDiff === void 0 ? void 0 : controlIDDiff.forEach((diffValue) => {
33
58
  if (diffValue[0] === '-') {
34
59
  profileDiff.removedControlIDs.push(diffValue[1]);
60
+ originalDiff.removedControlIDs.push(diffValue[1]);
35
61
  }
36
62
  else if (diffValue[0] === '+') {
37
63
  profileDiff.addedControlIDs.push(diffValue[1]);
64
+ originalDiff.addedControlIDs.push(diffValue[1]);
38
65
  }
39
66
  });
40
67
  // Add new controls to changedControls
@@ -42,27 +69,20 @@ function diffProfile(fromProfile, toProfile) {
42
69
  const newControl = toProfile.controls.find((control) => addedControl === control.id);
43
70
  if (newControl) {
44
71
  profileDiff.changedControls[addedControl] = newControl;
72
+ originalDiff.changedControls[addedControl] = newControl;
45
73
  }
46
74
  });
47
75
  // Find changed controls
48
76
  for (const fromControl of fromProfile.controls) {
49
77
  const toControl = toProfile.controls.find((control) => control.id === fromControl.id);
50
78
  if (toControl) {
51
- const controlDiff = (0, json_diff_1.diff)(fromControl, toControl);
79
+ const controlDiff = lodash_1.default.omit((0, json_diff_1.diff)(fromControl, toControl), 'code__deleted');
52
80
  if (controlDiff) {
53
- Object.entries(controlDiff).forEach(([key, value]) => {
54
- if (lodash_1.default.has(value, '__new')) {
55
- lodash_1.default.set(profileDiff, 'changedControls.' + fromControl.id + '.' + key.replace('.', '\\.'), lodash_1.default.get(controlDiff, key + '.__new'));
56
- }
57
- else if (typeof value === 'object') {
58
- Object.entries(value).forEach(([subKey]) => {
59
- lodash_1.default.set(profileDiff, 'changedControls.' + fromControl.id + '.' + key.replace('.', '\\.') + '.' + subKey.replace('.', '\\.'), lodash_1.default.get(controlDiff, key + '.' + subKey + '.__new'));
60
- });
61
- }
62
- });
81
+ profileDiff.changedControls[toControl.id] = simplifyDiff(controlDiff);
82
+ originalDiff.changedControls[toControl.id] = controlDiff;
63
83
  }
64
84
  }
65
85
  }
66
- return profileDiff;
86
+ return { simplified: profileDiff, originalDiff: originalDiff };
67
87
  }
68
88
  exports.diffProfile = diffProfile;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mitre/inspec-objects",
3
- "version": "0.0.7",
3
+ "version": "0.0.10",
4
4
  "description": "Typescript objects for normalizing between InSpec profiles and XCCDF benchmarks",
5
5
  "main": "lib/index.js",
6
6
  "publishConfig": {
Binary file
Binary file
Binary file
Binary file