Skip to content

Commit 5917352

Browse files
refactor: drop dependency on execa (#131)
1 parent b73ac8a commit 5917352

File tree

9 files changed

+162
-164
lines changed

9 files changed

+162
-164
lines changed

security-center/snippets/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
},
1414
"devDependencies": {
1515
"chai": "^4.2.0",
16-
"execa": "^1.0.0",
1716
"mocha": "^6.0.2"
1817
}
1918
}

security-center/snippets/system-test/.eslintrc.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ env:
33
mocha: true
44
rules:
55
node/no-unpublished-require: off
6-
no-empty: off
Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 Google LLC
1+
// Copyright 2019, Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -11,19 +11,19 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
1415
'use strict';
1516

17+
const {SecurityCenterClient} = require('@google-cloud/security-center');
1618
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'});
1921

2022
const organizationId = process.env['GCLOUD_ORGANIZATION'];
2123

2224
describe('client with security marks for assets', async () => {
2325
let data;
2426
before(async () => {
25-
const {SecurityCenterClient} = require('@google-cloud/security-center');
26-
2727
// Creates a new client.
2828
const client = new SecurityCenterClient();
2929

@@ -39,53 +39,47 @@ describe('client with security marks for assets', async () => {
3939
};
4040
console.log('data %j', data);
4141
});
42-
it('client can add security marks to asset.', async () => {
43-
const output = await exec(`node v1/addSecurityMarks.js ${data.assetName}`);
44-
assert.match(output, new RegExp(data.assetName));
42+
it('client can add security marks to asset.', () => {
43+
const output = exec(`node v1/addSecurityMarks.js ${data.assetName}`);
44+
assert.include(output, data.assetName);
4545
assert.match(output, /key_a/);
4646
assert.match(output, /value_a/);
4747
assert.match(output, /key_b/);
4848
assert.match(output, /value_b/);
4949
assert.notMatch(output, /undefined/);
5050
});
5151

52-
it('client can add and delete security marks', async () => {
52+
it('client can add and delete security marks', () => {
5353
// Ensure marks are set.
54-
await exec(`node v1/addSecurityMarks.js ${data.assetName}`);
54+
exec(`node v1/addSecurityMarks.js ${data.assetName}`);
5555

56-
const output = await exec(
57-
`node v1/addDeleteSecurityMarks.js ${data.assetName}`
58-
);
56+
const output = exec(`node v1/addDeleteSecurityMarks.js ${data.assetName}`);
5957
assert.match(output, /key_a/);
6058
assert.match(output, /new_value_a/);
6159
assert.notMatch(output, /key_b/);
6260
assert.notMatch(output, /undefined/);
6361
});
6462

65-
it('client can delete security marks', async () => {
63+
it('client can delete security marks', () => {
6664
// Ensure marks are set.
67-
await exec(`node v1/addSecurityMarks.js ${data.assetName}`);
65+
exec(`node v1/addSecurityMarks.js ${data.assetName}`);
6866

69-
const output = await exec(
70-
`node v1/deleteSecurityMarks.js ${data.assetName}`
71-
);
67+
const output = exec(`node v1/deleteSecurityMarks.js ${data.assetName}`);
7268
assert.notMatch(output, /key_a/);
7369
assert.notMatch(output, /value_a/);
7470
assert.notMatch(output, /key_b/);
7571
assert.notMatch(output, /value_b/);
76-
assert.match(output, new RegExp(data.assetName));
77-
assert.match(output, new RegExp(data.assetName));
72+
assert.include(output, data.assetName);
73+
assert.include(output, data.assetName);
7874
assert.notMatch(output, /undefined/);
7975
});
8076

81-
it('client can list assets with security marks', async () => {
77+
it('client can list assets with security marks', () => {
8278
// Ensure marks are set.
83-
await exec(`node v1/addSecurityMarks.js ${data.assetName}`);
79+
exec(`node v1/addSecurityMarks.js ${data.assetName}`);
8480

85-
const output = await exec(
86-
`node v1/listAssetsWithSecurityMarks.js ${data.orgId}`
87-
);
88-
assert.match(output, new RegExp(data.assetName));
81+
const output = exec(`node v1/listAssetsWithSecurityMarks.js ${data.orgId}`);
82+
assert.include(output, data.assetName);
8983
assert.notMatch(output, /undefined/);
9084
});
9185
});

security-center/snippets/system-test/v1/findings.test.js

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,21 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
1415
'use strict';
1516

17+
const {SecurityCenterClient} = require('@google-cloud/security-center');
1618
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'});
1921

2022
const organizationId = process.env['GCLOUD_ORGANIZATION'];
2123

2224
describe('Client with SourcesAndFindings', async () => {
2325
let data;
2426
before(async () => {
25-
const {SecurityCenterClient} = require('@google-cloud/security-center');
26-
2727
// Creates a new client.
2828
const client = new SecurityCenterClient();
29-
3029
const [source] = await client
3130
.createSource({
3231
source: {
@@ -69,95 +68,104 @@ describe('Client with SourcesAndFindings', async () => {
6968
};
7069
console.log('my data %j', data);
7170
});
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}`);
7474
assert.match(output, new RegExp(data.orgId));
7575
assert.match(output, /New Source/);
7676
assert.notMatch(output, /undefined/);
7777
});
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}`);
8081
assert.match(output, new RegExp(data.sourceName));
8182
assert.match(output, /Source/);
8283
assert.match(output, /"description":"A new custom source that does X"/);
8384
assert.notMatch(output, /undefined/);
8485
});
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}`);
8789
assert.match(output, new RegExp(data.sourceName));
8890
assert.match(output, /Sources/);
8991
assert.notMatch(output, /undefined/);
9092
});
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}`);
9396
assert.match(output, new RegExp(data.sourceName));
9497
assert.match(output, /New Display Name/);
9598
assert.match(output, /source that does X/);
9699
assert.notMatch(output, /undefined/);
97100
});
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}`);
100104
assert.match(output, new RegExp(data.sourceName));
101105
assert.match(output, /New finding created/);
102106
assert.notMatch(output, /undefined/);
103107
});
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(
106111
`node v1/createFindingSourceProperties.js ${data.sourceName}`
107112
);
108113
assert.match(output, new RegExp(data.sourceName));
109114
assert.match(output, /New finding created/);
110115
assert.match(output, /n_value/);
111116
assert.notMatch(output, /undefined/);
112117
});
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(
115121
`node v1/updateFindingSourceProperties.js ${data.findingName}`
116122
);
117123
assert.match(output, new RegExp(data.findingName));
118124
assert.match(output, /Updated Finding/);
119125
assert.match(output, /new_string_example/);
120126
assert.notMatch(output, /undefined/);
121127
});
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}`);
124131
assert.match(output, new RegExp(data.findingName));
125132
assert.match(output, /INACTIVE/);
126133
assert.notMatch(output, /undefined/);
127134
});
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}`);
130138
assert.equal(
131139
(output.match(/true/g) || []).length,
132140
2,
133141
`${output} contains true twice`
134142
);
135143
assert.notMatch(output, /undefined/);
136144
});
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}`);
139148
assert.match(output, new RegExp(data.findingName));
140149
assert.match(output, new RegExp(data.untouchedFindingName));
141150
assert.notMatch(output, /undefined/);
142151
});
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}`);
147155
assert.match(output, new RegExp(data.findingName));
148156
assert.notMatch(output, new RegExp(data.untouchedFindingName));
149157
assert.notMatch(output, /undefined/);
150158
});
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}`);
155162
// Nothing was created for the source more then a few minutes ago, so
156163
// days ago should return nothing.
157164
assert.equal(output, '');
158165
});
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(
161169
`node v1/addFindingSecurityMarks.js ${data.findingName}`
162170
);
163171
assert.match(output, new RegExp(data.findingName));
@@ -167,29 +175,29 @@ describe('Client with SourcesAndFindings', async () => {
167175
assert.match(output, /value_b/);
168176
assert.notMatch(output, /undefined/);
169177
});
170-
it('client can list findings withe security marks', async () => {
171-
// Ensure marks are set.
172-
await exec(`node v1/addFindingSecurityMarks.js ${data.findingName}`);
173178

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(
175183
`node v1/listFindingsWithSecurityMarks.js ${data.sourceName}`
176184
);
177185
assert.notMatch(output, new RegExp(data.findingName));
178186
assert.match(output, new RegExp(data.untouchedFindingName));
179187
assert.notMatch(output, /undefined/);
180188
});
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}`);
183192
assert.match(output, /Current policy/);
184193
assert.notMatch(output, /undefined/);
185194
});
186-
it('client set a sources policy', async () => {
195+
196+
it('client set a sources policy', () => {
187197
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}`);
191199
assert.match(output, /Updated policy/);
192-
assert.match(output, new RegExp(user));
200+
assert.include(output, user);
193201
assert.notMatch(output, /undefined/);
194202
});
195203
});

