|
| 1 | +Before: |
| 2 | + runtime ale_linters/terraform/trivy.vim |
| 3 | + |
| 4 | +After: |
| 5 | + call ale#linter#Reset() |
| 6 | + |
| 7 | +Execute(The trivy handler should handle empty output): |
| 8 | + AssertEqual |
| 9 | + \ [], |
| 10 | + \ ale_linters#terraform#trivy#Handle(bufnr(''), ['{}']) |
| 11 | + |
| 12 | +Execute(The trivy handler should handle null Results): |
| 13 | + AssertEqual |
| 14 | + \ [], |
| 15 | + \ ale_linters#terraform#trivy#Handle(bufnr(''), ['{"Results": null}']) |
| 16 | + |
| 17 | +Execute(The trivy handler should parse direct findings correctly): |
| 18 | + AssertEqual |
| 19 | + \ [ |
| 20 | + \ { |
| 21 | + \ 'lnum': 3, |
| 22 | + \ 'end_lnum': 6, |
| 23 | + \ 'text': 'Bucket does not have encryption enabled [AVD-AWS-0088]', |
| 24 | + \ 'detail': "AVD-AWS-0088: Bucket does not have encryption enabled\n" |
| 25 | + \ . 'S3 Buckets should be encrypted to protect the data that is stored within them if access is compromised.', |
| 26 | + \ 'code': 'AVD-AWS-0088', |
| 27 | + \ 'type': 'E', |
| 28 | + \ }, |
| 29 | + \ ], |
| 30 | + \ ale_linters#terraform#trivy#Handle(bufnr(''), [json_encode( |
| 31 | + \ { |
| 32 | + \ 'Results': [ |
| 33 | + \ { |
| 34 | + \ 'Target': expand('#' . bufnr('') . ':t'), |
| 35 | + \ 'Misconfigurations': [ |
| 36 | + \ { |
| 37 | + \ 'ID': 'AVD-AWS-0088', |
| 38 | + \ 'Title': 'Bucket does not have encryption enabled', |
| 39 | + \ 'Description': 'S3 Buckets should be encrypted to protect the data that is stored within them if access is compromised.', |
| 40 | + \ 'Severity': 'HIGH', |
| 41 | + \ 'CauseMetadata': { |
| 42 | + \ 'StartLine': 3, |
| 43 | + \ 'EndLine': 6, |
| 44 | + \ }, |
| 45 | + \ }, |
| 46 | + \ ], |
| 47 | + \ }, |
| 48 | + \ ], |
| 49 | + \ } |
| 50 | + \ )]) |
| 51 | + |
| 52 | +Execute(The trivy handler should use Occurrences for module findings): |
| 53 | + AssertEqual |
| 54 | + \ [ |
| 55 | + \ { |
| 56 | + \ 'lnum': 12, |
| 57 | + \ 'end_lnum': 17, |
| 58 | + \ 'text': 'S3 Bucket Logging [AWS-0089]', |
| 59 | + \ 'detail': "AWS-0089: S3 Bucket Logging\n" |
| 60 | + \ . 'Ensures S3 bucket logging is enabled for S3 buckets', |
| 61 | + \ 'code': 'AWS-0089', |
| 62 | + \ 'type': 'I', |
| 63 | + \ }, |
| 64 | + \ ], |
| 65 | + \ ale_linters#terraform#trivy#Handle(bufnr(''), [json_encode( |
| 66 | + \ { |
| 67 | + \ 'Results': [ |
| 68 | + \ { |
| 69 | + \ 'Target': 'git::ssh:/git@github.com/example/terraform-module?ref=v1.0.0/main.tf', |
| 70 | + \ 'Misconfigurations': [ |
| 71 | + \ { |
| 72 | + \ 'ID': 'AWS-0089', |
| 73 | + \ 'Title': 'S3 Bucket Logging', |
| 74 | + \ 'Description': 'Ensures S3 bucket logging is enabled for S3 buckets', |
| 75 | + \ 'Severity': 'LOW', |
| 76 | + \ 'CauseMetadata': { |
| 77 | + \ 'StartLine': 24, |
| 78 | + \ 'EndLine': 33, |
| 79 | + \ 'Occurrences': [ |
| 80 | + \ { |
| 81 | + \ 'Filename': expand('#' . bufnr('') . ':t'), |
| 82 | + \ 'Location': { |
| 83 | + \ 'StartLine': 12, |
| 84 | + \ 'EndLine': 17, |
| 85 | + \ }, |
| 86 | + \ }, |
| 87 | + \ ], |
| 88 | + \ }, |
| 89 | + \ }, |
| 90 | + \ ], |
| 91 | + \ }, |
| 92 | + \ ], |
| 93 | + \ } |
| 94 | + \ )]) |
| 95 | + |
| 96 | +Execute(The trivy handler should skip module findings with no matching Occurrences): |
| 97 | + AssertEqual |
| 98 | + \ [], |
| 99 | + \ ale_linters#terraform#trivy#Handle(bufnr(''), [json_encode( |
| 100 | + \ { |
| 101 | + \ 'Results': [ |
| 102 | + \ { |
| 103 | + \ 'Target': 'git::ssh:/git@github.com/example/terraform-module?ref=v1.0.0/main.tf', |
| 104 | + \ 'Misconfigurations': [ |
| 105 | + \ { |
| 106 | + \ 'ID': 'AWS-0089', |
| 107 | + \ 'Title': 'S3 Bucket Logging', |
| 108 | + \ 'Description': 'Ensures S3 bucket logging is enabled', |
| 109 | + \ 'Severity': 'LOW', |
| 110 | + \ 'CauseMetadata': { |
| 111 | + \ 'StartLine': 24, |
| 112 | + \ 'EndLine': 33, |
| 113 | + \ 'Occurrences': [ |
| 114 | + \ { |
| 115 | + \ 'Filename': 'other.tf', |
| 116 | + \ 'Location': { |
| 117 | + \ 'StartLine': 5, |
| 118 | + \ 'EndLine': 10, |
| 119 | + \ }, |
| 120 | + \ }, |
| 121 | + \ ], |
| 122 | + \ }, |
| 123 | + \ }, |
| 124 | + \ ], |
| 125 | + \ }, |
| 126 | + \ ], |
| 127 | + \ } |
| 128 | + \ )]) |
| 129 | + |
| 130 | +Execute(The trivy handler should map severity levels correctly): |
| 131 | + let g:result = ale_linters#terraform#trivy#Handle(bufnr(''), [json_encode( |
| 132 | + \ { |
| 133 | + \ 'Results': [ |
| 134 | + \ { |
| 135 | + \ 'Target': expand('#' . bufnr('') . ':t'), |
| 136 | + \ 'Misconfigurations': [ |
| 137 | + \ { |
| 138 | + \ 'ID': 'AVD-001', |
| 139 | + \ 'Title': 'Low issue', |
| 140 | + \ 'Description': 'Low', |
| 141 | + \ 'Severity': 'LOW', |
| 142 | + \ 'CauseMetadata': {'StartLine': 1, 'EndLine': 1}, |
| 143 | + \ }, |
| 144 | + \ { |
| 145 | + \ 'ID': 'AVD-002', |
| 146 | + \ 'Title': 'Medium issue', |
| 147 | + \ 'Description': 'Medium', |
| 148 | + \ 'Severity': 'MEDIUM', |
| 149 | + \ 'CauseMetadata': {'StartLine': 2, 'EndLine': 2}, |
| 150 | + \ }, |
| 151 | + \ { |
| 152 | + \ 'ID': 'AVD-003', |
| 153 | + \ 'Title': 'High issue', |
| 154 | + \ 'Description': 'High', |
| 155 | + \ 'Severity': 'HIGH', |
| 156 | + \ 'CauseMetadata': {'StartLine': 3, 'EndLine': 3}, |
| 157 | + \ }, |
| 158 | + \ { |
| 159 | + \ 'ID': 'AVD-004', |
| 160 | + \ 'Title': 'Critical issue', |
| 161 | + \ 'Description': 'Critical', |
| 162 | + \ 'Severity': 'CRITICAL', |
| 163 | + \ 'CauseMetadata': {'StartLine': 4, 'EndLine': 4}, |
| 164 | + \ }, |
| 165 | + \ ], |
| 166 | + \ }, |
| 167 | + \ ], |
| 168 | + \ } |
| 169 | + \ )]) |
| 170 | + |
| 171 | + AssertEqual 'I', g:result[0].type |
| 172 | + AssertEqual 'W', g:result[1].type |
| 173 | + AssertEqual 'E', g:result[2].type |
| 174 | + AssertEqual 'E', g:result[3].type |
0 commit comments