Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add-unit-tests #492

Merged
merged 8 commits into from
Jun 24, 2024
Merged

Feature/add-unit-tests #492

merged 8 commits into from
Jun 24, 2024

Conversation

richgreen-moj
Copy link
Contributor

@richgreen-moj richgreen-moj commented Jun 21, 2024

Issue

ministryofjustice/modernisation-platform#6490 Add unit tests where missing

What's changed

I've added unit tests for the backup module within the baselines module and a GH actions workflow file to run them.

As the baselines module is made up of a series of other modules, some of which have constraints that mean they won't be possible to unit test easily (e.g. IAM access analyser can only be built once per region) I decided to specifically target the backup child module with it's own dedicated backup-test directory but have kept a single baselines_test.go file that we can add to if there are any more child modules that can be tested.

Testing

I tested it locally and now via GH Actions as shown in the status checks below.

I've also added a draft PR ministryofjustice/modernisation-platform#7315 to update the baselines module to use this revision and it reports no changes on a terraform plan: https://github.com/ministryofjustice/modernisation-platform/actions/runs/9645571244/job/26600097925?pr=7315#step:7:318

This is to be expected as I've created variables and set the default values to the original names used for the various resources. The only change will be on apply where some extra outputs will be generated.

Future action

This just tests the backup module, in future we can add more tests for the others where possible. I will write some stories for ones which should be possible.

@richgreen-moj richgreen-moj requested a review from a team as a code owner June 21, 2024 12:00
Copy link
Contributor

Trivy Scan Success

Show Output ```hcl

Trivy will check the following folders:
modules/backup test/backup-test


Running Trivy in modules/backup
2024-06-21T12:02:56Z INFO Need to update DB
2024-06-21T12:02:56Z INFO Downloading DB... repository="ghcr.io/aquasecurity/trivy-db:2"
2024-06-21T12:02:58Z INFO Vulnerability scanning is enabled
2024-06-21T12:02:58Z INFO Misconfiguration scanning is enabled
2024-06-21T12:02:58Z INFO Need to update the built-in policies
2024-06-21T12:02:58Z INFO Downloading the built-in policies...
53.79 KiB / 53.79 KiB [-----------------------------------------------------------] 100.00% ? p/s 0s2024-06-21T12:02:59Z INFO Secret scanning is enabled
2024-06-21T12:02:59Z INFO If your scanning is slow, please try '--scanners vuln' to disable secret scanning
2024-06-21T12:02:59Z INFO Please see also https://aquasecurity.github.io/trivy/v0.52/docs/scanner/secret/#recommendation for faster secret detection
2024-06-21T12:02:59Z INFO Number of language-specific files num=0
2024-06-21T12:02:59Z INFO Detected config files num=2
trivy_exitcode=0


Running Trivy in test/backup-test
2024-06-21T12:02:59Z INFO Vulnerability scanning is enabled
2024-06-21T12:02:59Z INFO Misconfiguration scanning is enabled
2024-06-21T12:02:59Z INFO Secret scanning is enabled
2024-06-21T12:02:59Z INFO If your scanning is slow, please try '--scanners vuln' to disable secret scanning
2024-06-21T12:02:59Z INFO Please see also https://aquasecurity.github.io/trivy/v0.52/docs/scanner/secret/#recommendation for faster secret detection
2024-06-21T12:03:00Z INFO Number of language-specific files num=0
2024-06-21T12:03:00Z INFO Detected config files num=2
trivy_exitcode=0

</details> #### `Checkov Scan` Success
<details><summary>Show Output</summary>

```hcl

*****************************

Checkov will check the following folders:
modules/backup test/backup-test

*****************************

Running Checkov in modules/backup
Excluding the following checks: CKV_GIT_1,CKV_AWS_126,CKV2_AWS_38,CKV2_AWS_39
terraform scan results:

Passed checks: 1, Failed checks: 0, Skipped checks: 1


checkov_exitcode=0

*****************************

Running Checkov in test/backup-test
Excluding the following checks: CKV_GIT_1,CKV_AWS_126,CKV2_AWS_38,CKV2_AWS_39
terraform scan results:

Passed checks: 22, Failed checks: 0, Skipped checks: 1


