3838
3939@pytest .fixture (scope = "session" , autouse = True )
4040def setup_environment ():
41- """Fixture to ensure a clean environment by removing test modules before running tests."""
41+ """
42+ Fixture to ensure a clean environment by removing test modules before running tests.
43+
44+ This fixture lists all SHA custom modules in the organization and deletes any
45+ that were created by previous test runs, identified by the PREFIX.
46+ """
4247 if not ORGANIZATION_ID :
4348 pytest .fail ("GCLOUD_ORGANIZATION environment variable is not set." )
4449
@@ -73,7 +78,13 @@ def cleanup_existing_custom_modules(org_id: str):
7378
7479
7580def add_custom_module (org_id : str ):
76-
81+ """
82+ Adds a new SHA custom module.
83+ Args:
84+ org_id (str): The organization ID.
85+ Returns:
86+ Tuple[str, str]: The name and ID of the created custom module.
87+ """
7788 parent = f"organizations/{ org_id } /locations/global"
7889 client = securitycentermanagement_v1 .SecurityCenterManagementClient ()
7990
@@ -86,24 +97,24 @@ def add_custom_module(org_id: str):
8697 "display_name" : display_name ,
8798 "enablement_state" : "ENABLED" ,
8899 "custom_config" : {
89- "description" : "Sample custom module for testing purpose . Please do not delete." ,
100+ "description" : "Sample custom module for testing purposes . Please do not delete." ,
90101 "predicate" : {
91102 "expression" : "has(resource.rotationPeriod) && (resource.rotationPeriod > duration('2592000s'))" ,
92- "title" : "GCE Instance High Severity " ,
93- "description" : "Custom module to detect high severity issues on GCE instances ." ,
103+ "title" : "Cloud KMS CryptoKey Rotation Period " ,
104+ "description" : "Custom module to detect CryptoKeys with rotation period greater than 30 days ." ,
94105 },
95- "recommendation" : "Ensure proper security configurations on GCE instances ." ,
106+ "recommendation" : "Review and adjust the rotation period for Cloud KMS CryptoKeys ." ,
96107 "resource_selector" : {"resource_types" : ["cloudkms.googleapis.com/CryptoKey" ]},
97108 "severity" : "CRITICAL" ,
98109 "custom_output" : {
99110 "properties" : [
100111 {
101112 "name" : "example_property" ,
102113 "value_expression" : {
103- "description" : "The name of the instance " ,
114+ "description" : "The resource name of the CryptoKey " ,
104115 "expression" : "resource.name" ,
105116 "location" : "global" ,
106- "title" : "Instance Name" ,
117+ "title" : "CryptoKey Resource Name" ,
107118 },
108119 }
109120 ]
@@ -126,7 +137,7 @@ def add_custom_module(org_id: str):
126137 backoff .expo , (InternalServerError , ServiceUnavailable , NotFound ), max_tries = 3
127138)
128139def test_get_effective_security_health_analytics_custom_module ():
129-
140+ """Tests getting an effective SHA custom module."""
130141 module_name , module_id = add_custom_module (ORGANIZATION_ID )
131142 parent = f"organizations/{ ORGANIZATION_ID } /locations/{ LOCATION } "
132143
@@ -144,7 +155,7 @@ def test_get_effective_security_health_analytics_custom_module():
144155 backoff .expo , (InternalServerError , ServiceUnavailable , NotFound ), max_tries = 3
145156)
146157def test_list_descendant_security_health_analytics_custom_module ():
147-
158+ """Tests listing descendant SHA custom modules."""
148159 module_name , module_id = add_custom_module (ORGANIZATION_ID )
149160 parent = f"organizations/{ ORGANIZATION_ID } /locations/{ LOCATION } "
150161 # Retrieve the list descendant custom modules
@@ -169,7 +180,7 @@ def test_list_descendant_security_health_analytics_custom_module():
169180 backoff .expo , (InternalServerError , ServiceUnavailable , NotFound ), max_tries = 3
170181)
171182def test_list_effective_security_health_analytics_custom_module ():
172-
183+ """Tests listing effective SHA custom modules."""
173184 module_name , module_id = add_custom_module (ORGANIZATION_ID )
174185 parent = f"organizations/{ ORGANIZATION_ID } /locations/{ LOCATION } "
175186 # Retrieve the list of custom modules
@@ -194,7 +205,7 @@ def test_list_effective_security_health_analytics_custom_module():
194205 backoff .expo , (InternalServerError , ServiceUnavailable , NotFound ), max_tries = 3
195206)
196207def test_simulate_security_health_analytics_custom_module ():
197-
208+ """Tests simulating an SHA custom module."""
198209 module_name , module_id = add_custom_module (ORGANIZATION_ID )
199210 parent = f"organizations/{ ORGANIZATION_ID } /locations/{ LOCATION } "
200211
0 commit comments