security-center/snippets/system-test/v1/listAllAssets.test.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
/*
2-
* Copyright 2019, Google, LLC.
3-
* Licensed under the Apache License, Version 2.0 (the "License");
4-
* you may not use this file except in compliance with the License.
5-
* You may obtain a copy of the License at
6-
*
7-
* https://www.apache.org/licenses/LICENSE-2.0
8-
*
9-
* Unless required by applicable law or agreed to in writing, software
10-
* distributed under the License is distributed on an "AS IS" BASIS,
11-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12-
* See the License for the specific language governing permissions and
13-
* limitations under the License.
14-
*/
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
1516

1617
const {assert} = require('chai');
17-
const execa = require('execa');
18-
const exec = async cmd => (await execa.shell(cmd)).stdout;
18+
const {execSync} = require('child_process');
19+
const exec = cmd => execSync(cmd, {encoding: 'utf8'});
1920

2021
const organization_id = process.env['GCLOUD_ORGANIZATION'];
2122

2223
describe('listAllAssets', () => {
23-
it('should print all assets in org', async () => {
24-
const output = await exec(`node v1/listAllAssets.js ${organization_id}`);
24+
it('should print all assets in org', () => {
25+
const output = exec(`node v1/listAllAssets.js ${organization_id}`);
2526
assert.isAtLeast(output.match(/\n/g).length + 1, 62);
2627
assert.notMatch(output, /undefined/);
2728
});

0 commit comments

Comments
 (0)