checkov_exitcode=0

CTFLint Scan Success

Show Output
*****************************

Setting default tflint config...
Running tflint --init...
Installing "terraform" plugin...
Installed "terraform" (source: github.com/terraform-linters/tflint-ruleset-terraform, version: 0.5.0)
tflint will check the following folders:
modules/backup test/backup-test

*****************************

Running tflint in modules/backup
Excluding the following checks: terraform_unused_declarations
tflint_exitcode=0

*****************************

Running tflint in test/backup-test
Excluding the following checks: terraform_unused_declarations
tflint_exitcode=0

Trivy Scan Success

Show Output
*****************************

Trivy will check the following folders:
modules/backup test/backup-test

*****************************

Running Trivy in modules/backup
2024-06-21T12:02:56Z	INFO	Need to update DB
2024-06-21T12:02:56Z	INFO	Downloading DB...	repository="ghcr.io/aquasecurity/trivy-db:2"
2024-06-21T12:02:58Z	INFO	Vulnerability scanning is enabled
2024-06-21T12:02:58Z	INFO	Misconfiguration scanning is enabled
2024-06-21T12:02:58Z	INFO	Need to update the built-in policies
2024-06-21T12:02:58Z	INFO	Downloading the built-in policies...
53.79 KiB / 53.79 KiB [-----------------------------------------------------------] 100.00% ? p/s 0s2024-06-21T12:02:59Z	INFO	Secret scanning is enabled
2024-06-21T12:02:59Z	INFO	If your scanning is slow, please try '--scanners vuln' to disable secret scanning
2024-06-21T12:02:59Z	INFO	Please see also https://aquasecurity.github.io/trivy/v0.52/docs/scanner/secret/#recommendation for faster secret detection
2024-06-21T12:02:59Z	INFO	Number of language-specific files	num=0
2024-06-21T12:02:59Z	INFO	Detected config files	num=2
trivy_exitcode=0

*****************************

Running Trivy in test/backup-test
2024-06-21T12:02:59Z	INFO	Vulnerability scanning is enabled
2024-06-21T12:02:59Z	INFO	Misconfiguration scanning is enabled
2024-06-21T12:02:59Z	INFO	Secret scanning is enabled
2024-06-21T12:02:59Z	INFO	If your scanning is slow, please try '--scanners vuln' to disable secret scanning
2024-06-21T12:02:59Z	INFO	Please see also https://aquasecurity.github.io/trivy/v0.52/docs/scanner/secret/#recommendation for faster secret detection
2024-06-21T12:03:00Z	INFO	Number of language-specific files	num=0
2024-06-21T12:03:00Z	INFO	Detected config files	num=2
trivy_exitcode=0

Copy link
Contributor

Trivy Scan Success

Show Output ```hcl

Trivy will check the following folders:
modules/backup test/backup-test


Running Trivy in modules/backup
2024-06-21T12:03:57Z INFO Need to update DB
2024-06-21T12:03:57Z INFO Downloading DB... repository="ghcr.io/aquasecurity/trivy-db:2"
2024-06-21T12:04:00Z INFO Vulnerability scanning is enabled
2024-06-21T12:04:00Z INFO Misconfiguration scanning is enabled
2024-06-21T12:04:00Z INFO Need to update the built-in policies
2024-06-21T12:04:00Z INFO Downloading the built-in policies...
53.79 KiB / 53.79 KiB [-----------------------------------------------------------] 100.00% ? p/s 0s2024-06-21T12:04:00Z INFO Secret scanning is enabled
2024-06-21T12:04:00Z INFO If your scanning is slow, please try '--scanners vuln' to disable secret scanning
2024-06-21T12:04:00Z INFO Please see also https://aquasecurity.github.io/trivy/v0.52/docs/scanner/secret/#recommendation for faster secret detection
2024-06-21T12:04:00Z INFO Number of language-specific files num=0
2024-06-21T12:04:00Z INFO Detected config files num=2
trivy_exitcode=0


Running Trivy in test/backup-test
2024-06-21T12:04:01Z INFO Vulnerability scanning is enabled
2024-06-21T12:04:01Z INFO Misconfiguration scanning is enabled
2024-06-21T12:04:01Z INFO Secret scanning is enabled
2024-06-21T12:04:01Z INFO If your scanning is slow, please try '--scanners vuln' to disable secret scanning
2024-06-21T12:04:01Z INFO Please see also https://aquasecurity.github.io/trivy/v0.52/docs/scanner/secret/#recommendation for faster secret detection
2024-06-21T12:04:01Z INFO Number of language-specific files num=0
2024-06-21T12:04:01Z INFO Detected config files num=2
trivy_exitcode=0

</details> #### `Checkov Scan` Success
<details><summary>Show Output</summary>

```hcl

