|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +'use strict'; |
| 5 | + |
| 6 | +import { expect } from 'chai'; |
| 7 | +import { parseLine } from '../../client/linters/baseLinter'; |
| 8 | +import { BANDIT_REGEX } from '../../client/linters/bandit'; |
| 9 | + |
| 10 | +import { ILintMessage, LinterId } from '../../client/linters/types'; |
| 11 | + |
| 12 | +suite('Linting - Bandit', () => { |
| 13 | + test('parsing new bandit with col', () => { |
| 14 | + const newOutput = `\ |
| 15 | +1,0,LOW,B404:Consider possible security implications associated with subprocess module. |
| 16 | +19,4,HIGH,B602:subprocess call with shell=True identified, security issue. |
| 17 | +`; |
| 18 | + |
| 19 | + const lines = newOutput.split('\n'); |
| 20 | + const tests: [string, ILintMessage | undefined][] = [ |
| 21 | + [ |
| 22 | + lines[0], |
| 23 | + { |
| 24 | + code: 'B404', |
| 25 | + message: 'Consider possible security implications associated with subprocess module.', |
| 26 | + column: 0, |
| 27 | + line: 1, |
| 28 | + type: 'LOW', |
| 29 | + provider: 'bandit', |
| 30 | + }, |
| 31 | + ], |
| 32 | + [ |
| 33 | + lines[1], |
| 34 | + { |
| 35 | + code: 'B602', |
| 36 | + message: 'subprocess call with shell=True identified, security issue.', |
| 37 | + column: 3, |
| 38 | + line: 19, |
| 39 | + type: 'HIGH', |
| 40 | + provider: 'bandit', |
| 41 | + }, |
| 42 | + ], |
| 43 | + ]; |
| 44 | + for (const [line, expected] of tests) { |
| 45 | + const msg = parseLine(line, BANDIT_REGEX, LinterId.Bandit, 1); |
| 46 | + |
| 47 | + expect(msg).to.deep.equal(expected); |
| 48 | + } |
| 49 | + }); |
| 50 | + test('parsing old bandit with no col', () => { |
| 51 | + const newOutput = `\ |
| 52 | +1,col,LOW,B404:Consider possible security implications associated with subprocess module. |
| 53 | +19,col,HIGH,B602:subprocess call with shell=True identified, security issue. |
| 54 | +`; |
| 55 | + |
| 56 | + const lines = newOutput.split('\n'); |
| 57 | + const tests: [string, ILintMessage | undefined][] = [ |
| 58 | + [ |
| 59 | + lines[0], |
| 60 | + { |
| 61 | + code: 'B404', |
| 62 | + message: 'Consider possible security implications associated with subprocess module.', |
| 63 | + column: 0, |
| 64 | + line: 1, |
| 65 | + type: 'LOW', |
| 66 | + provider: 'bandit', |
| 67 | + }, |
| 68 | + ], |
| 69 | + [ |
| 70 | + lines[1], |
| 71 | + { |
| 72 | + code: 'B602', |
| 73 | + message: 'subprocess call with shell=True identified, security issue.', |
| 74 | + column: 0, |
| 75 | + line: 19, |
| 76 | + type: 'HIGH', |
| 77 | + provider: 'bandit', |
| 78 | + }, |
| 79 | + ], |
| 80 | + ]; |
| 81 | + for (const [line, expected] of tests) { |
| 82 | + const msg = parseLine(line, BANDIT_REGEX, LinterId.Bandit, 1); |
| 83 | + |
| 84 | + expect(msg).to.deep.equal(expected); |
| 85 | + } |
| 86 | + }); |
| 87 | +}); |
0 commit comments