Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add inventory item constraints #1063

Merged
merged 15 commits into from
Jan 10, 2025
Merged
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
21 changes: 21 additions & 0 deletions features/fedramp_extensions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Examples:
| address-type |
| aggregate-parameters-warning |
| attachment-type |
| authenticated-scan-no-has-remarks |
| authentication-method-has-remarks |
| authorization-type |
| by-component-has-responsible-role |
Expand All @@ -49,6 +50,7 @@ Examples:
| data-center-primary |
| data-center-us |
| deployment-model |
| end-of-life-date-type |
| external-system-nature-of-agreement |
| extraneous-implemented-requirements |
| fedramp-citations-has-correct-link |
Expand Down Expand Up @@ -104,6 +106,7 @@ Examples:
| has-system-id |
| has-system-name-short |
| has-user-guide |
| high-impact-inventory-item-has-asset-owner |
| image-has-checksum |
| implementation-status-has-remarks |
| import-profile-has-available-document |
Expand All @@ -116,10 +119,13 @@ Examples:
| information-type-has-confidentiality-impact |
| information-type-has-integrity-impact |
| information-type-system |
| inter-boundary-component-has-information-type |
| interconnection-direction |
| interconnection-security |
| inventory-item-allows-authenticated-scan |
| inventory-item-and-component-has-public |
| inventory-item-has-function |
| inventory-item-has-scan-type |
| inventory-item-has-valid-mac-address |
| inventory-item-has-vendor-name |
| inventory-item-or-component-has-asset-id |
Expand Down Expand Up @@ -154,6 +160,7 @@ Examples:
| role-defined-system-owner |
| saas-has-leveraged-authorization |
| scan-type |
| scan-type-has-remarks |
| security-level |
| security-sensitivity-level-matches-security-impact-level |
| statement-has-this-system-component |
Expand Down Expand Up @@ -189,6 +196,8 @@ Examples:
| aggregate-parameters-warning-PASS.yaml |
| attachment-type-FAIL.yaml |
| attachment-type-PASS.yaml |
| authenticated-scan-no-has-remarks-FAIL.yaml |
| authenticated-scan-no-has-remarks-PASS.yaml |
| authentication-method-has-remarks-FAIL.yaml |
| authentication-method-has-remarks-PASS.yaml |
| authorization-type-FAIL.yaml |
Expand Down Expand Up @@ -231,6 +240,8 @@ Examples:
| data-center-us-PASS.yaml |
| deployment-model-FAIL.yaml |
| deployment-model-PASS.yaml |
| end-of-life-date-type-FAIL.yaml |
| end-of-life-date-type-PASS.yaml |
| external-system-nature-of-agreement-FAIL.yaml |
| external-system-nature-of-agreement-PASS.yaml |
| extraneous-implemented-requirements-FAIL.yaml |
Expand Down Expand Up @@ -341,6 +352,8 @@ Examples:
| has-system-name-short-PASS.yaml |
| has-user-guide-FAIL.yaml |
| has-user-guide-PASS.yaml |
| high-impact-inventory-item-has-asset-owner-FAIL.yaml |
| high-impact-inventory-item-has-asset-owner-PASS.yaml |
| image-has-checksum-FAIL.yaml |
| image-has-checksum-PASS.yaml |
| implementation-status-has-remarks-FAIL.yaml |
Expand All @@ -365,6 +378,8 @@ Examples:
| information-type-id-PASS.yaml |
| information-type-system-FAIL.yaml |
| information-type-system-PASS.yaml |
| inter-boundary-component-has-information-type-FAIL.yaml |
| inter-boundary-component-has-information-type-PASS.yaml |
| interconnection-direction-FAIL.yaml |
| interconnection-direction-PASS.yaml |
| interconnection-security-FAIL.yaml |
Expand All @@ -373,6 +388,10 @@ Examples:
| inventory-item-allows-authenticated-scan-PASS.yaml |
| inventory-item-and-component-has-public-FAIL.yaml |
| inventory-item-and-component-has-public-PASS.yaml |
| inventory-item-has-function-FAIL.yaml |
| inventory-item-has-function-PASS.yaml |
| inventory-item-has-scan-type-FAIL.yaml |
| inventory-item-has-scan-type-PASS.yaml |
| inventory-item-has-valid-mac-address-FAIL.yaml |
| inventory-item-has-valid-mac-address-PASS.yaml |
| inventory-item-has-vendor-name-FAIL.yaml |
Expand Down Expand Up @@ -441,6 +460,8 @@ Examples:
| saas-has-leveraged-authorization-PASS.yaml |
| scan-type-FAIL.yaml |
| scan-type-PASS.yaml |
| scan-type-has-remarks-FAIL.yaml |
| scan-type-has-remarks-PASS.yaml |
| security-level-FAIL.yaml |
| security-level-PASS.yaml |
| security-sensitivity-level-matches-security-impact-level-FAIL.yaml |
Expand Down
30 changes: 19 additions & 11 deletions features/steps/fedramp_extensions_steps.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { BeforeAll, BeforeStep, Given, Then, When, setDefaultTimeout, world } from "@cucumber/cucumber";
import { BeforeAll, Given, Then, When, setDefaultTimeout } from "@cucumber/cucumber";
import { expect } from "chai";
import {
existsSync,
mkdirSync,
readFileSync,
readdirSync,
unlinkSync,
writeFileSync,
mkdirSync,
existsSync,
} from "fs";
import { load } from "js-yaml";
import { executeOscalCliCommand, resolveProfile, resolveProfileDocument, validateDocument} from "oscal";
import {checkServerStatus} from 'oscal/dist/server.js'
import { dirname, join,parse, resolve } from "path";
import { Exception, Log, Result } from "sarif";
import { JSDOM } from 'jsdom';
import { executeOscalCliCommand, formatSarifOutput, resolveProfileDocument, validateDocument } from "oscal";
import { checkServerStatus } from 'oscal/dist/server.js';
import { dirname, join, parse, resolve } from "path";
import { Log } from "sarif";
import { fileURLToPath } from "url";
import { parseString } from "xml2js";
import {JSDOM} from 'jsdom'
import { promisify } from "util";
import {formatSarifOutput} from 'oscal'
import { parseString } from "xml2js";
let executor: 'oscal-cli'|'oscal-server' = process.env.OSCAL_EXECUTOR as 'oscal-cli'|'oscal-server' || 'oscal-cli'
const quiet = process.env.OSCAL_TEST_QUIET === 'true'

