|
| 1 | +const Glob = require('../../../lib/glob') |
| 2 | + |
| 3 | +describe('glob test', function () { |
| 4 | + |
| 5 | + test('Test Glob **', () => { |
| 6 | + let pattern = new Glob('**/xss') |
| 7 | + let str = 'test/web/xss' |
| 8 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 9 | + str = 'test/web/xsssss' |
| 10 | + expect(str.search(pattern)>=0).toBeFalsy() |
| 11 | + |
| 12 | + pattern = new Glob('**/*.txt') |
| 13 | + str = 'sub/3.txt' |
| 14 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 15 | + str = '/sub1/sub2/sub3/3.txt' |
| 16 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 17 | + |
| 18 | + pattern = new Glob('**/csrf-protection-disabled') |
| 19 | + str = 'java/csrf-protection-disabled' |
| 20 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 21 | + str = '/java/test/csrf-protection-disabled' |
| 22 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 23 | + }) |
| 24 | + |
| 25 | + test('Test Glob *', () => { |
| 26 | + let str = 'web/xss' |
| 27 | + let pattern = new Glob('*/xss') |
| 28 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 29 | + |
| 30 | + pattern = new Glob('./[0-9].*') |
| 31 | + str = './1.gif' |
| 32 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 33 | + str = './2.gif' |
| 34 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 35 | + str = './2.' |
| 36 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 37 | + |
| 38 | + pattern = new Glob('*/csrf-protection-disabled') |
| 39 | + str = 'java/csrf-protection-disabled' |
| 40 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 41 | + str = 'rb/csrf-protection-disabled' |
| 42 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 43 | + |
| 44 | + pattern = new Glob('*/hardcoded-credential*') |
| 45 | + str = 'java/csrf-protection-disabled' |
| 46 | + expect(str.search(pattern)>=0).toBeFalsy() |
| 47 | + str = 'rb/csrf-protection-disabled' |
| 48 | + expect(str.search(pattern)>=0).toBeFalsy() |
| 49 | + str = 'cs/hardcoded-credentials' |
| 50 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 51 | + str = 'java/hardcoded-credential-api-call' |
| 52 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 53 | + |
| 54 | + }) |
| 55 | + |
| 56 | + test('Test Glob no *', () => { |
| 57 | + let pattern = new Glob('csrf-protection-disabled') |
| 58 | + let str = 'java/hardcoded-credential-api-call' |
| 59 | + expect(str.search(pattern)>=0).toBeFalsy() |
| 60 | + str = 'cs/test/hardcoded-credentials' |
| 61 | + expect(str.search(pattern)>=0).toBeFalsy() |
| 62 | + str = 'rb/csrf-protection-disabled' |
| 63 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 64 | + str = 'java/csrf-protection-disabled' |
| 65 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 66 | + |
| 67 | + pattern = new Glob('csrf') |
| 68 | + str = 'java/hardcoded-credential-api-call' |
| 69 | + expect(str.search(pattern)>=0).toBeFalsy() |
| 70 | + str = 'cs/test/hardcoded-credentials' |
| 71 | + expect(str.search(pattern)>=0).toBeFalsy() |
| 72 | + str = 'rb/csrf-protection-disabled' |
| 73 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 74 | + str = 'java/csrf-protection-disabled' |
| 75 | + expect(str.search(pattern)>=0).toBeTruthy() |
| 76 | + }) |
| 77 | + |
| 78 | +}) |
0 commit comments