/ test / handler / test_tfsec_handler.vader
test_tfsec_handler.vader
 1  Before:
 2    runtime ale_linters/terraform/tfsec.vim
 3  
 4  After:
 5    call ale#linter#Reset()
 6  
 7  Execute(The tfsec handler should handle empty output):
 8    AssertEqual
 9    \ [],
10    \ ale_linters#terraform#tfsec#Handle(bufnr(''), ['{"results": null}'])
11  
12  Execute(The tfsec handler should parse results correctly):
13    AssertEqual
14    \ [
15    \   {
16    \     'filename': '/test/main.tf',
17    \     'lnum': 10,
18    \     'end_lnum': 12,
19    \     'text': "IAM policy document uses sensitive action 'iam:PassRole' on wildcarded resource '*'",
20    \     'code': 'aws-iam-no-policy-wildcards',
21    \     'type': 'W',
22    \   },
23    \],
24    \ ale_linters#terraform#tfsec#Handle(bufnr(''), json_encode(
25    \ {
26    \   "results": [
27    \     {
28    \       "rule_id": "AVD-AWS-0057",
29    \       "long_id": "aws-iam-no-policy-wildcards",
30    \       "rule_description": "IAM policy should avoid use of wildcards and instead apply the principle of least privilege",
31    \       "rule_provider": "aws",
32    \       "rule_service": "iam",
33    \       "impact": "Overly permissive policies may grant access to sensitive resources",
34    \       "resolution": "Specify the exact permissions required, and to which resources they should apply instead of using wildcards.",
35    \       "links": [
36    \         "https://aquasecurity.github.io/tfsec/v1.28.0/checks/aws/iam/no-policy-wildcards/",
37    \         "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document"
38    \       ],
39    \       "description": "IAM policy document uses sensitive action 'iam:PassRole' on wildcarded resource '*'",
40    \       "severity": "HIGH",
41    \       "warning": v:false,
42    \       "status": 0,
43    \       "resource": "data.aws_iam_policy_document.default",
44    \       "location": {
45    \          "filename": "/test/main.tf",
46    \          "start_line": 10,
47    \          "end_line": 12
48    \       }
49    \     }
50    \   ]
51    \ }
52    \))