Expand Down Expand Up @@ -686,6 +685,7 @@ Then('I should have valid results {string}', async function (fileToValidate) {

Then('I should verify that all constraints follow the style guide constraint', async function () {
const baseDir = join(__dirname, '..', '..');
const styleGuidePath = join(baseDir, 'src', 'validations', 'styleguides', 'fedramp-constraint-style.xml');
const constraintDir = join(baseDir, 'src', 'validations', 'constraints');
const constraintFiles = readdirSync(constraintDir).filter(file =>
file.startsWith('fedramp') && file.endsWith('.xml')
Expand All @@ -701,7 +701,15 @@ Then('I should verify that all constraints follow the style guide constraint', a
const fileContent = readFileSync(filePath, 'utf8');
const dom = new JSDOM(fileContent, { contentType: 'text/xml' });
const document = dom.window.document;

const {isValid,log} = await validateDocument(filePath,{flags:['disable-schema'],quiet,extensions:[styleGuidePath],module:"http://csrc.nist.gov/ns/oscal/metaschema/1.0"},executor)
writeFileSync(
join(
__dirname,
"../../sarif/",
fileName.split(".xml").join("").toString()+".sarif"
),JSON.stringify(log, null,"\t"))
const formattedErrors = (formatSarifOutput(log));
formattedErrors&&errors.push(formattedErrors)
// Process each 'constraints' block separately
document.querySelectorAll('constraints').forEach(constraintsNode => {
// Get direct child elements with IDs within this constraints block
Expand Down
Loading
Loading