mirror of
https://github.com/openai/codex-security.git
synced 2026-11-21 22:25:34 +08:00
Simplify scan outcomes across the CLI, SDK, and GitHub Action. Completed report-only scans return 0, an opt-in findings threshold returns 1, and execution or required-output failures return 2. Remove partial and unknown outcomes while retaining coverage diagnostics and saved results. Require the current plugin for Deep Scan and canonical fields for new findings. Preserve readability of historical sealed reports. Update documentation and tests, and remove obsolete compatibility paths.
66 lines
5.3 KiB
TypeScript
66 lines
5.3 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { plain, resultSummary, resultTitle } from '../src/reporting.js';
|
|
import { parseInputs } from '../src/inputs.js';
|
|
import type { ScanResults } from '../src/results.js';
|
|
|
|
test('credential-shaped text and encodings remain in diagnostics',()=>{
|
|
assert.equal(plain('CANA\x01RY_VALUE'),'CANARY_VALUE');
|
|
for(const text of ['CANARY_VALUE',Buffer.from('CANARY_VALUE').toString('base64'),encodeURIComponent('canary/key'), 'Synthetic diagnostic. '.repeat(400)]) {
|
|
assert.equal(plain(text),text);
|
|
}
|
|
});
|
|
test('finding titles and messages cannot become Markdown links, images or raw HTML',()=>{
|
|
const result = {scanStatus:'completed',policyStatus:'passed',reportStatus:'ready',counts:{critical:0,high:1,medium:0,low:0,informational:0},errors:[],
|
|
findings:[{severity:'high',title:' <img src=x> @someone',summary:'</pre><script>bad</script>',path:'src/app.ts',startLine:1}]} as unknown as ScanResults;
|
|
const summary = resultSummary(result,parseInputs(()=>'', '/checkout'),{repository:'/checkout',scannedSha:'a'.repeat(40),analysisRef:'refs/heads/main',publishable:true,emptyDiff:false});
|
|
assert.ok(summary.includes('<h3>HIGH:  <img src=x> @someone</h3>'));
|
|
assert.ok(summary.includes('</pre><script>bad</script>'));
|
|
assert.ok(!summary.includes('### HIGH:')); assert.ok(!summary.includes('<img'));
|
|
});
|
|
|
|
test('completed findings are subject to severity policy without a coverage qualification', () => {
|
|
const result = {scanStatus:'completed',policyStatus:'failed',reportStatus:'ready',counts:{critical:0,high:1,medium:0,low:0,informational:0},
|
|
errors:[],findings:[{severity:'high',title:'Extraction issue',summary:'Archive traversal reaches files outside the destination.',path:'src/extract.ts',startLine:12}]} as unknown as ScanResults;
|
|
const inputs = parseInputs((name) => name === 'fail-on-severity' ? 'high' : '', '/checkout');
|
|
const summary = resultSummary(result, inputs, {repository:'/checkout',scannedSha:'a'.repeat(40),analysisRef:'refs/heads/main',publishable:true,emptyDiff:false});
|
|
assert.match(resultTitle(result, inputs), /Findings meet the configured failure threshold/);
|
|
assert.match(summary, /\*\*Scan:\*\* completed · \*\*Findings policy:\*\* failed/);
|
|
assert.match(summary, /\*\*Failure threshold:\*\* high and above/);
|
|
assert.match(summary, /HIGH: Extraction issue/);
|
|
assert.doesNotMatch(summary, /provisional|partial|unknown|not evaluated/i);
|
|
});
|
|
|
|
test('required reporting failures remain visible after a completed scan', () => {
|
|
const inputs = parseInputs(() => '', '/checkout');
|
|
const result = {scanStatus:'completed',policyStatus:'passed',reportStatus:'failed'} as ScanResults;
|
|
assert.match(resultTitle(result, inputs), /Scan completed, but required reporting failed/i);
|
|
assert.match(resultTitle({...result, scanStatus:'failed'}, inputs), /Scan could not complete/);
|
|
});
|
|
|
|
test('multiline titles remain literal across blank lines without losing diagnostic text', () => {
|
|
const result = {scanStatus:'completed',policyStatus:'passed',reportStatus:'ready',counts:{critical:0,high:1,medium:0,low:0,informational:0},errors:[],
|
|
findings:[{severity:'high',title:'Title\n\n\r\n\r\n[link](https://example.invalid)',summary:'First line\n\nNext line',path:'src/app.ts',startLine:1}]} as unknown as ScanResults;
|
|
const summary = resultSummary(result,parseInputs(()=>'', '/checkout'),{repository:'/checkout',scannedSha:'a'.repeat(40),analysisRef:'refs/heads/main',publishable:true,emptyDiff:false});
|
|
assert.ok(summary.includes('<h3>HIGH: Title  [link](https://example.invalid)</h3>'));
|
|
assert.ok(summary.includes('<pre>First line Next line</pre>'));
|
|
assert.doesNotMatch(summary, /<h3>[^]*?\n[^]*?<\/h3>/);
|
|
});
|
|
|
|
|
|
test('report fields preserve Markdown punctuation as literal content', () => {
|
|
const text = '_name_ *bold* [link](https://example.invalid)  `code` ~~text~~';
|
|
const escaped = '_name_ *bold* [link](https://example.invalid)  `code` ~~text~~';
|
|
const result = {scanStatus:'completed',policyStatus:'passed',reportStatus:'ready',counts:{critical:0,high:1,medium:0,low:0,informational:0},
|
|
errors:[text],findings:[{severity:'high',title:text,summary:text,path:'pkg/__init__.py',startLine:1},
|
|
{severity:'high',title:text,summary:text,path:`pkg/${text}`,startLine:2}]} as ScanResults;
|
|
const inputs = parseInputs(name => name === 'paths' ? 'pkg/__init__.py' : name === 'model' ? text : '', '/checkout');
|
|
const summary = resultSummary(result,inputs,{repository:'/checkout',scannedSha:'a'.repeat(40),analysisRef:'refs/heads/main',publishable:true,emptyDiff:false});
|
|
assert.ok(summary.includes(`<h3>HIGH: ${escaped}</h3>`));
|
|
assert.ok(summary.includes(`<pre>${escaped}</pre>`));
|
|
assert.ok(summary.includes(`<code>${escaped}</code>`));
|
|
assert.ok(summary.includes(`<code>pkg/${escaped}:2</code>`));
|
|
assert.ok(summary.includes('<code>pkg/__init__.py</code>'));
|
|
assert.ok(summary.includes('<code>pkg/__init__.py:1</code>'));
|
|
});
|