|
| 1 | +const assert = require('node:assert/strict'); |
| 2 | +const { describe, it } = require('node:test'); |
| 3 | +const {detectDiscussionLabels} = require('./helpers.js'); |
| 4 | + |
| 5 | +const configDiscussionLabels = { |
| 6 | + "Container Image":"ContainerImageLabel", |
| 7 | + "Filesystem":"FilesystemLabel", |
| 8 | + "Vulnerability":"VulnerabilityLabel", |
| 9 | + "Misconfiguration":"MisconfigurationLabel", |
| 10 | +}; |
| 11 | + |
| 12 | +describe('trivy-triage', async function() { |
| 13 | + describe('detectDiscussionLabels', async function() { |
| 14 | + it('detect scanner label', async function() { |
| 15 | + const discussion = { |
| 16 | + body: 'hello hello\nbla bla.\n### Scanner\n\nVulnerability\n### Target\n\nContainer Image\nbye bye.', |
| 17 | + category: { |
| 18 | + name: 'Ideas' |
| 19 | + } |
| 20 | + }; |
| 21 | + const labels = detectDiscussionLabels(discussion, configDiscussionLabels); |
| 22 | + assert(labels.includes('VulnerabilityLabel')); |
| 23 | + }); |
| 24 | + it('detect target label', async function() { |
| 25 | + const discussion = { |
| 26 | + body: 'hello hello\nbla bla.\n### Scanner\n\nVulnerability\n### Target\n\nContainer Image\nbye bye.', |
| 27 | + category: { |
| 28 | + name: 'Ideas' |
| 29 | + } |
| 30 | + }; |
| 31 | + const labels = detectDiscussionLabels(discussion, configDiscussionLabels); |
| 32 | + assert(labels.includes('ContainerImageLabel')); |
| 33 | + }); |
| 34 | + it('detect label when it is first', async function() { |
| 35 | + const discussion = { |
| 36 | + body: '### Scanner\n\nVulnerability\n### Target\n\nContainer Image\nbye bye.', |
| 37 | + category: { |
| 38 | + name: 'Ideas' |
| 39 | + } |
| 40 | + }; |
| 41 | + const labels = detectDiscussionLabels(discussion, configDiscussionLabels); |
| 42 | + assert(labels.includes('ContainerImageLabel')); |
| 43 | + }); |
| 44 | + it('detect label when it is last', async function() { |
| 45 | + const discussion = { |
| 46 | + body: '### Scanner\n\nVulnerability\n### Target\n\nContainer Image', |
| 47 | + category: { |
| 48 | + name: 'Ideas' |
| 49 | + } |
| 50 | + }; |
| 51 | + const labels = detectDiscussionLabels(discussion, configDiscussionLabels); |
| 52 | + assert(labels.includes('ContainerImageLabel')); |
| 53 | + }); |
| 54 | + it('detect scanner and target labels', async function() { |
| 55 | + const discussion = { |
| 56 | + body: 'hello hello\nbla bla.\n### Scanner\n\nVulnerability\n### Target\n\nContainer Image\nbye bye.', |
| 57 | + category: { |
| 58 | + name: 'Ideas' |
| 59 | + } |
| 60 | + }; |
| 61 | + const labels = detectDiscussionLabels(discussion, configDiscussionLabels); |
| 62 | + assert(labels.includes('ContainerImageLabel')); |
| 63 | + assert(labels.includes('VulnerabilityLabel')); |
| 64 | + }); |
| 65 | + it('not detect other labels', async function() { |
| 66 | + const discussion = { |
| 67 | + body: 'hello hello\nbla bla.\n### Scanner\n\nVulnerability\n### Target\n\nContainer Image\nbye bye.', |
| 68 | + category: { |
| 69 | + name: 'Ideas' |
| 70 | + } |
| 71 | + }; |
| 72 | + const labels = detectDiscussionLabels(discussion, configDiscussionLabels); |
| 73 | + assert(!labels.includes('FilesystemLabel')); |
| 74 | + assert(!labels.includes('MisconfigurationLabel')); |
| 75 | + }); |
| 76 | + }); |
| 77 | +}); |
0 commit comments