-
Notifications
You must be signed in to change notification settings - Fork 2
🧹 add createException api, deleteException api, add test #285
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
Changes from all commits
ed54cbc
c2979aa
65231d6
726d46d
43e0434
9d483a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package provider | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func TestExceptionResource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
// Create and Read testing | ||
{ | ||
Config: testCreateException(accSpace.ID(), accSpace.MRN(), "RISK_ACCEPTED"), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("mondoo_exception.windows_defender_exception", "action", "RISK_ACCEPTED"), | ||
), | ||
}, | ||
// Update testing | ||
{ | ||
Config: testCreateException(accSpace.ID(), accSpace.MRN(), "FALSE_POSITIVE"), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("mondoo_exception.windows_defender_exception", "action", "FALSE_POSITIVE"), | ||
), | ||
}, | ||
// // import testing | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leftover ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is, but i want to try to get it working in the future. we should have the imports tested. this one is being real tricky on me so i was hoping to address the test itself in a followup |
||
// { | ||
// Config: importException(accSpace.ID()), | ||
// ResourceName: "mondoo_exception.windows_defender_exception", | ||
// ImportStateIdFunc: func(s *terraform.State) (string, error) { | ||
// return s.RootModule().Resources["mondoo_exception.windows_defender_exception"].Primary.Attributes["exception_id"], nil | ||
// }, | ||
|
||
// ImportStateVerifyIdentifierAttribute: "exception_id", | ||
// ImportState: true, | ||
// ImportStateVerify: true, | ||
// }, | ||
}, | ||
}) | ||
} | ||
|
||
// func importException(spaceId string) string { | ||
vjeffrey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// return fmt.Sprintf(` | ||
// provider "mondoo" { | ||
// space = "%s" | ||
// } | ||
// resource "mondoo_exception" "windows_defender_exception" { | ||
// } | ||
// `, spaceId) | ||
// } | ||
|
||
func testCreateException(spaceId string, spaceMrn string, action string) string { | ||
return fmt.Sprintf(` | ||
resource "mondoo_policy_assignment" "cis_policy_assignment_enabled" { | ||
space_id = "%s" | ||
policies = [ | ||
"//policy.api.mondoo.app/policies/cis-microsoft-windows-10-l1-ce", | ||
"//policy.api.mondoo.app/policies/cis-microsoft-windows-10-l1-bl", | ||
"//policy.api.mondoo.app/policies/cis-microsoft-windows-11-l1-ce", | ||
"//policy.api.mondoo.app/policies/cis-microsoft-windows-11-l1-bl", | ||
"//policy.api.mondoo.app/policies/cis-microsoft-windows-server-2016-dc-level-1", | ||
"//policy.api.mondoo.app/policies/cis-microsoft-windows-server-2016-ms-level-1", | ||
"//policy.api.mondoo.app/policies/cis-microsoft-windows-server-2019-dc-level-1", | ||
"//policy.api.mondoo.app/policies/cis-microsoft-windows-server-2019-ms-level-1", | ||
"//policy.api.mondoo.app/policies/cis-microsoft-windows-server-2022-dc-level-1", | ||
"//policy.api.mondoo.app/policies/cis-microsoft-windows-server-2022-ms-level-1", | ||
"//policy.api.mondoo.app/policies/cis-microsoft-azure-windows-server-2019-dc-level-1", | ||
"//policy.api.mondoo.app/policies/cis-microsoft-azure-windows-server-2019-ms-level-1", | ||
"//policy.api.mondoo.app/policies/cis-microsoft-azure-windows-server-2022-dc-level-1", | ||
"//policy.api.mondoo.app/policies/cis-microsoft-azure-windows-server-2022-ms-level-1", | ||
"//policy.api.mondoo.app/policies/mondoo-edr-policy", | ||
] | ||
state = "enabled" | ||
} | ||
# Set exceptions for Windows policies in the space | ||
resource "mondoo_exception" "windows_defender_exception" { | ||
justification = "Windows Defender is disabled. Other EDR is used/configured instead." | ||
scope_mrn = "%s" | ||
action = "%s" | ||
valid_until = "2025-09-09" | ||
check_mrns = [ | ||
"//policy.api.mondoo.app/queries/cis-microsoft-windows-10--18.10.42.5.1", | ||
"//policy.api.mondoo.app/queries/cis-microsoft-windows-11--18.10.42.5.1", | ||
"//policy.api.mondoo.app/queries/cis-microsoft-windows-server-2016--18.10.42.5.1", | ||
"//policy.api.mondoo.app/queries/cis-microsoft-windows-server-2019--18.10.42.5.1", | ||
"//policy.api.mondoo.app/queries/cis-microsoft-windows-server-2022--18.10.42.5.1", | ||
] | ||
depends_on = [ | ||
mondoo_policy_assignment.cis_policy_assignment_enabled | ||
] | ||
} | ||
`, spaceId, spaceMrn, action) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens to existing state files where this doesnt exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm. good question. ill check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good call, i tested and that then would fail to delete the exception on update.
im implementing a change that will searchf or the exception if we dont have the exception id. if we search for it and find it, great.
if not, then my thought was we return an error to the user and then allow them to import the exception resource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. i tested this all out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
working on import resource now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import resource should be working now as well