11
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
+
14
15
'use strict' ;
15
16
17
+ const { SecurityCenterClient} = require ( '@google-cloud/security-center' ) ;
16
18
const { assert} = require ( 'chai' ) ;
17
- const execa = require ( 'execa ' ) ;
18
- const exec = async cmd => ( await execa . shell ( cmd ) ) . stdout ;
19
+ const { execSync } = require ( 'child_process ' ) ;
20
+ const exec = cmd => execSync ( cmd , { encoding : 'utf8' } ) ;
19
21
20
22
const organizationId = process . env [ 'GCLOUD_ORGANIZATION' ] ;
21
23
22
24
describe ( 'Client with SourcesAndFindings' , async ( ) => {
23
25
let data ;
24
26
before ( async ( ) => {
25
- const { SecurityCenterClient} = require ( '@google-cloud/security-center' ) ;
26
-
27
27
// Creates a new client.
28
28
const client = new SecurityCenterClient ( ) ;
29
-
30
29
const [ source ] = await client
31
30
. createSource ( {
32
31
source : {
@@ -69,95 +68,104 @@ describe('Client with SourcesAndFindings', async () => {
69
68
} ;
70
69
console . log ( 'my data %j' , data ) ;
71
70
} ) ;
72
- it ( 'client can create source' , async ( ) => {
73
- const output = await exec ( `node v1/createSource.js ${ data . orgId } ` ) ;
71
+
72
+ it ( 'client can create source' , ( ) => {
73
+ const output = exec ( `node v1/createSource.js ${ data . orgId } ` ) ;
74
74
assert . match ( output , new RegExp ( data . orgId ) ) ;
75
75
assert . match ( output , / N e w S o u r c e / ) ;
76
76
assert . notMatch ( output , / u n d e f i n e d / ) ;
77
77
} ) ;
78
- it ( 'client can get source' , async ( ) => {
79
- const output = await exec ( `node v1/getSource.js ${ data . sourceName } ` ) ;
78
+
79
+ it ( 'client can get source' , ( ) => {
80
+ const output = exec ( `node v1/getSource.js ${ data . sourceName } ` ) ;
80
81
assert . match ( output , new RegExp ( data . sourceName ) ) ;
81
82
assert . match ( output , / S o u r c e / ) ;
82
83
assert . match ( output , / " d e s c r i p t i o n " : " A n e w c u s t o m s o u r c e t h a t d o e s X " / ) ;
83
84
assert . notMatch ( output , / u n d e f i n e d / ) ;
84
85
} ) ;
85
- it ( 'client can list all sources' , async ( ) => {
86
- const output = await exec ( `node v1/listAllSources.js ${ data . orgId } ` ) ;
86
+
87
+ it ( 'client can list all sources' , ( ) => {
88
+ const output = exec ( `node v1/listAllSources.js ${ data . orgId } ` ) ;
87
89
assert . match ( output , new RegExp ( data . sourceName ) ) ;
88
90
assert . match ( output , / S o u r c e s / ) ;
89
91
assert . notMatch ( output , / u n d e f i n e d / ) ;
90
92
} ) ;
91
- it ( 'client can update a source' , async ( ) => {
92
- const output = await exec ( `node v1/updateSource.js ${ data . sourceName } ` ) ;
93
+
94
+ it ( 'client can update a source' , ( ) => {
95
+ const output = exec ( `node v1/updateSource.js ${ data . sourceName } ` ) ;
93
96
assert . match ( output , new RegExp ( data . sourceName ) ) ;
94
97
assert . match ( output , / N e w D i s p l a y N a m e / ) ;
95
98
assert . match ( output , / s o u r c e t h a t d o e s X / ) ;
96
99
assert . notMatch ( output , / u n d e f i n e d / ) ;
97
100
} ) ;
98
- it ( 'client can create a finding' , async ( ) => {
99
- const output = await exec ( `node v1/createFinding.js ${ data . sourceName } ` ) ;
101
+
102
+ it ( 'client can create a finding' , ( ) => {
103
+ const output = exec ( `node v1/createFinding.js ${ data . sourceName } ` ) ;
100
104
assert . match ( output , new RegExp ( data . sourceName ) ) ;
101
105
assert . match ( output , / N e w f i n d i n g c r e a t e d / ) ;
102
106
assert . notMatch ( output , / u n d e f i n e d / ) ;
103
107
} ) ;
104
- it ( 'client can create a finding with source properties' , async ( ) => {
105
- const output = await exec (
108
+
109
+ it ( 'client can create a finding with source properties' , ( ) => {
110
+ const output = exec (
106
111
`node v1/createFindingSourceProperties.js ${ data . sourceName } `
107
112
) ;
108
113
assert . match ( output , new RegExp ( data . sourceName ) ) ;
109
114
assert . match ( output , / N e w f i n d i n g c r e a t e d / ) ;
110
115
assert . match ( output , / n _ v a l u e / ) ;
111
116
assert . notMatch ( output , / u n d e f i n e d / ) ;
112
117
} ) ;
113
- it ( 'client can update a findings source properties' , async ( ) => {
114
- const output = await exec (
118
+
119
+ it ( 'client can update a findings source properties' , ( ) => {
120
+ const output = exec (
115
121
`node v1/updateFindingSourceProperties.js ${ data . findingName } `
116
122
) ;
117
123
assert . match ( output , new RegExp ( data . findingName ) ) ;
118
124
assert . match ( output , / U p d a t e d F i n d i n g / ) ;
119
125
assert . match ( output , / n e w _ s t r i n g _ e x a m p l e / ) ;
120
126
assert . notMatch ( output , / u n d e f i n e d / ) ;
121
127
} ) ;
122
- it ( 'client can set finding state' , async ( ) => {
123
- const output = await exec ( `node v1/setFindingState.js ${ data . findingName } ` ) ;
128
+
129
+ it ( 'client can set finding state' , ( ) => {
130
+ const output = exec ( `node v1/setFindingState.js ${ data . findingName } ` ) ;
124
131
assert . match ( output , new RegExp ( data . findingName ) ) ;
125
132
assert . match ( output , / I N A C T I V E / ) ;
126
133
assert . notMatch ( output , / u n d e f i n e d / ) ;
127
134
} ) ;
128
- it ( 'client can test IAM privileges' , async ( ) => {
129
- const output = await exec ( `node v1/testIam.js ${ data . sourceName } ` ) ;
135
+
136
+ it ( 'client can test IAM privileges' , ( ) => {
137
+ const output = exec ( `node v1/testIam.js ${ data . sourceName } ` ) ;
130
138
assert . equal (
131
139
( output . match ( / t r u e / g) || [ ] ) . length ,
132
140
2 ,
133
141
`${ output } contains true twice`
134
142
) ;
135
143
assert . notMatch ( output , / u n d e f i n e d / ) ;
136
144
} ) ;
137
- it ( 'client can list all findings' , async ( ) => {
138
- const output = await exec ( `node v1/listAllFindings.js ${ data . orgId } ` ) ;
145
+
146
+ it ( 'client can list all findings' , ( ) => {
147
+ const output = exec ( `node v1/listAllFindings.js ${ data . orgId } ` ) ;
139
148
assert . match ( output , new RegExp ( data . findingName ) ) ;
140
149
assert . match ( output , new RegExp ( data . untouchedFindingName ) ) ;
141
150
assert . notMatch ( output , / u n d e f i n e d / ) ;
142
151
} ) ;
143
- it ( 'client can list only some findings' , async ( ) => {
144
- const output = await exec (
145
- `node v1/listFilteredFindings.js ${ data . sourceName } `
146
- ) ;
152
+
153
+ it ( 'client can list only some findings' , ( ) => {
154
+ const output = exec ( `node v1/listFilteredFindings.js ${ data . sourceName } ` ) ;
147
155
assert . match ( output , new RegExp ( data . findingName ) ) ;
148
156
assert . notMatch ( output , new RegExp ( data . untouchedFindingName ) ) ;
149
157
assert . notMatch ( output , / u n d e f i n e d / ) ;
150
158
} ) ;
151
- it ( 'client can list findings at a time.' , async ( ) => {
152
- const output = await exec (
153
- `node v1/listFindingsAtTime.js ${ data . sourceName } `
154
- ) ;
159
+
160
+ it ( 'client can list findings at a time.' , ( ) => {
161
+ const output = exec ( `node v1/listFindingsAtTime.js ${ data . sourceName } ` ) ;
155
162
// Nothing was created for the source more then a few minutes ago, so
156
163
// days ago should return nothing.
157
164
assert . equal ( output , '' ) ;
158
165
} ) ;
159
- it ( 'client can add security marks to finding' , async ( ) => {
160
- const output = await exec (
166
+
167
+ it ( 'client can add security marks to finding' , ( ) => {
168
+ const output = exec (
161
169
`node v1/addFindingSecurityMarks.js ${ data . findingName } `
162
170
) ;
163
171
assert . match ( output , new RegExp ( data . findingName ) ) ;
@@ -167,29 +175,29 @@ describe('Client with SourcesAndFindings', async () => {
167
175
assert . match ( output , / v a l u e _ b / ) ;
168
176
assert . notMatch ( output , / u n d e f i n e d / ) ;
169
177
} ) ;
170
- it ( 'client can list findings withe security marks' , async ( ) => {
171
- // Ensure marks are set.
172
- await exec ( `node v1/addFindingSecurityMarks.js ${ data . findingName } ` ) ;
173
178
174
- const output = await exec (
179
+ it ( 'client can list findings withe security marks' , ( ) => {
180
+ // Ensure marks are set.
181
+ exec ( `node v1/addFindingSecurityMarks.js ${ data . findingName } ` ) ;
182
+ const output = exec (
175
183
`node v1/listFindingsWithSecurityMarks.js ${ data . sourceName } `
176
184
) ;
177
185
assert . notMatch ( output , new RegExp ( data . findingName ) ) ;
178
186
assert . match ( output , new RegExp ( data . untouchedFindingName ) ) ;
179
187
assert . notMatch ( output , / u n d e f i n e d / ) ;
180
188
} ) ;
181
- it ( 'client can get a sources policy' , async ( ) => {
182
- const output = await exec ( `node v1/getSourceIam.js ${ data . sourceName } ` ) ;
189
+
190
+ it ( 'client can get a sources policy' , ( ) => {
191
+ const output = exec ( `node v1/getSourceIam.js ${ data . sourceName } ` ) ;
183
192
assert . match ( output , / C u r r e n t p o l i c y / ) ;
184
193
assert . notMatch ( output , / u n d e f i n e d / ) ;
185
194
} ) ;
186
- it ( 'client set a sources policy' , async ( ) => {
195
+
196
+ it ( 'client set a sources policy' , ( ) => {
187
197
const user = 'csccclienttest@gmail.com' ;
188
- const output = await exec (
189
- `node v1/setSourceIam.js ${ data . sourceName } ${ user } `
190
- ) ;
198
+ const output = exec ( `node v1/setSourceIam.js ${ data . sourceName } ${ user } ` ) ;
191
199
assert . match ( output , / U p d a t e d p o l i c y / ) ;
192
- assert . match ( output , new RegExp ( user ) ) ;
200
+ assert . include ( output , user ) ;
193
201
assert . notMatch ( output , / u n d e f i n e d / ) ;
194
202
} ) ;
195
203
} ) ;
0 commit comments