@mitre/inspec-objects 0.0.24 → 0.0.27
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.
- package/lib/parsers/oval.d.ts +2 -1
- package/lib/parsers/oval.js +95 -1
- package/lib/parsers/xccdf.d.ts +6 -2
- package/lib/parsers/xccdf.js +99 -8
- package/lib/utilities/CciNistMappingData.d.ts +5100 -0
- package/lib/utilities/CciNistMappingData.js +5103 -0
- package/lib/utilities/update.d.ts +1 -1
- package/lib/utilities/update.js +24 -25
- package/lib/utilities/xccdf.d.ts +1 -0
- package/lib/utilities/xccdf.js +7 -1
- package/mitre-inspec-objects-v0.0.27.tgz +0 -0
- package/package.json +5 -1
- package/package-lock.json +0 -8529
package/lib/utilities/update.js
CHANGED
|
@@ -9,15 +9,13 @@ const profile_1 = tslib_1.__importDefault(require("../objects/profile"));
|
|
|
9
9
|
const xccdf_1 = require("../parsers/xccdf");
|
|
10
10
|
const diff_1 = require("./diff");
|
|
11
11
|
const diffMarkdown_1 = require("./diffMarkdown");
|
|
12
|
-
const knownInSpecKeywords = ['title', 'desc', 'impact', 'ref', 'tag',
|
|
12
|
+
const knownInSpecKeywords = ['title', 'desc', 'impact', 'ref', 'tag', "\""];
|
|
13
13
|
function projectValuesOntoExistingObj(dst, src, currentPath = '') {
|
|
14
14
|
for (const updatedValue in src) {
|
|
15
15
|
const existingValue = lodash_1.default.get(dst, updatedValue);
|
|
16
16
|
// We have a new value for something that already exists in dst
|
|
17
17
|
if (existingValue !== undefined) {
|
|
18
|
-
if (typeof existingValue === 'object' &&
|
|
19
|
-
existingValue !== null &&
|
|
20
|
-
!Array.isArray(existingValue)) {
|
|
18
|
+
if (typeof existingValue === 'object' && existingValue !== null && !Array.isArray(existingValue)) {
|
|
21
19
|
dst[updatedValue] = projectValuesOntoExistingObj(existingValue, src[updatedValue], currentPath + updatedValue + '.');
|
|
22
20
|
}
|
|
23
21
|
else if (typeof src[updatedValue] === 'string') {
|
|
@@ -27,9 +25,7 @@ function projectValuesOntoExistingObj(dst, src, currentPath = '') {
|
|
|
27
25
|
lodash_1.default.set(dst, updatedValue, src[updatedValue]);
|
|
28
26
|
}
|
|
29
27
|
else if (Array.isArray(src[updatedValue])) {
|
|
30
|
-
const uniqueArrayValues = [
|
|
31
|
-
...new Set(lodash_1.default.get(dst, updatedValue, []).concat(src[updatedValue]))
|
|
32
|
-
];
|
|
28
|
+
const uniqueArrayValues = [...new Set(lodash_1.default.get(dst, updatedValue, []).concat(src[updatedValue]))];
|
|
33
29
|
lodash_1.default.set(dst, updatedValue, uniqueArrayValues);
|
|
34
30
|
}
|
|
35
31
|
}
|
|
@@ -44,24 +40,23 @@ function getExistingDescribeFromControl(control) {
|
|
|
44
40
|
let currentQuoteEscape = '';
|
|
45
41
|
let inQuoteBlock = false;
|
|
46
42
|
let inMetadataValueOverride = false;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (typeof splitLines[lineIndex - 1] === 'string') {
|
|
51
|
-
if (knownInSpecKeywords.indexOf(splitLines[lineIndex - 1].trim().split(' ')[0]) !== -1 &&
|
|
52
|
-
splitLines[lineIndex - 1].trim().split(' ')[1].startsWith('[')) {
|
|
53
|
-
inMetadataValueOverride = true;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
43
|
+
let indentedMetadataOverride = false;
|
|
44
|
+
let mostSpacesSeen = 0;
|
|
45
|
+
control.code.split('\n').forEach((line) => {
|
|
56
46
|
const wordSplit = line.trim().split(' ');
|
|
57
|
-
|
|
47
|
+
const spaces = line.substring(0, line.indexOf(wordSplit[0])).length;
|
|
48
|
+
if (spaces - mostSpacesSeen > 10) {
|
|
49
|
+
indentedMetadataOverride = true;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
mostSpacesSeen = spaces;
|
|
53
|
+
indentedMetadataOverride = false;
|
|
54
|
+
}
|
|
55
|
+
if (!inQuoteBlock && !inMetadataValueOverride && !indentedMetadataOverride) {
|
|
58
56
|
// Get the number of spaces at the beggining of the current line
|
|
59
|
-
const spaces = line.substring(0, line.indexOf(wordSplit[0])).length;
|
|
60
57
|
if (spaces >= 2) {
|
|
61
58
|
const firstWord = wordSplit[0];
|
|
62
|
-
if (knownInSpecKeywords.indexOf(firstWord.toLowerCase()) === -1 ||
|
|
63
|
-
(knownInSpecKeywords.indexOf(firstWord.toLowerCase()) !== -1 &&
|
|
64
|
-
spaces > 2)) {
|
|
59
|
+
if (knownInSpecKeywords.indexOf(firstWord.toLowerCase()) === -1 || (knownInSpecKeywords.indexOf(firstWord.toLowerCase()) !== -1 && spaces > 2)) {
|
|
65
60
|
existingDescribeBlock += line + '\n';
|
|
66
61
|
}
|
|
67
62
|
}
|
|
@@ -70,7 +65,7 @@ function getExistingDescribeFromControl(control) {
|
|
|
70
65
|
const charSplit = word.split('');
|
|
71
66
|
charSplit.forEach((char, index) => {
|
|
72
67
|
if (char === '"' && charSplit[index - 1] !== '\\') {
|
|
73
|
-
if (!currentQuoteEscape) {
|
|
68
|
+
if (!currentQuoteEscape || !inQuoteBlock) {
|
|
74
69
|
currentQuoteEscape = '"';
|
|
75
70
|
}
|
|
76
71
|
if (currentQuoteEscape === '"') {
|
|
@@ -78,7 +73,7 @@ function getExistingDescribeFromControl(control) {
|
|
|
78
73
|
}
|
|
79
74
|
}
|
|
80
75
|
else if (char === "'" && charSplit[index - 1] !== '\\') {
|
|
81
|
-
if (!currentQuoteEscape) {
|
|
76
|
+
if (!currentQuoteEscape || !inQuoteBlock) {
|
|
82
77
|
currentQuoteEscape = "'";
|
|
83
78
|
}
|
|
84
79
|
if (currentQuoteEscape === "'") {
|
|
@@ -87,6 +82,10 @@ function getExistingDescribeFromControl(control) {
|
|
|
87
82
|
}
|
|
88
83
|
});
|
|
89
84
|
});
|
|
85
|
+
if (control.id === 'SV-204392') {
|
|
86
|
+
console.log(line);
|
|
87
|
+
console.log(inQuoteBlock);
|
|
88
|
+
}
|
|
90
89
|
});
|
|
91
90
|
return existingDescribeBlock;
|
|
92
91
|
}
|
|
@@ -130,7 +129,7 @@ function updateProfile(from, using, logger) {
|
|
|
130
129
|
// Find the diff
|
|
131
130
|
const diff = (0, diff_1.diffProfile)(from, using, logger);
|
|
132
131
|
// Add the new controls
|
|
133
|
-
diff.simplified.addedControlIDs.forEach(
|
|
132
|
+
diff.simplified.addedControlIDs.forEach(id => {
|
|
134
133
|
const addedControl = diff.simplified.addedControls[id];
|
|
135
134
|
if (addedControl) {
|
|
136
135
|
logger.debug(`New Control: ${addedControl.id} - ${addedControl.title}`);
|
|
@@ -155,7 +154,7 @@ function updateProfile(from, using, logger) {
|
|
|
155
154
|
}
|
|
156
155
|
return {
|
|
157
156
|
profile: to,
|
|
158
|
-
diff
|
|
157
|
+
diff,
|
|
159
158
|
};
|
|
160
159
|
}
|
|
161
160
|
exports.updateProfile = updateProfile;
|
package/lib/utilities/xccdf.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DecodedDescription } from '../types/xccdf';
|
|
2
2
|
export declare function convertEncodedXmlIntoJson(encodedXml: string): any;
|
|
3
|
+
export declare function convertJsonIntoXML(data: any): string;
|
|
3
4
|
export declare function removeXMLSpecialCharacters(str: string): string;
|
|
4
5
|
export declare function severityStringToImpact(string: string, id: string): number;
|
|
5
6
|
export declare function impactNumberToSeverityString(impact: number): string;
|
package/lib/utilities/xccdf.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertEncodedHTMLIntoJson = exports.impactNumberToSeverityString = exports.severityStringToImpact = exports.removeXMLSpecialCharacters = exports.convertEncodedXmlIntoJson = void 0;
|
|
3
|
+
exports.convertEncodedHTMLIntoJson = exports.impactNumberToSeverityString = exports.severityStringToImpact = exports.removeXMLSpecialCharacters = exports.convertJsonIntoXML = exports.convertEncodedXmlIntoJson = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fast_xml_parser_1 = tslib_1.__importDefault(require("fast-xml-parser"));
|
|
6
|
+
const jstoxml_1 = require("jstoxml");
|
|
6
7
|
const htmlparser = tslib_1.__importStar(require("htmlparser2"));
|
|
7
8
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
8
9
|
const he_1 = tslib_1.__importDefault(require("he"));
|
|
@@ -11,10 +12,15 @@ function convertEncodedXmlIntoJson(encodedXml) {
|
|
|
11
12
|
ignoreAttributes: false,
|
|
12
13
|
ignoreNameSpace: true,
|
|
13
14
|
attributeNamePrefix: '@_',
|
|
15
|
+
stopNodes: ['div', 'p'],
|
|
14
16
|
arrayMode: true
|
|
15
17
|
});
|
|
16
18
|
}
|
|
17
19
|
exports.convertEncodedXmlIntoJson = convertEncodedXmlIntoJson;
|
|
20
|
+
function convertJsonIntoXML(data) {
|
|
21
|
+
return (0, jstoxml_1.toXML)(data);
|
|
22
|
+
}
|
|
23
|
+
exports.convertJsonIntoXML = convertJsonIntoXML;
|
|
18
24
|
function removeXMLSpecialCharacters(str) {
|
|
19
25
|
return he_1.default.decode(str);
|
|
20
26
|
}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mitre/inspec-objects",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27",
|
|
4
4
|
"description": "Typescript objects for normalizing between InSpec profiles and XCCDF benchmarks",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -25,8 +25,10 @@
|
|
|
25
25
|
"@types/flat": "^5.0.2",
|
|
26
26
|
"@types/he": "^1.1.2",
|
|
27
27
|
"@types/json-diff": "^0.7.0",
|
|
28
|
+
"@types/jstoxml": "^2.0.2",
|
|
28
29
|
"@types/lodash": "^4.14.178",
|
|
29
30
|
"@types/mustache": "^4.2.0",
|
|
31
|
+
"@types/pretty": "^2.0.1",
|
|
30
32
|
"fast-xml-parser": "^3.1.19",
|
|
31
33
|
"flat": "^5.0.2",
|
|
32
34
|
"he": "^1.2.0",
|
|
@@ -34,8 +36,10 @@
|
|
|
34
36
|
"inspecjs": "^2.6.6",
|
|
35
37
|
"jest": "^28.1.1",
|
|
36
38
|
"json-diff": "^0.9.0",
|
|
39
|
+
"jstoxml": "^3.2.3",
|
|
37
40
|
"lodash": "^4.17.21",
|
|
38
41
|
"mustache": "^4.2.0",
|
|
42
|
+
"pretty": "^2.0.0",
|
|
39
43
|
"ts-jest": "^28.0.4",
|
|
40
44
|
"typescript": "^4.5.5",
|
|
41
45
|
"winston": "^3.8.1",
|