*****************************

Checkov will check the following folders:
modules/backup test/backup-test

*****************************

Running Checkov in modules/backup
Excluding the following checks: CKV_GIT_1,CKV_AWS_126,CKV2_AWS_38,CKV2_AWS_39
terraform scan results:

Passed checks: 1, Failed checks: 0, Skipped checks: 1


checkov_exitcode=0

*****************************

Running Checkov in test/backup-test
Excluding the following checks: CKV_GIT_1,CKV_AWS_126,CKV2_AWS_38,CKV2_AWS_39
terraform scan results:

Passed checks: 22, Failed checks: 0, Skipped checks: 1


checkov_exitcode=0

CTFLint Scan Success

Show Output
*****************************

Setting default tflint config...
Running tflint --init...
Installing "terraform" plugin...
Installed "terraform" (source: github.com/terraform-linters/tflint-ruleset-terraform, version: 0.5.0)
tflint will check the following folders:
modules/backup test/backup-test

*****************************

Running tflint in modules/backup
Excluding the following checks: terraform_unused_declarations
tflint_exitcode=0

*****************************

Running tflint in test/backup-test
Excluding the following checks: terraform_unused_declarations
tflint_exitcode=0

Trivy Scan Success

Show Output
*****************************

Trivy will check the following folders:
modules/backup test/backup-test

*****************************

Running Trivy in modules/backup
2024-06-21T12:03:57Z	INFO	Need to update DB
2024-06-21T12:03:57Z	INFO	Downloading DB...	repository="ghcr.io/aquasecurity/trivy-db:2"
2024-06-21T12:04:00Z	INFO	Vulnerability scanning is enabled
2024-06-21T12:04:00Z	INFO	Misconfiguration scanning is enabled
2024-06-21T12:04:00Z	INFO	Need to update the built-in policies
2024-06-21T12:04:00Z	INFO	Downloading the built-in policies...
53.79 KiB / 53.79 KiB [-----------------------------------------------------------] 100.00% ? p/s 0s2024-06-21T12:04:00Z	INFO	Secret scanning is enabled
2024-06-21T12:04:00Z	INFO	If your scanning is slow, please try '--scanners vuln' to disable secret scanning
2024-06-21T12:04:00Z	INFO	Please see also https://aquasecurity.github.io/trivy/v0.52/docs/scanner/secret/#recommendation for faster secret detection
2024-06-21T12:04:00Z	INFO	Number of language-specific files	num=0
2024-06-21T12:04:00Z	INFO	Detected config files	num=2
trivy_exitcode=0

*****************************

Running Trivy in test/backup-test
2024-06-21T12:04:01Z	INFO	Vulnerability scanning is enabled
2024-06-21T12:04:01Z	INFO	Misconfiguration scanning is enabled
2024-06-21T12:04:01Z	INFO	Secret scanning is enabled
2024-06-21T12:04:01Z	INFO	If your scanning is slow, please try '--scanners vuln' to disable secret scanning
2024-06-21T12:04:01Z	INFO	Please see also https://aquasecurity.github.io/trivy/v0.52/docs/scanner/secret/#recommendation for faster secret detection
2024-06-21T12:04:01Z	INFO	Number of language-specific files	num=0
2024-06-21T12:04:01Z	INFO	Detected config files	num=2
trivy_exitcode=0

@richgreen-moj richgreen-moj merged commit 957a6ca into main Jun 24, 2024
8 checks passed
@richgreen-moj richgreen-moj deleted the feature/add-unit-tests branch June 24, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants