@@ -29,27 +29,6 @@ const customModuleDisplayName = `node_sample_etd_custom_module_test_${uuid()}`;
29
29
// Creates a new client.
30
30
const client = new SecurityCenterManagementClient ( ) ;
31
31
32
- // cleanupExistingCustomModules clean up all the existing custom module
33
- async function cleanupExistingCustomModules ( ) {
34
- const [ modules ] = await client . listEventThreatDetectionCustomModules ( {
35
- parent : `organizations/${ organizationId } /locations/${ location } ` ,
36
- } ) ;
37
- // Iterate over the modules response and delete custom module one by one which start with
38
- // node_sample_etd_custom_module
39
- for ( const module of modules ) {
40
- try {
41
- if ( module . displayName . startsWith ( 'node_sample_etd_custom_module' ) ) {
42
- console . log ( 'Deleting custom module: ' , module . name ) ;
43
- // extracts the custom module ID from the full name
44
- const customModuleId = module . name . split ( '/' ) [ 5 ] ;
45
- await deleteCustomModule ( customModuleId ) ;
46
- }
47
- } catch ( error ) {
48
- console . error ( 'Error deleting EventThreatDetectionCustomModule:' , error ) ;
49
- }
50
- }
51
- }
52
-
53
32
// deleteCustomModule method is for deleting the custom module
54
33
async function deleteCustomModule ( customModuleId ) {
55
34
const name = `organizations/${ organizationId } /locations/${ location } /eventThreatDetectionCustomModules/${ customModuleId } ` ;
@@ -63,6 +42,7 @@ async function deleteCustomModule(customModuleId) {
63
42
64
43
describe ( 'Event Threat Detection Custom module' , async ( ) => {
65
44
let data ;
45
+ const createdCustomModuleIds = [ ] ;
66
46
before ( async ( ) => {
67
47
const parent = `organizations/${ organizationId } /locations/${ location } ` ;
68
48
@@ -120,8 +100,21 @@ describe('Event Threat Detection Custom module', async () => {
120
100
} ) ;
121
101
122
102
after ( async ( ) => {
123
- // Perform cleanup after running tests
124
- await cleanupExistingCustomModules ( ) ;
103
+ // Perform cleanup of the custom modules created by the current execution of the test, after
104
+ // running tests
105
+ if ( createdCustomModuleIds . length > 0 ) {
106
+ for ( const customModuleId of createdCustomModuleIds ) {
107
+ try {
108
+ console . log ( 'Deleting custom module: ' , customModuleId ) ;
109
+ await deleteCustomModule ( customModuleId ) ;
110
+ } catch ( error ) {
111
+ console . error (
112
+ 'Error deleting EventThreatDetectionCustomModule:' ,
113
+ error
114
+ ) ;
115
+ }
116
+ }
117
+ }
125
118
} ) ;
126
119
127
120
it ( 'should get the event threat detection custom module' , done => {
@@ -160,13 +153,57 @@ describe('Event Threat Detection Custom module', async () => {
160
153
const output = exec (
161
154
`node management_api/createEventThreatDetectionCustomModule.js ${ data . orgId } ${ data . customModuleName } `
162
155
) ;
156
+ // pushing the created custom module Id to an array for cleanup after running test
157
+ const jsonPart = output . substring ( output . indexOf ( '{' ) ) . trim ( ) ;
158
+ const parsedOutput = JSON . parse ( jsonPart ) ;
159
+ createdCustomModuleIds . push ( parsedOutput . name . split ( '/' ) [ 5 ] ) ;
163
160
assert ( output . includes ( data . orgId ) ) ;
164
161
assert ( output . includes ( data . customModuleName ) ) ;
165
162
assert . match ( output , / E v e n t T h r e a t D e t e c t i o n C u s t o m M o d u l e c r e a t e d / ) ;
166
163
assert . notMatch ( output , / u n d e f i n e d / ) ;
167
164
done ( ) ;
168
165
} ) ;
169
166
167
+ it ( 'should get the effective event threat detection custom module' , done => {
168
+ const output = exec (
169
+ `node management_api/getEffectiveEventThreatDetectionCustomModule.js ${ data . orgId } ${ data . customModuleId } `
170
+ ) ;
171
+ assert ( output . includes ( data . orgId ) ) ;
172
+ assert ( output . includes ( data . customModuleId ) ) ;
173
+ assert . match ( output , / R e t r i e v e d E f f e c t i v e E v e n t T h r e a t D e t e c t i o n C u s t o m M o d u l e / ) ;
174
+ assert . notMatch ( output , / u n d e f i n e d / ) ;
175
+ done ( ) ;
176
+ } ) ;
177
+
178
+ it ( 'should list all the effective event threat detection custom module' , done => {
179
+ const output = exec (
180
+ `node management_api/listEffectiveEventThreatDetectionCustomModules.js ${ data . orgId } `
181
+ ) ;
182
+ assert ( output . includes ( data . orgId ) ) ;
183
+ assert ( output . includes ( data . customModuleId ) ) ;
184
+ assert . notMatch ( output , / u n d e f i n e d / ) ;
185
+ done ( ) ;
186
+ } ) ;
187
+
188
+ it ( 'should list all the descendant event threat detection custom module' , done => {
189
+ const output = exec (
190
+ `node management_api/listDescendantEventThreatDetectionCustomModules.js ${ data . orgId } `
191
+ ) ;
192
+ assert ( output . includes ( data . orgId ) ) ;
193
+ assert ( output . includes ( data . customModuleId ) ) ;
194
+ assert . notMatch ( output , / u n d e f i n e d / ) ;
195
+ done ( ) ;
196
+ } ) ;
197
+
198
+ it ( 'should validate the event threat detection custom module' , done => {
199
+ const output = exec (
200
+ `node management_api/validateEventThreatDetectionCustomModule.js ${ data . orgId } `
201
+ ) ;
202
+ assert . match ( output , / V a l i d a t i o n s u c c e s s f u l : N o e r r o r s f o u n d ./ ) ;
203
+ assert . notMatch ( output , / u n d e f i n e d / ) ;
204
+ done ( ) ;
205
+ } ) ;
206
+
170
207
it ( 'should delete the event threat detection custom module' , done => {
171
208
const output = exec (
172
209
`node management_api/deleteEventThreatDetectionCustomModule.js ${ data . orgId } ${ data . customModuleId } `
0 commit comments