2017-05-05 09:05:53 +00:00
|
|
|
Before:
|
2017-07-26 22:17:46 +00:00
|
|
|
call ale#test#SetDirectory('/testplugin/test/handler')
|
2017-05-05 09:14:46 +00:00
|
|
|
|
2017-07-26 22:17:46 +00:00
|
|
|
runtime ale_linters/ruby/brakeman.vim
|
2017-05-05 09:05:53 +00:00
|
|
|
|
|
|
|
After:
|
2017-07-26 22:17:46 +00:00
|
|
|
call ale#test#RestoreDirectory()
|
|
|
|
call ale#linter#Reset()
|
2017-05-05 09:05:53 +00:00
|
|
|
|
|
|
|
Execute(The brakeman handler should parse JSON correctly):
|
2021-03-20 22:11:22 +00:00
|
|
|
call ale#test#SetFilename('../test-files/ruby/valid_rails_app/app/models/thing.rb')
|
2017-05-05 09:05:53 +00:00
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ [
|
|
|
|
\ {
|
2017-09-13 22:33:13 +00:00
|
|
|
\ 'filename': expand('%:p'),
|
2017-05-05 09:05:53 +00:00
|
|
|
\ 'lnum': 84,
|
|
|
|
\ 'text': 'SQL Injection Possible SQL injection (Medium)',
|
|
|
|
\ 'type': 'W',
|
|
|
|
\ },
|
|
|
|
\ {
|
2017-09-13 22:33:13 +00:00
|
|
|
\ 'filename': expand('%:p'),
|
2017-05-05 09:05:53 +00:00
|
|
|
\ 'lnum': 1,
|
|
|
|
\ 'text': 'Mass Assignment Potentially dangerous attribute available for mass assignment (Weak)',
|
|
|
|
\ 'type': 'W',
|
|
|
|
\ }
|
|
|
|
\ ],
|
|
|
|
\ ale_linters#ruby#brakeman#Handle(bufnr(''), [
|
|
|
|
\ '{',
|
|
|
|
\ '"warnings": [',
|
|
|
|
\ '{',
|
|
|
|
\ '"warning_type": "SQL Injection",',
|
|
|
|
\ '"warning_code": 0,',
|
|
|
|
\ '"fingerprint": "1234",',
|
|
|
|
\ '"check_name": "SQL",',
|
|
|
|
\ '"message": "Possible SQL injection",',
|
2017-12-19 18:23:09 +00:00
|
|
|
\ '"file": "' . substitute(ale#path#Simplify('app/models/thing.rb'), '\\', '\\\\', 'g') . '",',
|
2017-05-05 09:05:53 +00:00
|
|
|
\ '"line": 84,',
|
|
|
|
\ '"link": "http://brakemanscanner.org/docs/warning_types/sql_injection/",',
|
|
|
|
\ '"code": "Thing.connection.execute(params[:data])",',
|
|
|
|
\ '"render_path": null,',
|
|
|
|
\ '"location": {',
|
|
|
|
\ '"type": "method",',
|
|
|
|
\ '"class": "Thing",',
|
|
|
|
\ '"method": "run_raw_sql_from_internet"',
|
|
|
|
\ '},',
|
|
|
|
\ '"user_input": "whatever",',
|
|
|
|
\ '"confidence": "Medium"',
|
|
|
|
\ '},',
|
|
|
|
\ '{',
|
|
|
|
\ '"warning_type": "Mass Assignment",',
|
|
|
|
\ '"warning_code": 60,',
|
|
|
|
\ '"fingerprint": "1235",',
|
|
|
|
\ '"check_name": "ModelAttrAccessible",',
|
|
|
|
\ '"message": "Potentially dangerous attribute available for mass assignment",',
|
2017-12-19 18:23:09 +00:00
|
|
|
\ '"file": "' . substitute(ale#path#Simplify('app/models/thing.rb'), '\\', '\\\\', 'g') . '",',
|
2017-05-05 09:05:53 +00:00
|
|
|
\ '"line": null,',
|
|
|
|
\ '"link": "http://brakemanscanner.org/docs/warning_types/mass_assignment/",',
|
|
|
|
\ '"code": ":name",',
|
|
|
|
\ '"render_path": null,',
|
|
|
|
\ '"location": {',
|
|
|
|
\ '"type": "model",',
|
|
|
|
\ '"model": "Thing"',
|
|
|
|
\ '},',
|
|
|
|
\ '"user_input": null,',
|
|
|
|
\ '"confidence": "Weak"',
|
|
|
|
\ '}',
|
|
|
|
\ ']',
|
|
|
|
\ '}'
|
|
|
|
\ ])
|
2017-07-01 14:18:21 +00:00
|
|
|
|
|
|
|
Execute(The brakeman handler should parse JSON correctly when there is no output from brakeman):
|
|
|
|
AssertEqual
|
|
|
|
\ [],
|
|
|
|
\ ale_linters#ruby#brakeman#Handle(347, [
|
|
|
|
\ ])
|
2017-07-26 22:17:46 +00:00
|
|
|
\
|
|
|
|
Execute(The brakeman handler should handle garbage output):
|
|
|
|
AssertEqual
|
|
|
|
\ [],
|
|
|
|
\ ale_linters#ruby#brakeman#Handle(347, [
|
|
|
|
\ 'No such command in 2.4.1 of ruby',
|
|
|
|
\ ])
|