|
| 1 | +import { expect } from "chai"; |
| 2 | +import "mocha"; |
| 3 | +import * as core from "../src"; |
| 4 | +import * as path from "path-browserify"; |
| 5 | + |
| 6 | +import { ParseFlows } from "../src/main/libs/ParseFlows"; |
| 7 | +import { ParsedFlow } from "../src/main/models/ParsedFlow"; |
| 8 | + |
| 9 | +import { UnsafeRunningContext } from "../src/main/rules/UnsafeRunningContext"; |
| 10 | + |
| 11 | +describe("UnsafeRunningContext", () => { |
| 12 | + const unsafeRunningContext: UnsafeRunningContext = new UnsafeRunningContext(); |
| 13 | + |
| 14 | + it("should have a scan result for without sharing system mode", async () => { |
| 15 | + const unsafeContextTestFile = path.join( |
| 16 | + __dirname, |
| 17 | + "./xmlfiles/Unsafe_Running_Context.flow-meta.xml" |
| 18 | + ); |
| 19 | + const parsed: ParsedFlow = (await ParseFlows([unsafeContextTestFile])).pop() as ParsedFlow; |
| 20 | + const ruleResult: core.RuleResult = unsafeRunningContext.execute(parsed.flow as core.Flow); |
| 21 | + expect(ruleResult.occurs).to.be.true; |
| 22 | + expect(ruleResult.details).to.not.be.empty; |
| 23 | + expect(ruleResult.ruleDefinition.severity).to.be.equal("warning"); |
| 24 | + }); |
| 25 | + |
| 26 | + it("should not have a scan result for with sharing system mode", async () => { |
| 27 | + const unsafeContextTestFile = path.join( |
| 28 | + __dirname, |
| 29 | + "./xmlfiles/Unsafe_Running_Context_WithSharing.flow-meta.xml" |
| 30 | + ); |
| 31 | + const parsed: ParsedFlow = (await ParseFlows([unsafeContextTestFile])).pop() as ParsedFlow; |
| 32 | + const ruleResult: core.RuleResult = unsafeRunningContext.execute(parsed.flow as core.Flow); |
| 33 | + expect(ruleResult.occurs).to.be.false; |
| 34 | + expect(ruleResult.details).to.be.empty; |
| 35 | + }); |
| 36 | + |
| 37 | + it("should not have a scan result for default mode", async () => { |
| 38 | + const unsafeContextTestFile = path.join( |
| 39 | + __dirname, |
| 40 | + "./xmlfiles/Unsafe_Running_Context_Default.flow-meta.xml" |
| 41 | + ); |
| 42 | + const parsed: ParsedFlow = (await ParseFlows([unsafeContextTestFile])).pop() as ParsedFlow; |
| 43 | + const ruleResult: core.RuleResult = unsafeRunningContext.execute(parsed.flow as core.Flow); |
| 44 | + expect(ruleResult.occurs).to.be.false; |
| 45 | + expect(ruleResult.details).to.be.empty; |
| 46 | + }); |
| 47 | +}); |
0 commit comments